DHT22 with RasPi taking up to 71mins for a reading

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/
Locked
JimApple
 
Posts: 2
Joined: Thu Oct 17, 2013 3:12 pm

DHT22 with RasPi taking up to 71mins for a reading

Post by JimApple »

Hi,

I am trying to use a DHT22 with my RasPi. I followed the Adafruit tutorial DHT Humidity Sensing on Raspberry Pi with GDocs Logging but when trying to get a reading by running sudo ./Adafruit_DHT type pin# from the command line, it can take an absolute age to get the reading back - the best I have had so far is about 5mins and the worst 71 mins!

I have connected the DHT as described and have tried both a 4.7K and 10K resistors and have loaded all the libraries. I have had a look at the C code in Adafruit_DHT.c and am guessing it is getting stuck at

Code: Select all

  // wait for pin to drop?
  while (bcm2835_gpio_lev(pin) == 1) {
    usleep(1);
  }
but don't really know how to monitor this, change it or what could be causing it (I can just about get by with Python but C is a black art to me.)

Below are a few typical results I have been getting (I am using port 22 but have tried others, including 4 as in the tutorial):

Code: Select all

pi@raspberrypi ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ time sudo ./Adafruit_DHT 22 22
Using pin #22
Data (40): 0x1 0xf2 0x0 0xe2 0xd5
Temp =  22.6 *C, Hum = 49.8 %

real	5m12.403s
user	0m5.820s
sys	1m26.350s

Code: Select all

pi@raspberrypi ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ time sudo ./Adafruit_DHT 22 22
Using pin #22

Data (40): 0x1 0xef 0x0 0xe5 0xd5
Temp =  22.9 *C, Hum = 49.5 %

real	16m50.953s
user	0m49.030s
sys	4m14.370s

Code: Select all

pi@raspberrypi ~/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver $ time sudo ./Adafruit_DHT 22 22
Using pin #22

Data (40): 0x1 0xf0 0x0 0xe2 0xd3
Temp =  22.6 *C, Hum = 49.6 %

real	71m56.141s
user	1m8.340s
sys	20m5.480s
Can anyone suggest what might be the problem here please?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by adafruit_support_mike »

I have no idea what the problem would be, but am slightly in awe of your patience..

The DHT tutorial is still experimental, so this looks like an extreme case of YMMV, and it will be best if you talk to the people who have the most direct knowledge. I'll pass this thread along to the folks doing the research and see who has the freshest information.

Fair warning: you may have volunteered to be one of our Test Subjects. ;-)

JimApple
 
Posts: 2
Joined: Thu Oct 17, 2013 3:12 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by JimApple »

Thanks Mike, I would appreciate any help they can provide and am more than happy to be a test subject.

User avatar
sunshinegrrrl
 
Posts: 3
Joined: Mon Oct 07, 2013 3:54 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by sunshinegrrrl »

If this helps any, I had to rewrite a bunch of the code. It just never worked for me, so I read through the information for the dht22 and created a library for it with the original code as a good starting point. I tightened up some of the stuff in the loops, changed the starting timers(seemed way to long to detect initial drop), and gave it the chance to retry if it didn't get valid information. Linux isn't real time and if your load is fairly high it may take 2 or 3 tries. It has worked pretty solidly for me for the last two months but I've not tested it with the dht11 or the am2302. This creates dhtquery and a library libdhtxx. so that I could use it in my thermostat project. It may give some people a better place to start or at least something different to try.

http://www.missliss.org/code/dhtxx-0.9b.tar.gz

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by adafruit_support_mike »

Very nice!

Thank you for posting that.

User avatar
sunshinegrrrl
 
Posts: 3
Joined: Mon Oct 07, 2013 3:54 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by sunshinegrrrl »

Absolutely. I hope it's helpful. I needed a pure C solution for my daemon and for whatever reason, I couldn't get anyone elses source to work. I'm sure I was doing something wrong but this works for me.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by adafruit_support_mike »

Prebuilt libraries are great, but you never really understand a process until you have to implement it yourself.

Again: bravo!

User avatar
egutting
 
Posts: 297
Joined: Wed Nov 14, 2012 12:57 am

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by egutting »

Awesome job! When I was looking into a humidity sensor I saw the warning in the tutorial and didn't even try. I ran away to the Honeywell HIH-5031 analog sensor. Maybe I should pick up a DHT22 to play with now.

User avatar
sunshinegrrrl
 
Posts: 3
Joined: Mon Oct 07, 2013 3:54 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by sunshinegrrrl »

It's a fairly inexpensive investment. That said, while I've gotten the DHT22 to work under linux, it's not an ideal situation. The timings are very quick and it's easy for linux to switch to another process for a few milliseconds. I've mitigated that somewhat by allowing a do-over, but it's not perfect. About 30% of the time, it requires a do-over on my raspi's and if the cpu is especially taxed, it will take a few more. I've rarely had it fail after the 3rd try. The 1-wire one is much better for continuous polling and reporting I think even if it needs a little adjustment up or down a degree or two. It's super thrifty, too.

I'm using the DHT22 as a secondary and it's coming through pretty well. Every once in awhile it will get a bad read that passes the checksum and it will show a spike in my graphs(which I've mitigated some in the code for producing my graphs). Just FYI. This seems to work for me for what I'm doing. Mileage may vary. =)

User avatar
pieman99
 
Posts: 8
Joined: Mon Apr 28, 2014 7:37 pm

Re: DHT22 with RasPi taking up to 71mins for a reading

Post by pieman99 »

Thanks for this library. This code seems to work better than the Adafruit code. Occasionally I still get a bad reading coming through. Any suggestions on how to identify these and throw them out? Is it the code or the sensor?

For example:
Tue May 6 02:47:05 EDT 2014 7.8 C 46.0 F 69.5%
Tue May 6 02:52:07 EDT 2014 7.8 C 46.0 F 70.1%
Tue May 6 02:57:08 EDT 2014 7.7 C 45.9 F 70.8%
Tue May 6 03:02:10 EDT 2014 14.8 C 58.6 F 144.8% <<<<
Tue May 6 03:07:24 EDT 2014 7.3 C 45.1 F 73.1%
Tue May 6 03:12:30 EDT 2014 7.2 C 45.0 F 73.0%
Tue May 6 03:17:34 EDT 2014 7.2 C 45.0 F 72.3%
Tue May 6 03:22:38 EDT 2014 14.2 C 57.6 F 145.6% <<<<
Tue May 6 03:27:43 EDT 2014 14.0 C 57.2 F 148.2% <<<<
Tue May 6 03:32:46 EDT 2014 6.9 C 44.4 F 75.3%
Tue May 6 03:37:48 EDT 2014 6.8 C 44.2 F 74.8%

or

Tue May 6 04:35:33 EDT 2014 6.2 C 43.2 F 78.4%
Tue May 6 04:40:37 EDT 2014 6.2 C 43.2 F 78.1%
Tue May 6 04:45:38 EDT 2014 24.2 C 75.6 F 80.2% <<<<<
Tue May 6 04:50:50 EDT 2014 6.1 C 43.0 F 78.4%
Tue May 6 04:56:30 EDT 2014 6.2 C 43.2 F 78.6%
Tue May 6 05:01:33 EDT 2014 6.1 C 43.0 F 78.5%

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”