DHT2302 Sensor
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

DHT2302 Sensor

by Dwali on Sun Sep 23, 2012 5:01 pm

I can't seem to get the AM2302 Temp/Humidity sensor to work on my raspberry pi. I can verify that it works on my arduino.

I've followed the tutorial provided.

This is what I'm getting back when I try to work with the device:

pi@raspberrypi ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ sudo ./Adafruit_DHT 2302 4
Using pin #4
Data (0): 0x0 0x0 0x0 0x0 0x0

Edit: I'm aware of the delay on the device, but after polling for a long time, I never saw any data.
Dwali
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

by cynikal on Mon Sep 24, 2012 2:06 am

Seems to be a common occurance, found some other threads where folks are having trouble as well (myself included). Must be an issue with the code Adafruit is providing us. I've gotten it to work maybe twice out of 200 tries.. Not a very good success rate :-)
cynikal
 
Posts: 7
Joined: Sun Sep 09, 2012 9:38 pm

Re: DHT2302 Sensor

by Dwali on Mon Sep 24, 2012 11:02 am

At least I'm not the only one -.-

I was beginning to conclude that I ruined my GPIO pins. My pi lives another day!

But seriously, hope this issue is looked at. Adafruit had it working fine in the tutorial. I wonder what is different in their setup.
Dwali
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

by cynikal on Tue Sep 25, 2012 10:40 am

You need to change that initial usleep to be longer in their code after the first gpio output is set. i did some digging deeper in the datasheet, and actually got it working in python as well using the RPi.GPIO module actually (can't say it's pure python since the RPi.GPIO module is doing gpio via ctypes, but i found it's fast enough on the raspberry using time it).. I basically run a renice'd while loop (with the condition being a 500 count) and just collecting time.time() and the output of the pins, and nothing else in that loop (other than incrementing the counter) so it runs as fast as possible. I then process all the data collected outside the loop when i have more time:

cynikal@raspberrypi ~/raspberry-pi-files $ sudo ./dht-test-rpi-gpio.py
[0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0]
Temperature: 25.4
Humidity: 36.5

It's not perfect either and i more did it for the challenge of it than anything else, since the timing on this thing is so picky you can't get it working 100% of the time either (even in their C code it seems).. but it's considered "a low-cost sensor" so you have to basically live with it (or so i get that impression from everything i read).
cynikal
 
Posts: 7
Joined: Sun Sep 09, 2012 9:38 pm

Re: DHT2302 Sensor

by Dwali on Tue Sep 25, 2012 7:21 pm

Using your suggestion, I got one temperature reading out of hundreds of tries. Do you have a usleep value suggestion?

Also, I'm not sure how to read the data from the GPIO pin 4 using the module. I'm just receiving a bool value. Any suggestions or direction to material worth reading?

Thanks for your help!!
Dwali
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

by sergiosanche on Mon Oct 01, 2012 9:23 am

I'm using this sensor temperature / humidity and initially had the same problem. The solution is to modify the source code in C file and change the value of the function usleep and put in a loop so that it does not return until a valid value is not displayed. If you need to ask me and I sent it.
Greetings
sergiosanche
 
Posts: 1
Joined: Mon Oct 01, 2012 9:17 am

Re: DHT2302 Sensor

by eboonin on Tue Oct 02, 2012 10:58 pm

ugh, super frustrated to hit this problem-- I specifically ordered this sensor because Adafruit had a tutorial so I somehow believed that meant that this would work.

Is the problem specific to the 2302 or is it the same for the 22 and the 11 as well?

I tried to edit the C and make but got an error about a missing .h file.... any tips on hacking it?
eboonin
 
Posts: 1
Joined: Mon Jul 02, 2012 4:25 am

Re: DHT2302 Sensor

by adafruit on Wed Oct 03, 2012 9:54 pm

We're not sure why some people can't get it to work - we've seen tons of reports that it -does- work. Be sure to try other pins just in case pin 4 is fried or is activated for another use

Its difficult to debug because the code works great for us here on our RPis running Occidentalis :(

But you can post a photo and we'll take a look!

Meanwhile, keep in mind, this 'driver' is experimental and DHT sensors are very low cost and can be flaky. The best sensor we carry for humidity/temperature sensing is the Sensiron http://www.adafruit.com/products/246
HOWEVER, there is no RPi driver for it at this time - it does use I2C so it should not be too difficult and hopefully someone will write one soon (we have no plans at this time)
User avatar
adafruit
 
Posts: 11704
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: DHT2302 Sensor

by Dwali on Wed Oct 03, 2012 10:56 pm

The solution proposed by sergiosanche and cynikal worked just fine. I have finally moved ahead with my project.

eboonin, you'll want to do this:

sudo wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.8.tar.gz
tar -zxvf bcm2835-1.8.tar.gz
cd bcm2835-1.8
./configure
make
sudo make install
Dwali
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

by adafruit on Wed Oct 03, 2012 11:03 pm

Thanks - we did push a new version to the git repo - not sure if its the same as your code as nobody posted up anything here but we did get a suggestion from a nice person on the RPi forums who posted last night :)

Can everyone please try the version here
https://github.com/adafruit/Adafruit-Ra ... DHT_Driver

(run git update in the directory or git clone http://github.com/adafruit/Adafruit-Ras ... ython-Code to re-download)

let us know if it works!
User avatar
adafruit
 
Posts: 11704
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: DHT2302 Sensor

by Dwali on Thu Oct 04, 2012 1:47 am

This does work! However.. it runs slower than the code I'm running suggested by sergiosanche. I'm also still receiving 0 values frequently as I run the script.

In the code I'm running:
First usleep is 25, second is 10000.
There is a conditional to ensure zeros are never returned.

Edit: thanks for working on this <3
Dwali
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

by adafruit on Thu Oct 04, 2012 8:03 am

we cant put in a conditional to not return zeros as that could hang it. we'll get more feedback and adjust as necessary - we think it is SENSOR dependent
User avatar
adafruit
 
Posts: 11704
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: DHT2302 Sensor

by outspoken on Fri Oct 05, 2012 2:21 pm

basically this sensor is not meant to work with the pi. i have had it for over a week now and sometimes it works, most of the time it does not. i have done all suggested fixes in this thread and elsewhere on the web.
outspoken
 
Posts: 2
Joined: Tue Sep 18, 2012 8:23 pm

Re: DHT2302 Sensor

by Dwali on Sun Oct 07, 2012 5:24 pm

I disagree outspoken, after recompiling the code it has worked flawlessly for a couple of days straight.
Dwali
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

by adafruit on Mon Oct 08, 2012 5:03 pm

Thanks for the feedback Dwali!
User avatar
adafruit
 
Posts: 11704
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc