-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
DHT22 not ready without power #106
Comments
How do you flash an DHT22? I assume you don't flash the sensor but some board.
Hypothesis I - powerThe DHT22 has 3V3 power line (assumption) which is just too low. Measure with a DMM and/or put the power to 5V. Hypothesis II - pull up resistors
Very unlikely as one would expect it would affect more than just the first reading. Hypothesis III - unwanted pulses on the lineThe DHT22 gets one or more pulses during the flashing of the board. Have a logic analyzer on the DHT22 data line to see if there are pulses during startup. |
Thanks for the detailed reply: How do you flash an DHT22? I assume you don't flash the sensor but some board. Board is https://www.aliexpress.com/item/1005006223885039.html? which appears to be following the standard DHT design. Which pins are used for flashing? Which pins connect to the DHT22? - D4 for data 3.3V and Gnd - I'll check this, but this appears to be the 'standard' design. i.e. https://oshwlab.com/adrirobot/dht-shield-for-wemos-d1-mini Hypothesis I - power Will do the measurement but can't really be editing boards - to cut power lines.
Hypothesis II - pull up resistors My thinking as well - this is more likely something to do with timing. Hypothesis III - unwanted pulses on the line Possible - though not sure how it gets those pulses. On D1 and D2 Have a logic analyzer on the DHT22 data line to see if there are pulses during startup. I don't have a logic analyzer unfortunately. My guess was that its a timing thing - that after programming its coming up quicker than with a physical reset or power cycle, and maybe the library is starting the process when the SHT22 is in the wrong state. but that doesnt quite make sense since by the time it does the first read on the SHT22 is after its connected to WiFi. Given the cycle - at the end of the read process the physical device should be in the right space for whatever you are doing during the first read after re-flash? Unless you do something different the first time on the presumption the board has just been powered up. |
electric fields, induction, just the power on sequence can give a glitch on pins before they stabilize.
You have to wait 2 seconds before the first measurement of the DHT22 But I have connected and disconnected runtime and the library always picked up the sensor, sometimes one faulty read, sometimes without.
If I understand your question correctly, yes, after a successful read the device should be ready for the next read just like after a power on start (after the 2 seconds mentioned before) . At the moment no clue what is causing this. |
The only thing that I can currently think of is that the pulling of D4 high during boot, which https://lastminuteengineers.com/wemos-d1-mini-pinout-reference/ refers to is putting the DHT22 into a strange state ? Or that the process of flashing is leaving the pin in a strange state - e.g. with a pullup, or output when it should be input or something like that, and the library code is presuming its in a default state. |
Normally one would have a pull up of 2k2-4k7 or so on the data pin (== D4) so I would not expect problems from the sensor. |
There's a 10K on it. |
Ok - so some more info - After a power-cycle or flash D4 is ~3.2V, presumably because of the 10K pullup. Two scenarios: After flash - D4 starts at ~3.2V Let me capture some debugging info |
Here's the first run - after the flash its reporting each time
|
And after power cycle
|
Problem seems to be that on the flashed run - between line 143 where it correctly sets the type to 22, and line 166 where it sets it back to 11.
|
That error from read() is DHTLIB_ERROR_SENSOR_NOT_READY which only comes from the sensor not going low around line 423, I tried changing the WAITFORSENSOR time and it didn't fix it. Also tried lengthening DHTLIB_DHT_WAKEUP and that also didn't work. I also tried using setType(22) and get same issues - the _readSensor comes back with DHTLIB_ERROR_SENSOR_NOT_READY, again failing after a flash but succeeding after a power-cycle. |
And one confirmation - if I go back to DHT11 (same shield manufacturer I think - I bought from different AliExpress store, but looks like identical board layout & printing.) then it comes up correctly and doesn't have this problem. |
So it effectively always give "Sensor not ready" except once after power cycle. D4 = 3.2V What is the voltage the sensor gets? |
Line 143 is the first guess. |
So it could be just a different (good/bad) batch of sensors? |
The pull up should pull it to 3.2V, |
Sorry - big mistake above - I was trying lots of things and keeping notes that changed as I learned more. On power cycle it only gives one Sensor Not Ready, the 2nd read (corrected below) The sensor is connected to 3.3V (all the DHT and SHT shields I found ran at 3.3V) I don't think its a good/bad batch of sensors, though I can't prove it, as the only difference for DHT22 is on flash vs power-cycle. While DHT11 works fine on both flash and power-cycle The board soldering is fine - the powerup is on a machine made board, and I've checked it - its ONLY 0V on the 2nd read (in either power cycle or flash scenario) I think its something in your sequence but I've gone thru the code line by line (with copious print statements) and can't find anything odd.
|
So your measured voltage at start does not make a difference. No ideas how to proceed |
Correct, the voltage pattern seems to be the same in both cases, and understand there may be no obvious route forward to debug this. I do notice that the first read leaves it driven to 0V which might not be a good thing, but doesn't appear to be causing this problem. And I've tried various things prior to the first read - like a digitalWrite Low or High to that pin, with no change to behavior. I've switched back to DHT11's for now - its unfortunate cos I'm heading out to do the pilot trials in a week, was originally going to use SHT30's but they had an overheating problem with the enclosure I was using (reading too hot, and too dry), probably due to vicinity to main board and not enough air-flow, so I'd bought a bunch of DHT22's because they are external to the box - don't have time to source DHT11 shields before traveling. |
I'm seeing a consistent issue with a DHT22 sensor
When I flash it, it resets and then reports
Sensor Not Ready
- and stays in that stateIf I then power cycle it, it starts reporting correctly.
This is consistent behavior - i.e. every reprogram and every power cycle.
Note - Reseting with the Reset button is not sufficient, it needs an actual power cycle.
Any ideas ?
The text was updated successfully, but these errors were encountered: