DHT11 LIB Functionality

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Vigge
 
Posts: 2
Joined: Tue Jun 30, 2015 7:29 am

DHT11 LIB Functionality

Post by Vigge »

Hi,

I tried searching for this topic but couldn't find it in the forums already. If it's there please help me find it. :)

My story is that I need a DHT11 sensor hooked up to a custom avr board, so I wrote a driver/lib for my atmega328 based on this datasheet: http://www.micropik.com/PDF/dht11.pdf

Naturally I checked adafruits Arduino code to see how this sensor is most commonly used. But in your lib there are a few things done differently than I am doing:

1. The main big difference, the adafruit driver is only allowing samples every 2 second. There is a note in the datasheet saying that 1 second is the fastest sample time but it seems that my sensor samples fine directly after the read out operation is complete. -although, my sensor is broken(it cannot read rh greater than about 32% regardless of the sample frequency).
Is it possible that the sensor will damage itself if sampled too frequently?

2. The adafruit lib has an awfully long initial sample delay(250ms) were the sensor is just pulled up using the built in pull up of the avr. It seems to me that this is an unecessary delay, but then again, my sensor is broken... Why is this delay needed when the line is supposed to always have a pull-up? Is this just to prevent accidentally pulling the line low if the sensor happens to be already transmitting? Or is there something not mentioned in the datasheet that requires this behavior?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: DHT11 LIB Functionality

Post by adafruit_support_rick »

No idea. Lots of times, our libraries seem to include undocumented behavior, which was probably necessary to get things working. The delay may be something that was arrived at empirically. I'll see if anyone remembers why these things were done.

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

Re: DHT11 LIB Functionality

Post by tdicola »

Good questions! The 2 second sampling limit comes from this note in the datasheet (http://www.adafruit.com/datasheets/Digi ... AM2302.pdf), "See below figure for overall communication process, the interval of whole process must beyond 2 seconds." A little odd phrasing, but it basically means read the sensor at most every two seconds. :) I don't think there's the potential for damage if you read it faster, at least the datasheet doesn't have any warnings about it, but I bet you might not get accurate or up to date readings. When in doubt stick with reading every 2 seconds like the datasheet recommends.

As far as the initial high signal delay goes, good question I think you're right in that it could be a little shorter than 250 milliseconds. I can't think of any specific reason why its 250 milliseconds, and the datasheet doesn't have any note or warning that it should be that long--likely it was just a good initial value that was used when the library was developed and hasn't changed. If you experiment with it and see a smaller value that still works feel free to send a pull request to adjust it. Thanks!

User avatar
Vigge
 
Posts: 2
Joined: Tue Jun 30, 2015 7:29 am

Re: DHT11 LIB Functionality

Post by Vigge »

Ok, I think that was the answer I was looking for. I was afraid that the fast sampling was the reason for my broken sensor but then I guess it was probably broken right out of the shelf.

Thanks

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

Re: DHT11 LIB Functionality

Post by tdicola »

Oh that's odd if you're not reading about 32% humidity from a new sensor. We can replace it with a new one though--email [email protected] and point them at this thread to help get the replacement process going. Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”