Black Lives Matter - Action and Equality. ... Adafruit is part of the Stop Hate for Profit campaign. Adafruit is open and shipping.
0

DHT 22 Temperature and Humidity sensor with adafruit code
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by gtjy on Wed Jul 02, 2014 3:12 am

Sorry, just to add another query. Could this whole logging to Google Docs work with a AM2302 sensor?
gtjy
 
Posts: 5
Joined: Mon Jun 30, 2014 2:53 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Wed Jul 02, 2014 12:02 pm

Yep the Arduino library and python library both support the AM2302. Check out the examples in each to see how you send in the type of sensor as a constant value (usually 22 in the case of the DHT22 or AM2302).

For the issue logging to google docs, lets check you can get readings from the DHT sensor. Are you using the newer python library here: https://github.com/adafruit/Adafruit_Python_DHT or the older one in the Raspberry Pi code here: https://github.com/adafruit/Adafruit-Ra ... ython-Code ?

If you're using the newer one, what happens when you run the AdafruitDHT.py example? The script takes two command line parameters, the first is the type of sensor (11 for DHT11, 22 for DHT22 or AM2302) and then the GPIO number connected to the sensor. For example if you have a DHT22 connected to GPIO23 you would run:

Code: Select all | TOGGLE FULL SIZE
sudo ./AdafruitDHT.py 22 23


What output do you see if you run that a few times? If you see an error 'Failed to get reading. Try again!' try a few more times since it sometimes takes a few attempts to read the sensor.

If you're using the older library, there's a precompiled version of a similar script. Navigate to the Adafruit_DHT_Driver folder and run AdafruitDHT with the same parameters as above, so for example with a DHT22 on GPIO 23:

Code: Select all | TOGGLE FULL SIZE
sudo ./AdafruitDHT 22 23


Grab the output of that and lets check that you're getting temperature and humidity readings.

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by gtjy on Sat Sep 20, 2014 1:06 am

Hi,

Anybody tried the same code provided with the new Raspberry Pi Model B+?
Any issues faced?
gtjy
 
Posts: 5
Joined: Mon Jun 30, 2014 2:53 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by gtjy on Sat Sep 20, 2014 1:44 am

Hi,

Because I am trying to implement the same set of code on the Raspberry Pi B+
Apparently my hardware setup are all in place
But when I run the program, I always fail to get reading.

Any idea whether is there any new settings or commands that I need to run for the program to work?
Or does this set of code only work for the Model B?
gtjy
 
Posts: 5
Joined: Mon Jun 30, 2014 2:53 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by adafruit_support_rick on Sat Sep 20, 2014 8:08 am

Are you getting errors? Please post your output.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Sun Sep 21, 2014 7:12 pm

Yeah if you can clarify what code you're running and what response you're getting that would help troubleshoot the issue. I just tried a DHT22 sensor with a B+ Pi and didn't see any problems.

Make sure you're wiring up the sensor to the Pi like this guide shows (using a pull-up resistor from 3.3V to the signal line of the DHT22). Also be careful not to power the DHT22 with 5V or you might damage GPIO pins on the Pi!

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by delta544 on Sat Sep 27, 2014 5:34 am

Hi everybody,

currently I am using your tutorial to learn a bit about Raspberry Pi and attaching sensor to it.
Goal is to create a weather station.
So bought a AM2302 DHT22 Sensor and connected it.
Followed the Adafruit tutorial and so far it seems to be OK, but, for some reason the output on command line is formated OK, but the google.doc shows weird values. Means, on command line I have 19.9 C but within the Excel sheet something like 196000003815. Same for Humidity on command line 61,9 % and in google 622000007629. Time is only displayed by Date, not by Date and Time.

Is there a way to reformat this? Tried to figure how this can be solved, but due to the lack of Python experience I was not really able to determine where this could be changed within the gspread scripts.

kind regards,
Andreas

delta544
 
Posts: 1
Joined: Sat Sep 27, 2014 5:19 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Sat Sep 27, 2014 5:01 pm

Are you sure there isn't a decimal point in the values in the spreadsheet? For example when I run with a new sheet right now I see values like:
Image

The long values with lots of decimal places are normal. Floating point numbers actually can't represent certain exact numbers and end up creating approximations like that. When the code displays the temperature in the script it's just rounding up to 1 decimal place, but when it writes the value to the spreadsheet it's writing with as many decimal places as possible. Try playing around with some of the options in Google spreadsheets to change the format and precision of the columns. It looks like if you change it to a Number type in the sheet it will only display two decimal places, and I bet it has options like Excel to round to an arbitrary decimal precision.

For the date, make sure to expand the column a bit so you can see the full value. Also again try changing some of the column options in the sheet to adjust how the date is printed. For example here's the same data but with a different date format applied to the spreadsheet (and number format for the temp & humidity columns):
Image

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by bijl on Tue Sep 30, 2014 1:40 am

Hi,
Thanks for the clear tutorial. I got it all running. But I have the same issue with displaying the values in google docs.
This is the time notation: 2014-09-28 21:03:37.883949
This is the temperature: 16.0,15.5 but for all other values it displays a value without a point 156000003815
This is the same for the humidity: 913000030518 or 91.5

The value 16.0 is alligned to the left side of the cell, the value 156000003815 is alligned to the right side of the cell.

bijl
 
Posts: 1
Joined: Tue Sep 30, 2014 1:33 am

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by richardjy211 on Sun Nov 09, 2014 10:51 pm

I got the temperature and humidity reading alright, but I am not able to login and get google spreadsheet.

I tried to create the old version of spreadsheet or update the pip gspread, but none is working for me.

Is anyone else having the same issue?

Nevermind. The access was blocked by google.

Please note the security level.

richardjy211
 
Posts: 1
Joined: Sun Nov 09, 2014 10:47 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by loonhaunt on Sat Dec 20, 2014 10:52 am

I follow this tutorial last Spring and it worked perfectly. I think more has been changed, other than the google docs url and related issues mentioned here. As now when I use following: sudo apt-get install build-essential python-dev
Err404.jpg
Err404.jpg (68.75 KiB) Viewed 3988 times
I get all of these err 404 which I think means that the the command is not finding a functional link to download the code from??? And then this when I try the test code in examples.
NoSuchModule.jpg
NoSuchModule.jpg (74.36 KiB) Viewed 3988 times

Could be a host site web hiccup also no?

So if any one has used these links lately with success please five me a shout.

Thanks

Dave

loonhaunt
 
Posts: 70
Joined: Sat Nov 16, 2013 1:40 am
Location: Colorado US

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Sat Dec 27, 2014 2:02 am

Sorry just catching up on this thread, but one thing to do is update your apt package list by running:
Code: Select all | TOGGLE FULL SIZE
sudo apt-get update


Then try running the apt-get install commands to install the dependencies. I have a feeling the 404 errors you see are for older versions that have since been updated. Running the update command above will grab the latest version numbers and URLs for all the packages. Give that a shot and let me know if you still see errors, thanks!

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by loonhaunt on Sat Dec 27, 2014 12:11 pm

That did the trick. Weird I thought that I did do an apt-get update, during the process but must have skipped it?
Thanks much have a great New Year!

loonhaunt
 
Posts: 70
Joined: Sat Nov 16, 2013 1:40 am
Location: Colorado US

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by tdicola on Wed Dec 31, 2014 3:01 pm

Oh nice, glad to hear it's working. Thanks for the followup!

tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: DHT 22 Temperature and Humidity sensor with adafruit cod

by dcrand on Thu Jan 01, 2015 12:00 pm

Hello,
I'm using google_spreadsheet.py and it is updating to google drive just fine. However I and my family would like to see the Temp in "F" not "C"
I'm new to coding so how do I change print 'Temperature: {0:0.1f} C'.format(temp)
to print 'Temperature: {0:0.1f} F'.format(temp)

dcrand
 
Posts: 4
Joined: Wed Jul 13, 2011 1:13 pm

Please be positive and constructive with your questions and comments.