Skip to content

driver: sensor: aosong,dht: fix sensor protocol #89753

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

Merged

Conversation

moosery
Copy link
Contributor

@moosery moosery commented May 9, 2025

Fix DHT sensor protocol broken since previous change

A recent change 9eeb60c for issue #83192 improperly removed a critical line in the driver.
This commit replaces that line and moves an irq_lock to above any pin
value manipulation since the timing is critical in the DHT protocol.

This was tested with both IRQs enabled and disabled on an Arduino Giga R1 using a DHT11.

Fixes #89631

Signed-off-by: John Shelton moosery@gmail.com

…ephyrproject-rtos#83192

A recent change 9eeb60c improperly removed a critical line in the driver.

This commit replaces that line and moves an irq_lock to above any pin

value manipulation since the timing is sensitive with the DHT protocol.

This should also fix the timing issue 9eeb60c attempted to fix.

Signed-off-by: John Shelton <moosery@gmail.com>
Copy link

github-actions bot commented May 9, 2025

Hello @moosery, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@moosery
Copy link
Contributor Author

moosery commented May 9, 2025

@OmarNaffaa can you please check this with your board setup? Remember to enable the IRQ locks in your prj.conf and use GPIO_ACTIVE_LOW on your GPIO pin. DHT's also require either a MCU pullup (like GPIO_PULL_UP) or a pull up resistor on the data line.

Copy link

sonarqubecloud bot commented May 9, 2025

@OmarNaffaa
Copy link
Contributor

OmarNaffaa commented May 9, 2025

I was able to poll with a DHT22 every second for ~1 hour with these changes if I disable WiFi on my device, but with WiFi on I immediately get a -5 error code when trying to fetch.

Since it does work with WiFi off on my board I think your fix is valid, but I would likely need to do some digging on my end to know more (maybe I'm doing something wrong on my project).

image

@moosery
Copy link
Contributor Author

moosery commented May 26, 2025

I've tested the driver with DHT11's and DHT22's on the ESP32-Wrover, NXP MIMXRT1060-EVKB, and the Arduino Giga R1. It has executed without fail for days.

However, there is some timing issue on that ESP32-Wrover board in regards to using wifi along with the DHT's (I am able to duplicate the issue that @OmarNaffaa sees when using wifi but only on the ESP32-Wrover).

I believe we need to go ahead and accept this pull request to get the driver back to working for other boards, and continue to work on figuring out what is causing the problem when wifi is enabled on a separate issue.

@moosery
Copy link
Contributor Author

moosery commented May 27, 2025

@MaureenHelm this PR has kind of stalled. Is it possible to get it moving again?

@kartben kartben merged commit 7af5523 into zephyrproject-rtos:main May 31, 2025
27 checks passed
Copy link

Hi @moosery!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

@moosery moosery deleted the dht-driver-protocol-fix-89631 branch May 31, 2025 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

driver: sensor: aosong,dht: sensor bit reading broken since change #83192
5 participants