winlinvip / SimpleDHT

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

DHT11 sampling fix (tested on ESP8266 and Mega2560 r3) #22

Closed t-w closed 6 years ago

t-w commented 6 years ago

Changed 2 things for DHT11 :

As you see, I was not using the confirm(), which actually gives shorter code - but to make measurements when something fails, it was easier to have methods returning the measured time (levelTime()).

After these changes, the readings for the 2 mentioned boards are very stable with no errors (for me at least...).

winlinvip commented 6 years ago

Why change the pin to the member? It changes the API of library. We should keep API compatible.

winlinvip commented 6 years ago

Sorry, it's compatible API, I got it. I only need to test on Arduino UNO R3, then I will merge it. Thanks for your good work.

t-w commented 6 years ago

Initially, I haven't actually been thinking that it will be ever used by someone other than me... and I decided to simplify the interface. I added the backward compatibility calls to the interface, so it should be fine for all the existing code. I was aware that it can cause doubts, but also I think the updated library is even simpler to use and more clear (might be good for beginners that use it to play).

While testing, note that the timing is very delicate here. It may be necessary to measure and adjust the thresholds if it fails on UNO R3 (and test it again on other devices). Eventually, if necessary, the thresholds could be set different depending on the device (I tried to avoid this). It is not by the book at all - but it seems the sensor just works like this...

winlinvip commented 6 years ago

Verified on Arduino UNO R3. Merged to master.

winlinvip commented 6 years ago

@t-w I refined the code, please test 1.0.9 on ESP8266 and Mega2560 r3 again.

t-w commented 6 years ago

Tested on ESP8266 and Mega2560r3 (1.0.11) - works fine! (Thanks for the merge!)