-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DHT init sequence wrong #48
Comments
Which platform do you use ? Sent from my iPhone
|
Hi asetyde, |
Oh, and yes, it DOES influence the quality of the readings. At least if connected to the ESP8266 GPIO #2, the original lib returned "NAN" about every 10th read. The modified lib now performed around 50.000 reads with zero errors ( I added success/fail counters to the code ). |
I ask to you because my nodemcu sometime it block itself and I don't know why , I try to restore library to 1.1.1 but i don't know how can I do .. I can not records with ide many hours of serial .. But block it showed in MySQL table .. Often after 3h or 7h many times, tomorrow I try to cut sensor and isolate issue , but if it dht ? I change many sensor but it mustn't block device ! Sent from my iPhone
|
Hi Wolfgang, Thank you for posting this fix together with detailed test results including sexy waveforms 😄 👍 I am writing a tutorial on automatic humidity control using ESP8266 and after longer testing discovered similar issue. I like to use adafruit library as it is slick and mature, very well commented in code and available for installation right out of Arduino IDE. For these reasons I was reluctant to replace it and started searching for issue reports and luckily found your post! I was observing random DHT22 / AM2302 read failures using this library together with Arduino Due and now with ESP8266. I do not observe so big failure rate like you, but still see one Anyway, after applying your fix the issue vanished 💨 Thank you again for contribution of this fix 👍 Krzysztof |
Dear Krzysztof, welcome. Just as a rule of thumb: If you do something that later "goes public as a product" either do not use Arduino or check any used library for mistakes. To bring that above complaining to the right perspective: I think the Arduino project is GREAT. They found the right balance between hiding hardware ( register ) complexitivity and making things too simplified ( and therefor to much constrained ). I also like the business model of financing this entire thing with sold hardware. So, yes I like Arduino. No, I do not recommend it for professional product development. I mostly like that there is plenty of overall good documentation. Regards, Am 20.12.2015 um 12:07 schrieb krzychb:
|
I agree with W-E, the MCU should never make the pin output and high. After investigating most known DHT datasheets, I think it is obvious that it will cause a "more or less" shortcut between the MCU and the microcontroller inside the DHT. Thank you for the pictures of that shortcut W-E. |
Thank you Wolfgang for posting this fix. After following your advice to add the pull up resistor and comment out the 2 lines, I am getting much cleaner reads from the DHT-11. I was able to reproduce your before and after scope screenshots with my ESP8266 and DHT-11. This really needs to get into the main library. In the mean time I have made the changes in my fork. Thanks again, |
Thanx @W-E , before this modification I couldn't get good reading most of the time. After fix it works noticeable better but sill get What pull up resistor do you use? Do you use third parameter in |
Hi Renno, I did use 4k7 pullup. I believe ( I do not have the code here now ) that Oh, I just looked at Github and now the example is adapted: // Initialize DHT sensor. So, no, no additional parameter. Regards, Am 16.02.2016 um 14:05 schrieb renno-bih:
|
I tried with 4k3 resistor and without third parameter but still can see lot of bad readings. ( I read Also tried another DHT11 sensor and DHT22 sensor, both give some false readings. |
@renno-bih, |
Yes, here are some readings:
|
Hi renno-bih, |
Looks like I found solution. |
2.1.0 best choice in staging ElectricLabsDevelop & Research [email protected]Verona (Italy) INFORMAZIONE RISERVATA - Le informazioni contenute in questo messaggio e in qualsiasi documento a esso allegato sono confidenziali, potrebbero essere riservate e possono essere utilizzate solo dal destinatario designato. Se Lei non è il destinatario qualsiasi copia, trasmissione, divulgazione o azione basata su tali informazioni è assolutamente vietata ed è proibita sia ai sensi dell'art. 616 c.p. sia ai sensi della vigente Legge sulla privacy dei dati. Se questo messaggio è stato ricevuto per errore, La preghiamo cortesemente di darcene comunicazione via e-mail e quindi di procedere alla cancellazione di questo messaggio e all'eliminazione di ogni sua copia. Rispetta l'ambiente: se non ti è necessario, non stampare questa mail.
|
2.1.0 work flawlessly. |
2.0.0 has memory leak memory bug . i’m using 2.1.0 rc1 work good
|
Hello everybody, I think that the initial solution is probably not fully correct. The original waveforms indicate that the timing is the same, so besides commenting out the first two lines, we should also increase the second delay after pull-up to 50 us: //digitalWrite(_pin, HIGH);
//delayMicroseconds(40);
// Now start reading the data line to get the value from the DHT sensor.
pinMode(_pin, INPUT_PULLUP);
delayMicroseconds(50); // Delay a bit to let sensor pull data line low. - adjusted from 10 us In this code, the expectPulse will take care of this in most cases, however some timeouts may occur because of this (maybe it is the problem @renno-bih mentions) and when modifying the derived code (NodeMCU, ESP Easy) the unadjusted timing leads to reading of incorrect values. |
With 50us delay I couldn't get any data from DHT11 |
@W-E Thanks a lot your fix worked really well for DHT11. Do have any ideas why that happens? Thanks. |
A native chinese speaker read the datasheets : http://forum.arduino.cc/index.php?topic=377413.msg2699553#msg2699553 |
I was having fits with an AM2302and the ESP8266; I implemented the changes by pm-cz abd everything is working great. I think it worked for AVR chips more or less by accident, because the protocol is quite clear and the library code does not implement it correctly. Surprised Adafruit hasn't fixed it. |
…up after the conversion start : adafruit/DHT-sensor-library#48
Add fixes from adafruit/DHT-sensor-library#48
I've been trying to get this library to work for weeks without success. This fix worked for me. I figured using the latest library provided by the Library Manager in the Arduino IDE was a safe bet. Lesson learned! Why on earth hasn't this fix been applied? It was suggested over 12 months ago! So frustrating! |
I also had invalid readings and thought it was a problem of my sensor. I agree it should have been fixed, a lot of people trust Adafruit with their hardware/software and the solution is over a year old. Please Adafruit, implement the changes suggested by W-E and pm-cz! |
with W-E 's solution, I never met any reading errors any more. |
WOW this works, I have been dealing with this for a long time, trying to figure out where this noise is coming from, neopixels seems to exacerbate the problem, but this fixed it, makes no sense, no scope here to test. |
This fixes issue 48, using the method suggested there. Reference: adafruit#48
Delay for 50 us not 10 us after pulling data line low. This change is taken from a comment on Issue 48 (adafruit#48) of the Adafruit library (https://github.com/adafruit/DHT-sensor-library) Reference: adafruit#48 (comment)
The recent version of the library 1.3.0 (available through Library Manager in Arduino IDE) still has no fix for this issue... My caseI had occasional problems with reading data from DHT (DHT11 or DHT22) which IMO were somehow related to using |
Thank you @W-E - I thought I had a bad sensor, but your work has fixed this. I hope Adafruit integrate this fix soon. |
Been fighting with read errors for two days... @pm-cz suggested change seems to have eliminated every read error I was getting... Before the "fix" I was getting a 20-25% error rate on my readings when running pubsubclient "client.publish" commands... Now I'm getting 0% error rates running at full tilt... Since this issue seems to have been around for two years now, i'm not really holding my breath on an official fix any time soon. |
Applied fix as suggested here: adafruit/DHT-sensor-library#48
Hi, Thank You! :-) |
Try newest library - reopen if still an issue. |
I abandoned DHTxx sensors due to their very low and inconsistent accuracy. Anyhow, I will have a look at some time.
|
@W-E what sensors do you use now? |
use sht21 or sht2x family |
Dear all,
there is an mistake in your DHT11 init sequence. Admittedly, the DHT11 datasheet is not very clear here. Anyhow, after you pulled the data line low for the at least 18 milliseconds to signal the DHT11 a start, you should NOT actively pull it up. As soon as the DHT does see the low-high transition on the data line ( Well "as soon is around 12 usec later ) it tries to pull it down. If the data line is still held "high" by the uC at that time, you have more or less a short circuit on the data line with the uC pulling up and the DHT pulling down.
This can clearly be seen on an oscilloscope if your lib is used "as is".
You need to change the uC pin state to "INPUT" after the initial >18 msec LOW phase right away, without actively pulling up before.
Luckily this bugfix is as easy as commenting out two lines, see below:
'''
// End the start signal by setting data line high for 40 microseconds.
// digitalWrite(_pin, HIGH);
// delayMicroseconds(40);
// WEB: This is an error. DHT tries to pull the line low as soon as it came back to high.
// therefore the low-high transition after the start signal "low" needs to be realised by
// the pullup resistor only, uC pin must already be in INPUT mode.
'''
See attached before-after scope screenshots
before: (your lib as-is )
after, with fixed startup sequence:
With best regards,
Wolfgang Ebersbach
The text was updated successfully, but these errors were encountered: