arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.85k stars 4.75k forks source link

conflict between PWM output and AM2301 sensor reading #17652

Closed scimmiettarossa closed 1 year ago

scimmiettarossa commented 1 year ago

PROBLEM DESCRIPTION

I have a Sonoff DualR2 with the last Tasmota (12.3.1); I have hacked it a bit using additional GPIOs with respect to the standard two buttons / two relays:

stat/garageswitch/RESULT = {"NAME":"DualR2_ext","GPIO":[33,416,0,1216,0,225,163,32,224,320,0,0,0,0],"FLAG":0,"BASE":39} GPIO0: Button 2 [33] (default) GPIO1: PWM 1 [416], added to drive a led stripe GPIO3: AM2301 [1216], added to monitor temperature and humidity with a DHT22 GPIO5: Relay 2 [225] (default) GPIO9: Switch 4 [163], added to monitor a door contact GPIO10: Button 1 [32] (default] GPIO12: Relay 1 [224] (default) GPIO13: Led_i 1 [320] (default)

everything works fine, if the PWM output is off, while if I set it to any value >0 (via web GUI or via domoticz or via console with the dimmer command), the readings from the DHT22 goes to "null" or "0". If I set the PWM back to 0, after a few seconds the readings are back

If I modify GPIO1 from PWM1 to RELAY3 (with the same led connected to the pin), I have no issue, both with the output ON or OFF: thereforeI'm using this configuration as a fallback solution, but in this way I can not dim the led

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [x] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
20:48:26.671 CMD: Backlog Rule1; Rule2; Rule3
20:48:26.761 MQT: stat/garageswitch/RESULT = {"Rule1":{"State":"ON","Once":"OFF","StopOnError":"OFF","Length":73,"Free":438,"Rules":"ON switch4#state DO publish domoticz/in {\"idx\":36,\"nvalue\":%value%} ENDON"}}
20:48:26.982 MQT: stat/garageswitch/RESULT = {"Rule2":{"State":"OFF","Once":"OFF","StopOnError":"OFF","Length":0,"Free":511,"Rules":""}}
20:48:27.232 MQT: stat/garageswitch/RESULT = {"Rule3":{"State":"OFF","Once":"OFF","StopOnError":"OFF","Length":0,"Free":511,"Rules":""}}
- [x] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
20:57:06.262 CMD: weblog 4
20:57:06.265 SRC: WebConsole from 192.168.1.20
20:57:06.267 CMD: Grp 0, Cmd 'WEBLOG', Idx 1, Len 1, Pld 4, Data '4'
20:57:06.273 MQT: stat/garageswitch/RESULT = {"WebLog":4}
20:57:06.456 DHT: Pin3 read 025E007BDB                ---> POWER 3 OFF (PWM off) --> DHT22 readings ok
20:57:10.450 DHT: Pin3 timeout waiting for low pulse
20:57:14.452 DHT: Pin3 timeout waiting for low pulse
20:57:18.419 DHT: Pin3 read 025D007BDA
20:57:19.010 WIF: Controllo connessione...
20:57:22.450 DHT: Pin3 timeout waiting for low pulse
20:57:26.451 DHT: Pin3 timeout waiting for low pulse
20:57:30.447 DHT: Pin3 timeout waiting for low pulse
20:57:34.446 DHT: Pin3 read 025D007BDA
20:57:36.393 WIF: Sending Gratuitous ARP
20:57:37.924 SRC: WebGui from 192.168.1.20
20:57:37.931 MQT: domoticz/in = {"idx":38,"nvalue":1,"svalue":"38","Battery":100,"RSSI":10}
20:57:37.934 MQT: stat/garageswitch/RESULT = {"POWER3":"ON"}                 ---> POWER 3 ON (PWM on) 
20:57:37.937 MQT: stat/garageswitch/POWER3 = ON
20:57:38.410 DHT: Pin3 checksum failure 000012E803 =? FA                            --> DHT22 readings KO
20:57:38.860 CFG: Salvato nella flash in FA, Conteggio 508, Byte 4096
20:57:39.009 WIF: Controllo connessione...
20:57:42.424 DHT: Pin3 checksum failure 0000000978 =? 09
20:57:46.436 DHT: Pin3 read 0000000000                            --> DHT22 readings= 0
20:57:50.437 DHT: Pin3 read 0000000000
20:57:54.435 DHT: Pin3 read 0000000000
20:57:58.444 DHT: Pin3 read 0000000000
20:57:59.002 WIF: Controllo connessione...
20:58:02.439 DHT: Pin3 read 0000000000
20:58:02.760 SRC: WebGui from 192.168.1.20
20:58:02.768 MQT: domoticz/in = {"idx":38,"nvalue":0,"svalue":"38","Battery":100,"RSSI":10}
20:58:02.771 MQT: stat/garageswitch/RESULT = {"POWER3":"OFF"}                 ---> POWER 3 OFF again (PWM off) 
20:58:02.776 MQT: stat/garageswitch/POWER3 = OFF
20:58:02.913 CFG: Salvato nella flash in F9, Conteggio 509, Byte 4096
20:58:06.409 DHT: Pin3 read 025D007BDA                            --> DHT22 readings ok again
20:58:10.446 DHT: Pin3 timeout waiting for low pulse
20:58:14.452 DHT: Pin3 timeout waiting for low pulse
20:58:18.452 DHT: Pin3 timeout waiting for low pulse
20:58:19.001 WIF: Controllo connessione...
20:58:22.440 DHT: Pin3 read 025D007BDA
etc...

TO REPRODUCE

Steps to reproduce the behavior:

switch PWM on and off

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen.

non conflict between GPIO1 (PWM and GPIO3 (sensor)

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

sfromis commented 1 year ago

Does not look like a conflict between GPIO1 and GPIO3. As the one-wire communication with the DHT22 (not a good sensor choice) is very fickle about timing, and software PWM on ESP8266 pushes the MCU hard, failure is not surprising.

scimmiettarossa commented 1 year ago

thanks, @sfromis ... do you think that with other sensors I can overcome this issue? any suggestion?

Until now I used a sonoff TH with Si7021, using a PWM output as well, with no issue: is it worth to try to use the Si7021? I have also available a DHT11 (but very inaccurate, and I think it shares the same logic), or even DS18B20 (without humidity reading, but it is not a big issue): do you think any of them is more "robust" in behaviour?

sfromis commented 1 year ago

What I'd prefer would be an I2C sensor, instead of any of those. Point being that the I2C bus communication is more robust than those one-wire protocols. But if you have good experiences with the Sonoff SI7021 wrapped as non-I2C - whatever works for you.

More generally, I'm not really in favor of trying to see those commercial devices as suitable for just adding stuff to.

scimmiettarossa commented 1 year ago

I leave the issue open until I try with alternative sensors, then I'll let you know

thanks again