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/
User avatar
LoveWizard
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

DHT2302 Sensor

Post by LoveWizard »

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.

User avatar
cynikal
 
Posts: 10
Joined: Sun Sep 09, 2012 9:38 pm

Re: DHT2302 Sensor

Post by cynikal »

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 :-)

User avatar
LoveWizard
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

Post by LoveWizard »

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.

User avatar
cynikal
 
Posts: 10
Joined: Sun Sep 09, 2012 9:38 pm

Re: DHT2302 Sensor

Post by cynikal »

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).

User avatar
LoveWizard
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

Post by LoveWizard »

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!!

sergiosanche
 
Posts: 6
Joined: Mon Oct 01, 2012 9:17 am

Re: DHT2302 Sensor

Post by sergiosanche »

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

eboonin
 
Posts: 1
Joined: Mon Jul 02, 2012 4:25 am

Re: DHT2302 Sensor

Post by eboonin »

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?

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: DHT2302 Sensor

Post by adafruit »

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
LoveWizard
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

Post by LoveWizard »

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

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: DHT2302 Sensor

Post by adafruit »

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
LoveWizard
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

Post by LoveWizard »

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

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: DHT2302 Sensor

Post by adafruit »

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

outspoken
 
Posts: 2
Joined: Tue Sep 18, 2012 8:23 pm

Re: DHT2302 Sensor

Post by outspoken »

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.

User avatar
LoveWizard
 
Posts: 7
Joined: Sun Sep 23, 2012 4:55 pm

Re: DHT2302 Sensor

Post by LoveWizard »

I disagree outspoken, after recompiling the code it has worked flawlessly for a couple of days straight.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: DHT2302 Sensor

Post by adafruit »

Thanks for the feedback Dwali!

Locked
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/

Return to “Adafruit Raspberry Pi® accessories”