-
Notifications
You must be signed in to change notification settings - Fork 13
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
Waterelf32 startPeripherals not detecting DHT22 #15
Comments
My reading of that datasheet (note however we are using AM2302, a clone of DHT22) is that the period between readings has to be >2s. However, the datasheet also states "When power is supplied to sensor, don't send any instruction to the sensor within one second to pass unstable status." Can you test with a 1s delay? Also I see that there are a number of startup functions such as |
This may be related to an issue I have been investigating where I discovered that turning off WiFi significantly increases the reliability of reading the DHT and Water temperature sensors. I have some idea of what's going on but it may need further investigation. |
This issue in the DHT library may also be relevant: adafruit/DHT-sensor-library#48 (implementing this change appears to have decreased the failure rate of my sensor) EDIT: This makes the sensor work 99% reliably in the example provided with the library (it was pretty intermittent otherwise), but it still doesn't get detected by the waterelf code. |
Sounds like a timing issue if WiFi impacts on reliability, which was typical ESP8266 but is a bit more surprising on (dual core) ESP32. Perhaps having the handler for webserver requests in the main loop is part of the problem? |
I'm shocked that despite excellent investigation and the simplicity of the fix suggested over at adafruit that it hasn't been implemented! Well found - have you tried increasing the second delay to 50us as well? |
One solution I have found that works for the water temperature sensor, but doesn't have much effect on the DHT readings to to place the library calls doing soft serial in a critical section (which disables ISRs and task pre-emption). As far as I can tell the esp8266 uses co-operative tasks (as does the original arduino for which the libraries are designed), but the esp32 uses pre-emptive tasks so I suspect the issue is that the soft-serial routines are being pre-empted by the task running the WiFi stack which would disrupt the timing, but also explain why this was not seen on esp8266. |
I've finally tracked down what seems to be the real source of the problem, which is that the arduino functions
(I also tried putting |
@Eroc33 nice work! As a small change, looking into the FreeRTOS documentation they seem to recommend using Looking at the source code for tasks.h these are just macros that essentially alias their port equivalents, however they are meant to act as interfaces so we should probably use them :) |
- Custom DHT.h correctly disables interrupts on ESP32, allowing for conistent startup of sensor - Closes hamishcunningham#15
Great stuff - nice to get the interface macros even for a hotfix... |
- Custom DHT.h correctly disables interrupts on ESP32, allowing for conistent startup of sensor - Closes hamishcunningham#15
As noted in https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf, the DHT22 has an average sensing period of 2s.
The function
startPeripherals
will occasionally not detect the DHT22 as a reading has not yet been made before initialising the sensor withdht.begin()
:fishy-wifi/ardesp/waterelf32/waterelf32.ino
Lines 816 to 823 in c7e3cb4
Adding a
delay(2000)
before line 816 seems to work as a fix for this.The text was updated successfully, but these errors were encountered: