-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
DHT sensors protocol revision and refactoring #7468
DHT sensors protocol revision and refactoring #7468
Conversation
1. Only DHT22 protocol has been changed according to the issue arendst#5619. 2. noInterrupts() command moved to the begining of the reading protocol. 3. One switch created to embrace protocols for all sensors in one place for better code readability (protocols revision gathered below and placed in code comments). 4. Tested on AM2302. Usually issue arendst#5619 occured after several hours and needed power cycle reboot. Currently works without a problem for over 2 days. DHT21, DHT22, AM2301, AM2302 Specs: https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf Protocol: 1. MCU PULLS LOW data bus for 1 to 10ms to activate sensor 2. MCU PULLS UP data bus for 20-40us to ask sensor for response 3. SENSOR PULLS LOW data bus for 80us as a response 4. SENSOR PULLS UP data bus for 80us for data sending preparation 5. SENSOR starts sending data (LOW 50us then HIGH 26-28us for "0" or 70us for "1") DHT11 Specs: https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf Protocol: 1. MCU PULLS LOW data bus for at least 18ms to activate sensor 2. MCU PULLS UP data bus for 20-40us to ask sensor for response 3. SENSOR PULLS LOW data bus for 80us as a response 4. SENSOR PULLS UP data bus for 80us for data sending preparation 5. SENSOR starts sending data (LOW 50us then HIGH 26-28us for "0" or 70 us for "1") SI7021 Specs: https://www.silabs.com/documents/public/data-sheets/Si7021-A20.pdf Protocol: Reverse-engineered on arendst#735 (comment): 1. MCU PULLS LOW data bus for at 500us to activate sensor 2. MCU PULLS UP data bus for ~40us to ask sensor for response 3. SENSOR starts sending data (LOW 40us then HIGH ~25us for "0" or ~75us for "1") 4. SENSOR sends "1" start bit as a response 5. SENSOR sends 16 bits (2 bytes) of a humidity with one decimal (i.e. 35.6% is sent as 356) 6. SENSOR sends 16 bits (2 bytes) of a temperature with one decimal (i.e. 23.4C is sent as 234) 7. SENSOR sends 8 bits (1 byte) checksum of 4 data bytes
Closing to restart Travis. |
An offset for humidity could be useful too... :-) |
@ildena why offset? If it measures wrong a offset does not help. Errors are not linear. |
I would like to test further your changes due to I have several of these sensors working with Tasmota for more than 2 years and never have this issue. I'm not against this optimization, I'm in favour of it, I just want not to broke other people's setup since in reported issues the problem with these sensors were very sporadic and very low in last 2 years. |
An in addition, when do people finally start dropping these devices for way better ones. |
Regarding code changes.
So, there are no fancy changes than rational only. Regarding variability in sensor performance. |
@arendst They will definitely do that when you stop supporting bad ones ;) |
@ildena As stated in #2872, you can calibrate sensor using Commands: |
I added extra explanation to PR description:
PS. The 4th day of stable system operation without rebooting or power cycle passes. |
ok, I surrender... too many shooters :-) :-) |
There are some review comments in the code. Please, check them. I think that in the mobile version can not easily be seen. Thanks. |
@ascillato If you refer to this PR, I can't see them on the computer either. |
@ildena It's not about shooting anyone but facts and rationality. If you read these tests, you'll find that humidity reading error is a f(h,t) function, not a simple constant offset. |
Yes, on this PR. Please, click on the upper tab called changes, and you will see them. Those are not obligatory. Just small suggestions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Testing.... |
@ascillato Adrian, did you find any issues with this driver or can I release it? |
Add new DHT driver. The old driver can still be used using define USE_DHT_OLD (#7468)
Merged with additional Shelly code. Thx. |
So far this new driver is working very good. @KrzysztofPrzygoda Good job!!! 👍 Sorry for the delay on testing. |
@KrzysztofPrzygoda @arendst |
15/20 AM2301 working with ver 8.1.0.7. :(( |
That was also reported at #7717 |
@KrzysztofPrzygoda any idea? |
Is it possible that this protocol change is affecting BME280 sensors? They are running fine on 8.1.0, but with the latest beta release and the final 8.2.0 my Sonoff Basic is not showing any data from this sensors. Have the same issue with another Sonoff Basic with BME280 sensor. |
Let me guess, you are using Tasmota and not Tasmota-sensors... |
you are right...i've added the BME280 sensor like described on this page: https://github.com/arendst/Tasmota/wiki/BME280 |
For future reference: builds |
[SOLUTION FOUND HERE for null readings] - Tasmota version 8.3.1 Hi friends, I am new here but want to contribute as I think it will help many folks. |
@marlonpnz as written in another issue, I even increased the delay from 2ms to 20ms to get more stability. Check out the Ethersex DHT driver written by me for reference. |
Hi @eku, thanks you reply. |
Change delay(2) to delayMicroseconds(2000) and see if it helps (#7468)
Sorry for re-opening. If you prefer I'll create a new issue. |
Description:
Related issue (if applicable): fixes #5619
IMO, the root-cause of the problem were both: 1) DHT22 bad timings and 2)
noInterrupts()
that was switched on too late (should be on at the very beginning of the protocol). My AM2302 (with SONOFF Basic R2 on GPIO3 Serial In) has been working stable for 3 days now. Previously it hung (null readings) every few hours with power cycle as a remedy. I did not any hardware adjustments like better coords, connections etc. Just code changes and hanging is gone.Changes:
noInterrupts()
command moved at the very begining of the protocol to ensure reading stability.switch
statement created to embrace protocols for all sensors in one place for better code readability (protocols revision gathered below and placed in code comments).Revision based on:
DHT21, DHT22, AM2301, AM2302
Specs:
https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf
Protocol:
DHT11
Specs:
https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf
Protocol:
SI7021
Specs:
https://www.silabs.com/documents/public/data-sheets/Si7021-A20.pdf
Protocol:
Reverse-engineered on #735 (comment):
Checklist: