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

ESP32: need a module DHT21/22/AM2301 #1874

Closed
LDmitryL opened this issue Mar 22, 2017 · 19 comments
Closed

ESP32: need a module DHT21/22/AM2301 #1874

LDmitryL opened this issue Mar 22, 2017 · 19 comments

Comments

@LDmitryL
Copy link

LDmitryL commented Mar 22, 2017

Missing feature

Need the library to support reading the sensors of the type DHT21/22/AM2301

Justification

This is the most convenient and easy way to get humidity.
And most importantly low cost!
Which is very important for home automation.

Workarounds

API for module dht from ESP8266 good


Subset of API from ESP8266.

dht.read2x(pin)

Read a DHT21/22/AM2301 sensor at given pin.
Returns status, temp, humi, temp_dec, humi_dec with repsective support for float and integer build.

dht.read11(pin)

Read a DHT11 sensor at given pin.
Returns status, temp, humi, temp_dec, humi_dec with repsective support for float and integer build.

@devsaurus
Copy link
Member

I'd propose to use the RMT peripheral to implement the low-level protocol for talking to this family of sensors. An RX channel can capture data bits from the sensor in read direction and decoding to '0' and '1' is done based on the duration between the signal edges. This worked very well for the ow protocol.

The start impulse in TX direction can be done with simple gpio writes, roughly timed by vTaskDelay().

@devsaurus devsaurus moved this from TODO to API definition in ESP32 i.e. ESP-IDF Mar 29, 2017
@devsaurus
Copy link
Member

Had a look at the existing dht module. API seems to be ok, although I don't plan to implement dht.readxx() since the detection of DHT11 vs. DHT21/22 etc. appears to be unreliable in my opinion.

@devsaurus devsaurus self-assigned this Mar 30, 2017
@devsaurus devsaurus moved this from API definition to Implementation in ESP32 i.e. ESP-IDF Mar 30, 2017
@devsaurus
Copy link
Member

There's a draft version available in my repo over at https://github.com/devsaurus/nodemcu-firmware/tree/dev-esp32-dht

I've tested it with an AM2302 sensor that happened to be in my stock. Checking against a DHT11 is still required before merge to upstream since this variant triggers substantially different paths in the code.

@LDmitryL
Copy link
Author

LDmitryL commented Apr 4, 2017

@devsaurus
Noticed a compile error if you remove the option UART console auto baud detection in platform config in component config

CC user_main.o
C:/msys32/home/LDL/nodemcu-firmware/components/base_nodemcu/user_main.c: In function 'app_main':
C:/msys32/home/LDL/nodemcu-firmware/components/base_nodemcu/user_main.c:160:19: error: 'CONFIG_CONSOLE_BIT_RATE_AUTO' undeclared (first use in this function)
cfg.auto_baud = CONFIG_CONSOLE_BIT_RATE_AUTO;
^
C:/msys32/home/LDL/nodemcu-firmware/components/base_nodemcu/user_main.c:160:19: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [/home/LDL/esp-idf/make/component_wrapper.mk:177: user_main.o] Error 1
make: *** [C:/msys32/home/LDL/esp-idf/make/project.mk:386: base_nodemcu-build] Error 2

@devsaurus
Copy link
Member

Thanks for reporting @LDmitryL! I'll have a look.

@devsaurus
Copy link
Member

Running the contained functions triggers an error message in the RMT driver code. I've reported this to Espressif and suggested a fix with espressif/esp-idf#492.

Furthermore, there appear to be interoperability issues between this module and the ow module: Executing dht.read*() kills the RMT channels of the onewire protocol implementation (see espressif/esp-idf#486). This will become even worse with the ws2812 module from #1896. I need to wait for Espressif's response until I can proceed.

@jmattsson:
What would be the best way to include the fix from espressif/esp-ifd#486 into our code base before they ran it through their development mill? Is it acceptable to temporarily reference the sdk/esp32-esp-idf submodule from my PR branch? Or can I place a .patch file somewhere in our repo which is applied before compilation starts?

@LDmitryL
Copy link
Author

LDmitryL commented Apr 6, 2017

Yes, indeed there is a bug in the module DHT module in conjunction with the OW. Separately they work but together no.

[0;31mE (153312) rmt: RMT[5] ERR [0m
[0;31mE (153312) rmt: status: 0x14140180 [0m
[0;31mE (153312) rmt: rmt_set_tx_thr_intr_en(347): RMT EVT THRESH ERR [0m

the message after the call dht.read2x(port). After that just reset.

@devsaurus
Copy link
Member

Noticed a compile error if you remove the option UART console auto baud detection in platform config in component config

Fixed in dev-esp32 branch.

@devsaurus
Copy link
Member

Module merged into dev-esp32 branch.

@zelll
Copy link
Contributor

zelll commented Apr 21, 2017

I tried to build a release version, but got

...
CC dht.o
D:/tmp/msys32/home/0j/nodemcu-firmware/components/modules/dht.c: In function 'ldht_read_generic':
D:/tmp/msys32/home/0j/nodemcu-firmware/components/modules/dht.c:75:29: error: 'humi' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   int humidec = (int)((humi - (int)humi) * 1000);
                             ^
D:/tmp/msys32/home/0j/nodemcu-firmware/components/modules/dht.c:74:29: error: 'temp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   int tempdec = (int)((temp - (int)temp) * 1000);
                             ^
cc1.exe: some warnings being treated as errors

BTW, I did not select dht module.
# CONFIG_LUA_MODULE_DHT is not set

@devsaurus
Copy link
Member

I ran a build on dev-esp32 branch just the other day without issues.
This error happened for you on this branch as well?

@zelll
Copy link
Contributor

zelll commented Apr 21, 2017

I meant choosing build for release in menuconfig, not master branch for 8266...

@devsaurus
Copy link
Member

I see.

The error was correct and I just pushed a fix for it. Strangely it's not reported for a debug build...

@LDmitryL
Copy link
Author

@devsaurus Managed to overcome the problem with RMT?

@devsaurus
Copy link
Member

Interoperability with onewire remains problematic since espressif/esp-idf#486 is still waiting for a resolution.

@LDmitryL
Copy link
Author

LDmitryL commented Jun 2, 2017

@devsaurus I noticed that the problem with RMT was fixed. (message Yes, was fixed by #492, closing. in espressif/esp-idf#473 ). Which, in turn, referred to the problem with the ws2812 module. #1896
Does this mean that the problem is fixed and this module too?
Last update is not working with nodemcu module DHT21/22/AM2301 and OW at the same time. The system hangs without displaying any messages.

@devsaurus
Copy link
Member

devsaurus commented Jun 3, 2017

No, the root cause for that is espressif/esp-idf#486.
Hope that concrete fix with espressif/esp-idf#669 is considered now quickly.

@devsaurus
Copy link
Member

I updated to latest esp-idf which contains a fix for espressif/esp-idf#486. Waiting for a response to espressif/esp-idf#719.

igrr pushed a commit to espressif/esp-idf that referenced this issue Sep 8, 2017
…source only when all the handlers disabled.

also document handlers sharing a same source.

TW#13454, nodemcu/nodemcu-firmware#1874

Breaking change: handles assigned to a same source should have the same flag now.
@LDmitryL
Copy link
Author

LDmitryL commented Nov 22, 2017

@devsaurus This fix is already included?

@devsaurus devsaurus added the ESP32 label Jan 5, 2018
@devsaurus devsaurus moved this from Implementation to Done in ESP32 i.e. ESP-IDF Jul 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants