winlinvip / SimpleDHT

Simple, Stable and Fast Arduino Temp & Humidity Sensors for DHT11 and DHT22. http://learn.adafruit.com/dht
MIT License
145 stars 61 forks source link

Running on Mega2560 cause unstable reading results #18

Closed nailgilaziev closed 6 years ago

nailgilaziev commented 6 years ago

HI! Thanks for this great library!

I want to report a strange behavior on mega2560. Same dht22, VCC 5v, same pullUP 10K resistor, same wires, same Pin on board.

attempt №1 , I connect it to my Arduino Nano and run example sketch: Arduino Nano (Atmega 328P)

=================================
Sample DHT22 with error count
//...iterate 100 times
24.80 *C, 27.50 RH%, total: 100, err: 0, success rate: 100.00%

Success rate 100% after 100 iterates.

Attempt №2, I connect it to my Arduino Mega Pro and run same sketch: Arduino Mega Pro (Atmega2560 / 12MHz)

=================================
Sample DHT22 with error count
//...iterate 100 times
Read DHT22 failed, err=105
0.00 *C, 0.00 RH%, total: 100, err: 31, success rate: 69.00%

attempt №3 Arduino Mega (Atmega 2560 / 16MHz)

=================================
Sample DHT22 with error count
//...iterate 100 times
Read DHT22 failed, err=105 // happened not before next line
24.10 *C, 31.80 RH%, total: 100, err: 29, success rate: 71.00%

On both mega2560 error with code 105 occur. (checksum) What can be a problem?

nailgilaziev commented 6 years ago

who can give advice in which direction should I look for a problem?

t-w commented 6 years ago

I had similar problems, but with DHT11 (https://github.com/t-w/SimpleDHT/issues/2). After having look inside the library and playing for a while, I found out that there are timing issues while accessing the device (the times I measured do not match exactly those implemented or specified in documentation). I managed to patch the library so that it works properly on my Mega2560, you can find it here: https://github.com/t-w/SimpleDHT/tree/mega2560_r3 It would require testing on other devices though, before eventually merging (I already had to correct one time threshold to works also on ESP8266, available in provided repo, the esp2866 branch).

For the DHT22, I suppose the problems are similar. You would need to have a closer look at the SimpleDHT22:sample(), where the timing problems occur... I do not have DHT22 so cannot test it myself.

winlinvip commented 6 years ago

👍 Please file a MergeRequest.

winlinvip commented 6 years ago

I will test it on Arduino with DHT11 and DHT22.

delfuego commented 6 years ago

@t-w Your fork works perfectly for me! Prior to it, with my MEGA2560, I was getting 95 read errors out of 100 (not an exaggeration); now, it's perfect.

@winlinvip, any chance of getting this merged in? Pretty please? If only because I experienced what my 10yo's reaction was when the DHT11 in our kit "wasn't working at all" — leading me to hunt and figure out what might be happening, and finding this.

winlinvip commented 6 years ago

I need to test it on Arduino UNO R3.

winlinvip commented 6 years ago

Please test 1.0.9