Skip to content
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 working with ESP Easy on Wemos D1 #2569

Closed
Daniel-Ebert opened this issue Aug 26, 2019 · 105 comments · Fixed by #2571
Closed

DHT22 not working with ESP Easy on Wemos D1 #2569

Daniel-Ebert opened this issue Aug 26, 2019 · 105 comments · Fixed by #2571
Labels
Category: Plugin Related to supported sensors Status: Needs Info Needs more info before action can be taken Type: Documentation

Comments

@Daniel-Ebert
Copy link

Daniel-Ebert commented Aug 26, 2019

Hello alltogehter,

I have connected my DHT22 properly to my Wemos D1 but can´t get it to work with ESP Easy. Many "normal" program scripts to output the temperature and humidity to the serial monitor also didn´t work, but this here finally did the trick! : https://chewett.co.uk/blog/1476/using-the-dht22-temperature-sensor-with-a-wemos-d1-mini-esp8266/

There is also a modified library involved, related to the 3,3V limitation of the Wemos D1´s digital GPIOS. The EspEasy displaying me in the webinterface "nan" may be also caused by the "normal" library used by EspEasy, calculating the values with 5V. I´d be very grateful if someone knew how to resolve this problem.

Best regards Daniel

EDIT: I figured out, that "nan" is only displayed when I set the setting "IDX/Variable". Otherwise simply 0.0 is shown.

@uzi18
Copy link
Contributor

uzi18 commented Aug 26, 2019

for this sensor none of libraries calculate with 5V or 3V3 because it is a digital sensor, so you receive value from sensor itself

@TD-er
Copy link
Member

TD-er commented Aug 26, 2019

OK, so apparently it is suggested to use this DHTesp library

I have quickly browsed through the code of that library, and some of the code does look familiar, so maybe that library does have some fixes compared to the version we use.

But I don't remember a lot of issues reported with this plugin, so I would also like to know what exact sensor your are running and more info about your board and how it is connected.

@TD-er TD-er added Category: Plugin Related to supported sensors Status: Needs Info Needs more info before action can be taken labels Aug 26, 2019
@uzi18
Copy link
Contributor

uzi18 commented Aug 26, 2019

will try to compare it with our implementation

@uzi18
Copy link
Contributor

uzi18 commented Aug 26, 2019

@TheAppService lets start with debug log from reading your sensor under espeasy please

@TD-er I see initial timings are a little bit different, but lest check debug log so. we will know maybe what is realy wrong
We support bunch of DHT like sensors, so maybe just DHT22 is wrong

@TD-er
Copy link
Member

TD-er commented Aug 26, 2019

I know there was an issue about it about half a year ago (or maybe longer?) that was about changing the timing of some of the DHT sensors, but not all.

@uzi18
Copy link
Contributor

uzi18 commented Aug 26, 2019

you have added some error logging, so we can use it now =)

@Daniel-Ebert
Copy link
Author

Daniel-Ebert commented Aug 27, 2019

Alright, well I will give you more information about my setup shortly! But first, maybe a suggestion of mine - If the DHT 22 is the only affected one on Wemos Boards, maybe replacing the plugin wouldn´t be a good idea, maybe for testing purposes adding the new plugin especially for Wemos boards or maybe "Updated ESP Compatibility Plugin" would be suitable...

Sensor Type:
"ASAIR AM 2302" - "SN: 180497FD9"
Board is a Wemos D1 Ver. 2015-08
My Circuit is exactly like this here, although I have a Wemos D1 instead of the D1 Mini
3,3V to VCC Pin on Sensor, 3,3V over a 10kOhm resistor into the data- line, Data-line of the sensor to Pin D2, Ground to Ground
wemos_d1_mini_dht22_bb
DEBUG Log will follow in a nother comment when I have found the feature in ESP Easy

grafik

grafik

@Daniel-Ebert
Copy link
Author

In the DEBUG log i can only find this: (Maybe you can give me a hint how I can exactly debug the sensor...
66149 : WD : Uptime 1 ConnectFailures 0 FreeMem 28888 96150 : WD : Uptime 1 ConnectFailures 0 FreeMem 28760 126151 : WD : Uptime 2 ConnectFailures 0 FreeMem 28728 156152 : WD : Uptime 2 ConnectFailures 0 FreeMem 28696 186153 : WD : Uptime 3 ConnectFailures 0 FreeMem 28680 216154 : WD : Uptime 3 ConnectFailures 0 FreeMem 28664 246155 : WD : Uptime 4 ConnectFailures 0 FreeMem 28648 276156 : WD : Uptime 4 ConnectFailures 0 FreeMem 28616 306157 : WD : Uptime 5 ConnectFailures 0 FreeMem 28584 336158 : WD : Uptime 5 ConnectFailures 0 FreeMem 28568

@uzi18
Copy link
Contributor

uzi18 commented Aug 27, 2019

If you are using serial connection, than in advenced settings change log level for serial to debug

@TD-er
Copy link
Member

TD-er commented Aug 27, 2019

Hmm what version of ESPeasy are you running?
This looks rather old.

@Daniel-Ebert
Copy link
Author

Booting Build nr:120 (I thought this was the newest...)
I set the serial log level to 5 (Hope this is high enough) but I´m only getting this output: https://gist.github.com/TheAppService/0d47f76b3462b988c612007afeb3d9e3

@Daniel-Ebert
Copy link
Author

"please update for latest version, R120 is obsolete." -- So i should youse the mega Versions ? Maybe you should clarify, that the "current stable" on this site here https://www.letscontrolit.com/wiki/index.php/ESPEasy is rather old...

@uzi18
Copy link
Contributor

uzi18 commented Aug 27, 2019

yes, try mega build, mega have some problems and is not rocksolid, but has lots of bugs resolved

@Daniel-Ebert
Copy link
Author

Alright, I updated it but the log still "only" says 40797 : DHT : No Reading
60744 : DHT : No Reading

@Daniel-Ebert
Copy link
Author

grafik
Just tested it again with the simple sketch under the exact same conditions and voila ;D

@Daniel-Ebert
Copy link
Author

My settings should be correct or do you think otherwise?
grafik
grafik
grafik
grafik

@AxelMilb
Copy link

Use 4,7kOhm resistor

@Daniel-Ebert
Copy link
Author

I can try to "build" one out of the resistors I have but I won´t exactly be able to hit 4,7kOhm. Is this really neccessary ? I have one perfectly working sensor on my raspberry with a 10kOhm resistor...

@AxelMilb
Copy link

I have a DHT22 on a Wemos D1 mini with 4.7kOhm resistor.
The specifications are 4.7k - 10K
https://www.letscontrolit.com/wiki/index.php?title=DHT11_DHT22
DHT22 defect? ESP alright? Cold solder joint?

@Daniel-Ebert
Copy link
Author

grafik
Just tested it again with the simple sketch under the exact same conditions and voila ;D

Well @AxelMilb as i tested it with the exact same setup using the sketch you see above, it is generally working...

@Daniel-Ebert
Copy link
Author

The specifications are 4.7k - 10K

Ah, one more question, do you have it connected to 5V or 3,3V?
And I don´t know, maybe something has changed concerning this sensor / there are maybe also different types on the market... Therefore maybe the devs could/ and maybe already had a look over the library to maybe introduce a little compatiblity mode with the other library

@uzi18
Copy link
Contributor

uzi18 commented Aug 27, 2019

You can use 2x10kOhm in parallel connection so it will be about 5kOhm

@uzi18
Copy link
Contributor

uzi18 commented Aug 27, 2019

Assume DHT22 works for you now =)

uzi18 added a commit to uzi18/ESPEasy that referenced this issue Aug 27, 2019
- use delays according to datasheets
- set bus high after a request for every type of sensor (this may fix problems with pullup resistors)

fixes letscontrolit#2569
@uzi18
Copy link
Contributor

uzi18 commented Aug 27, 2019

@TheAppService "no reading" means no data from sensor, it could be related to initial timing or pullup resistor

This sensor works with 3V3 and 5V.

@TD-er some improvements here #2571

@TD-er
Copy link
Member

TD-er commented Aug 27, 2019

A Test build for PR #2571.

@uzi18
Copy link
Contributor

uzi18 commented Aug 27, 2019

@TheAppService please try this test build and give us debug log, thanks

@uzi18
Copy link
Contributor

uzi18 commented Jan 27, 2020

@thenightfighter as @TD-er suggests, try on other gpio pins.
We also thinked about some timing issues between builds/boards
(if you have selae logic analyzer it could be big help here).

@thenightfighter
Copy link

@uzi18 Tried also D1 yesterday and got still "nan" results.

I don't have an logic analyzer, sry.

@thenightfighter
Copy link

Tested D0, D3, D4, D5, D6, D7 and D8 with mega-01022018 receiving "0.00" on temperature and humidity.
Tested D4 with mega-20190106 and it works! Got Temperature at 20.70 C° and Humidity at 49.20%.
Tested D4 with mega-20191208 and it works too... My wifi credentials are also there, is there any persistent space? I can't reproduce the error anymore :(.

@TD-er
Copy link
Member

TD-er commented Jan 27, 2020

Just leave it unpowered for a while (few minutes?) and try again.
As far as I know, the DHT's do not have a persistent memory.

@georgep56
Copy link

georgep56 commented Jan 27, 2020 via email

@thenightfighter
Copy link

Flashed mega-20191208 first, before I asked here for some help/ideas. A few min ago I tried mega-01022018 with different pins and seeing 0.00. After that I flashed mega-20190106 and it worked. Then I flashed mega-20191208 and it also works.

@TD-er hmm but why does the wemos know my wifi credentials after "flashing" a newer versopm with the esptool?

@TD-er
Copy link
Member

TD-er commented Jan 27, 2020

@TD-er hmm but why does the wemos know my wifi credentials after "flashing" a newer versopm with the esptool?

If you switch between ESPEasy versions, then the settings will still be there.

The flash layout is:

  • sketch + OTA update space
  • SPIFFS filesystem.

As long as the filesystem area is not erased, the settings will be kept.

@georgep56
Copy link

georgep56 commented Jan 27, 2020 via email

@CONSULitAS
Copy link

CONSULitAS commented Sep 7, 2020

With ESP_Easy_mega_20200812_normal_ESP8266_4M1M.bin on Wemos D1 mini with DHT Shield (DHT22 on D4) there is the same problem:

Fresh system, never flashed with ESP Easy:

17:42:37.301 -> 2958 : Info  : WIFI : Connecting xxx attempt #1
17:42:37.301 -> 2962 : Info  : Webserver: start
17:42:37.335 -> 2986 : Info  : WIFI  : Scan finished, found: 9
17:42:37.335 -> 2988 : Info  : WIFI  : Selected: xxx CC:CE:1E:E1:B0:F5 Ch:1 (-79dBm) WPA/WPA2/PSK
17:42:37.372 -> 3028 : Info  : DHT  : Temperature: 27.70
17:42:37.372 -> 3029 : Info  : DHT  : Humidity: 39.90
17:42:38.672 -> 4320 : Info  : WD   : Uptime 0 ConnectFailures 0 FreeMem 24144 WiFiStatus WL_DISCONNECTED
17:42:40.420 -> 6094 : Info  : WIFI : Connected! AP: xxx (CC:CE:1E:E1:B0:F5) Ch: 1 Duration: 3124 ms
17:42:40.595 -> 6255 : Info  : firstLoopConnectionsEstablished
17:42:40.628 -> 6287 : Error : MQTT : Intentional reconnect
17:42:40.662 -> 6336 : Info  : MQTT : Connected to broker with client ID: ESP_Easy_0
17:42:40.662 -> 6338 : Info  : Subscribed to: M20/XX/XX/ESP-Easy/#
17:42:40.912 -> 6593 : Info  : DHT  : Temperature: 27.60
17:42:40.946 -> 6594 : Info  : DHT  : Humidity: 40.60
17:42:50.922 -> 16593 : Info  : DHT  : Temperature: 27.70
17:42:50.922 -> 16594 : Info  : DHT  : Humidity: 38.20
17:43:00.919 -> 26593 : Info  : DHT  : Temperature: 27.60
17:43:00.919 -> 26594 : Info  : DHT  : Humidity: 38.30
17:43:08.612 -> 34296 : Info  : WD   : Uptime 1 ConnectFailures 0 FreeMem 22328 WiFiStatus WL_CONNECTED
17:43:10.922 -> 36593 : Info  : DHT  : Temperature: 27.60
17:43:10.922 -> 36594 : Info  : DHT  : Humidity: 38.10
17:43:20.926 -> 46593 : Info  : DHT  : Temperature: 27.60
17:43:20.926 -> 46594 : Info  : DHT  : Humidity: 38.20
17:43:30.938 -> 56593 : Info  : DHT  : Temperature: 27.60
17:43:30.938 -> 56593 : Info  : DHT  : Humidity: 39.00
17:43:38.612 -> 64296 : Info  : WD   : Uptime 1 ConnectFailures 0 FreeMem 22328 WiFiStatus WL_CONNECTED
17:43:40.938 -> 66593 : Info  : DHT  : Temperature: 27.60
17:43:40.938 -> 66594 : Info  : DHT  : Humidity: 38.40
...

then after pressing reset:

17:44:35.218 -> 
INIT : Booting version:  (ESP82xx Core 5d3af165, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support)
17:44:35.256 -> 84 : Info  : INIT : Free RAM:34896
17:44:35.256 -> 85 : Info  : INIT : Warm boot #1 Last Task: Background Task Last systime: 119 - Restart Reason: External System
17:44:35.256 -> 86 : Info  : FS   : Mounting...
17:44:35.329 -> 110 : Info  : FS   : Mount successful, used 75802 bytes of 957314
17:44:35.329 -> 184 : Info  : FS   : Success garbage collection
17:44:35.366 -> 209 : Info  : CRC  : SecuritySettings CRC   ...OK 
17:44:35.467 -> 317 : Info  : INIT : Free RAM:32176
17:44:35.467 -> 317 : Info  : INIT : I2C
17:44:35.467 -> 318 : Info  : INIT : SPI not enabled
17:44:35.574 -> 422 : Info  : INFO : Plugins: 46 [Normal] (ESP82xx Core 5d3af165, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support)
17:44:35.678 -> 526 : Info  : WIFI : Set WiFi to STA
17:44:35.784 -> 629 : Info  : WIFI : Connecting xxx attempt #1
17:44:35.784 -> 634 : Info  : Webserver: start
17:44:35.784 -> 635 : Info  : Time set to 119.000 Time adjusted by 118365.00 msec. Wander: 32.88 msec/second
17:44:35.784 -> 637 : Info  : Current Time Zone: STD time start: 1970-10-25 03:00:00 offset: 0 min
17:44:35.818 -> 639 : Info  : Local time: 1970-01-01 00:01:59
17:44:35.854 -> 699 : Info  : DHT  : No Reading
17:44:36.867 -> 1709 : Info  : WIFI : Connected! AP: xxx (CC:CE:1E:E1:B0:F5) Ch: 1 Duration: 1046 ms
17:44:36.935 -> 1777 : Info  : firstLoopConnectionsEstablished
17:44:37.039 -> 1896 : Error : MQTT : Intentional reconnect
17:44:37.110 -> 1943 : Info  : MQTT : Connected to broker with client ID: ESP_Easy_0
17:44:37.110 -> 1945 : Info  : Subscribed to: M20/XX/XX/ESP-Easy/#
17:44:37.110 -> 1973 : Info  : WD   : Uptime 0 ConnectFailures 0 FreeMem 23408 WiFiStatus WL_CONNECTED
17:44:37.350 -> 2197 : Info  : DHT  : No Reading
...

Then remove power, wait, boot and press reset after 3rd successful reading:

17:51:34.429 -> ⸮�⸮⸮⸮I⸮!҅<⸮⸮⸮99⸮⸮⸮⸮,i⸮⸮=⸮(;�⸮9<⸮⸮⸮ق⸮⸮⸮
17:51:36.439 -> 2736 : Info  : WIFI : Connecting xxx attempt #1
17:51:36.439 -> 2740 : Info  : Webserver: start
17:51:36.476 -> 2764 : Info  : WIFI  : Scan finished, found: 11
17:51:36.476 -> 2766 : Info  : WIFI  : Selected: xxx 44:4E:6D:15:B1:5A Ch:11 (-72dBm) WPA/WPA2/PSK
17:51:36.513 -> 2806 : Info  : DHT  : Temperature: 27.70
17:51:36.513 -> 2806 : Info  : DHT  : Humidity: 38.30
17:51:37.787 -> 4097 : Info  : WD   : Uptime 0 ConnectFailures 0 FreeMem 24048 WiFiStatus WL_DISCONNECTED
17:51:39.797 -> 6098 : Info  : WIFI : Connected! AP: xxx (CC:CE:1E:E1:AE:4E) Ch: 1 Duration: 3352 ms
17:51:39.906 -> 6190 : Info  : firstLoopConnectionsEstablished
17:51:39.941 -> 6254 : Error : MQTT : Intentional reconnect
17:51:40.012 -> 6298 : Info  : MQTT : Connected to broker with client ID: ESP_Easy_0
17:51:40.012 -> 6299 : Info  : Subscribed to: M20/XX/XX/ESP-Easy/#
17:51:40.259 -> 6554 : Info  : DHT  : Temperature: 27.70
17:51:40.259 -> 6555 : Info  : DHT  : Humidity: 39.20
17:51:50.244 -> 16554 : Info  : DHT  : Temperature: 27.70
17:51:50.244 -> 16554 : Info  : DHT  : Humidity: 38.80
17:51:55.743 -> {d�d⸮⸮|�⸮d⸮<��⸮d⸮�c|⸮⸮�⸮�⸮r⸮c⸮�c⸮⸮'n⸮lgg⸮⸮⸮�c�x⸮⸮drlsdx⸮g⸮��⸮d�Ĝ�b�o⸮|�⸮d⸮⸮c⸮⸮oo⸮�l⸮⸮d`�⸮��'n�l`���n{⸮⸮⸮g�c�l`��s⸮⸮oc�d`�⸮⸮⸮��⸮�⸮⸮{rl⸮⸮n⸮�⸮U84 : Info  : 
17:51:55.848 -> 
17:51:55.848 -> 
INIT : Booting version:  (ESP82xx Core 5d3af165, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support)
17:51:55.848 -> 85 : Info  : INIT : Free RAM:34896
17:51:55.884 -> 86 : Info  : INIT : Warm boot #1 Last Task: Background Task Last systime: 21 - Restart Reason: External System
17:51:55.884 -> 87 : Info  : FS   : Mounting...
17:51:55.921 -> 111 : Info  : FS   : Mount successful, used 75802 bytes of 957314
17:51:55.921 -> 136 : Info  : CRC  : SecuritySettings CRC   ...OK 
17:51:56.024 -> 243 : Info  : INIT : Free RAM:32272
17:51:56.024 -> 244 : Info  : INIT : I2C
17:51:56.024 -> 244 : Info  : INIT : SPI not enabled
17:51:56.132 -> 348 : Info  : INFO : Plugins: 46 [Normal] (ESP82xx Core 5d3af165, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support)
17:51:56.238 -> 452 : Info  : WIFI : Set WiFi to STA
17:51:56.313 -> 555 : Info  : WIFI : Connecting xxx attempt #1
17:51:56.313 -> 560 : Info  : Webserver: start
17:51:56.313 -> 561 : Info  : Time set to 21.000 Time adjusted by 20439.00 msec. Wander: 5.68 msec/second
17:51:56.346 -> 563 : Info  : Current Time Zone: STD time start: 1970-10-25 03:00:00 offset: 0 min
17:51:56.346 -> 565 : Info  : Local time: 1970-01-01 00:00:21
17:51:56.380 -> 625 : Info  : DHT  : No Reading
17:51:57.392 -> 1635 : Info  : WIFI : Connected! AP: xxx (CC:CE:1E:E1:AE:4E) Ch: 1 Duration: 1053 ms
17:51:57.464 -> 1710 : Info  : firstLoopConnectionsEstablished
17:51:57.535 -> 1776 : Error : MQTT : Intentional reconnect
17:51:57.608 -> 1822 : Info  : MQTT : Connected to broker with client ID: ESP_Easy_0
17:51:57.608 -> 1823 : Info  : Subscribed to: M20/XX/XX/ESP-Easy/#
17:51:57.679 -> 1899 : Info  : WD   : Uptime 0 ConnectFailures 0 FreeMem 23448 WiFiStatus WL_CONNECTED
17:51:57.853 -> 2075 : Info  : DHT  : No Reading
17:52:07.848 -> 12075 : Info  : DHT  : No Reading
...

This is reproducible!

🙅

Hardware used:
IMG_3363

@TD-er
Copy link
Member

TD-er commented Sep 7, 2020

Hmm, @uzi18 made this change in November 2019: 88c6887#diff-63c481456206c5a2f90a396a7a688f2e

That was already some tweak of the category "hmm if it's that timing critical, we will see more reported issues".
That tweak was for the DHT11 and you're reporting issues with DHT22.
So I guess there will be a similar fix.

@TD-er TD-er reopened this Sep 7, 2020
@CONSULitAS
Copy link

Interesting!

@thenightfighter proposed to use https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTstable

There https://github.com/RobTillaart/Arduino/blob/2b97b8d4beccf1db29de0fb1c77238ce7e21aa3c/libraries/DHTstable/dht.h#L29 we find

const int DHTLIB_DHT_WAKEUP      = 1;

leading to https://github.com/RobTillaart/Arduino/blob/2b97b8d4beccf1db29de0fb1c77238ce7e21aa3c/libraries/DHTstable/dht.cpp#L84

    int rv = _readSensor(pin, DHTLIB_DHT_WAKEUP);

leading to https://github.com/RobTillaart/Arduino/blob/2b97b8d4beccf1db29de0fb1c77238ce7e21aa3c/libraries/DHTstable/dht.cpp#L130

    delay(wakeupDelay);

to wait after setting the pin to low.

[88c6887#diff-63c481456206c5a2f90a396a7a688f2e

gives

    case P005_DHT22:  delay(2);  break;  // minimum 1ms

to wait after setting the pin to low.

So: Perhaps 2 ms here are to long? I would refactor the code to find the constants in #defines and try to reduce the delay to 1 ms.

The comment on this line made me curious! Let's look what happened:

Blame for this line
https://github.com/letscontrolit/ESPEasy/blame/88c6887946f9ae4414be7376db88d504410947b0/src/_P005_DHT.ino#L155 gives:
Bildschirmfoto 2020-09-07 um 22 30 26

How was the code before this?
https://github.com/letscontrolit/ESPEasy/blame/4a8cfd2d9b1fbfea27fa7b7829cb85a7ffc29301/src/_P005_DHT.ino#L154

    case P005_DHT11:
    case P005_DHT22:
    case P005_DHT12:  delay(18); break;  // FIXME TD-er: Must this be so long?

Oops! No delay at all! BTW: The change was made to fix this issue. 😁

I think the 2 ms delay was the again breaking change. Depending on the used pullup the needed time may vary.

  • 0 ms seems to be to short
  • 2 ms seems to be sometimes to long
  • 1 ms could fit
  • something in between may be delayMicroseconds(1500); if 1 ms does not fit either

What do you think?

@TD-er
Copy link
Member

TD-er commented Sep 7, 2020

    case P005_DHT11:
    case P005_DHT22:
    case P005_DHT12:  delay(18); break;  // FIXME TD-er: Must this be so long?

Oops! No delay at all! BTW: The change was made to fix this issue. 😁

Those case entries just are a fall-through, so they all had the 18 msec delay in that version of the code.

@CONSULitAS
Copy link

Those case entries just are a fall-through, so they all had the 18 msec delay in that version of the code.

Right. A bit late in the evening. 😁

@CONSULitAS
Copy link

BTW: Thanks for the late support. In NL it's late too (like in D). Tot ziens.

@TD-er
Copy link
Member

TD-er commented Sep 7, 2020

Graag gedaan :)

@uzi18
Copy link
Contributor

uzi18 commented Sep 8, 2020

It is minimum time to wake up sensor from datasheet.
How long are your wires and what kind of resistor you use?
Ok See now picture with module attached.

I guess something with configuration reading is wrong.

@TD-er
Copy link
Member

TD-er commented Sep 8, 2020

As the sensor does respond well initially, but starts acting badly after a reboot, I wonder if it could be the sensor is still in another state compared to what we expect in our code?
Maybe the datasheet has some information about resetting the sensor?

Edit:
The AdaFruit library does have an extra step to put the pin in high impedance first:
https://github.com/adafruit/DHT-sensor-library/blob/13d25e6b9a67b735b2e223300ef92a0ef8df6f19/DHT.cpp#L247-L267

@CONSULitAS
Copy link

CONSULitAS commented Sep 8, 2020

Solved

Solution:

  • D4 (GPIO2) does not work. 👎
  • DHT22 crashes by signals not understood while soft reset. 💣
  • Use other pin: D5 works fine. 😲
  • For Wemos DHT shield it is a hardware bug! 🐞

Findings:

A modified DHT22 example sketch (from Arduino DHT library - change baud rate to 74880) reproducible shows after soft reset:

15:11:38.191 -> 25.60	49.20	25.50	14.15
15:11:40.216 -> 25.60	49.00	25.49	14.09
15:11:42.228 -> 25.60	48.90	25.49	14.06
15:11:44.218 -> 25.60	48.80	25.49	14.03
15:11:45.089 -> 
15:11:45.089 ->  ets Jan  8 2013,rst cause:2, boot mode:(3,6)
15:11:45.089 -> 
15:11:45.089 -> load 0x4010f000, len 1392, room 16 
15:11:45.089 -> tail 0
15:11:45.089 -> chksum 0xd0
15:11:45.089 -> csum 0xd0
15:11:45.089 -> v3d128e5c
15:11:45.125 -> ~ld
15:11:45.161 -> DHTxx test!
15:11:47.218 -> Failed to read from DHT sensor!
15:11:49.272 -> Failed to read from DHT sensor!
15:11:51.320 -> Failed to read from DHT sensor!
  • Only way to reset the DHT is to cycle power. ➡️ Further investigations needed.
  • The behavior is not configurable, it is an output of the boot rom.

How to find out

You need a logic analyzer (here: Saleae logic clone with PulseView) to examine.

Working DHT (klick screenshot to zoom)
DHT decoded

Timing in detail (looks good)
DHT timing detail

After soft reset by reset button

  • Bursts on TX and D4 in first 50 ms - OOPS!

  • See 2 ms signal at 660 ms: No answer from DHT22 any more. It seems to be upset. 😬
    after reset

  • UART with 74880 baud shows - We know this stuff!
    D4 output

  • Hardware patch DHT22 data pin to D5 - Everything is fine, even after soft reset!
    after reset on D5

How to patch Wemos DHT shield

  • Scratch trace from D4 to DHT22
  • solder cable from D5 to DHT22
  • reconfigure ESP Easy
  • I have to admit: A little bit quick and dirty, but it works. 😉
    IMG_3365

BTW: Others found this, too. https://blog.zs64.net/2018/02/fixing-the-wemos-d1-mini-dht22-shield/

Proposal

Any other ideas?

Thanks for your support!

@TD-er
Copy link
Member

TD-er commented Sep 8, 2020

Great post explaining your findings and solution and indeed there should be a warning about this on the plugin documentation.

@Roos-AID
Copy link

Roos-AID commented Sep 8, 2020

This issue with burst on Tx when warm boot was also described here for the ESP-01: #2585 (comment)

So indeed a warning in the plugin documentation is a good thing to do.
There are few more pins that show strange behaviour during warm boot as described here : https://rabbithole.wwwdotorg.org/2017/03/28/esp8266-gpio.html

@Misiu
Copy link

Misiu commented Sep 9, 2020

Here is some information about this problem: adafruit/DHT-sensor-library#116
especially those two:
adafruit/DHT-sensor-library#116 (comment)
adafruit/DHT-sensor-library#116 (comment)
but I agree that changing PIN from D4 to D5 is the easiest solution, and I agree this should be added to the docs and a warning should be shown if someone chooses D4

@CONSULitAS
Copy link

Great post explaining your findings and solution and indeed there should be a warning about this on the plugin documentation.

Thanks for the feedback. Fun to work with you.

BTW: You never find problems like this without a logic analyzer and its cheap!

  • Search eBay for "usb logic analyzer 24khz" and the 6$ stuff is your friend. Really.
  • The software you need is "PulseView" (Open Source, https://sigrok.org/wiki/PulseView). Highly recommend!
  • There is also "Saleae Logic Pro" but it is not Open Source and may not be used with this cheap clones.

@TD-er
Copy link
Member

TD-er commented Sep 9, 2020

Just added it to the Wiki to make sure people are not spending lots of hour again.
Will now add it to ReadTheDocs

@CONSULitAS
Copy link

Great. Found

The DHT sensor needs to be connected to a configurable GPIO on the ESP module. In case you have a simple ESP-01 module, it's best to use the GPIO-2 pin.

there.

This should be changed, too. Mentioned here: #2585 (comment)

So #2585 and #2569 (this) can be closed.

@TD-er
Copy link
Member

TD-er commented Sep 9, 2020

As it is now documented, these issues can be closed.

@TD-er TD-er closed this as completed Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Plugin Related to supported sensors Status: Needs Info Needs more info before action can be taken Type: Documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants