Skip to content

Fix gpio/dht_sensor - #793

Open
keytouch wants to merge 1 commit into
raspberrypi:developfrom
keytouch:fix-dht
Open

keytouch wants to merge 1 commit into
raspberrypi:developfrom
keytouch:fix-dht

Conversation

@keytouch

Copy link
Copy Markdown

As I was testing, without prior sleep_us(2) before waiting for low signal, it turned out to be Bad data.
Tested on DHT11, I don't own a DHT22, but the line protocol should be the same.

  • sleep_us(2) before waiting for low signal

  • check iteration variable j to avoid out of bound write on data[5]

  • flip last directly instead of polling again

  • 1 bit is 70us and 0 bit is about 26-28us, fix the check on polling count

@github-actions

Copy link
Copy Markdown

Please do not submit against master, use develop instead

@keytouch
keytouch changed the base branch from master to develop September 26, 2026 10:30
@keytouch
keytouch marked this pull request as draft September 26, 2026 10:31
@keytouch
keytouch marked this pull request as ready for review September 26, 2026 10:31
Comment thread gpio/dht_sensor/dht.c Outdated
Comment thread gpio/dht_sensor/dht.c Outdated
Comment thread gpio/dht_sensor/dht.c Outdated
* sleep_us(2) before waiting for low signal

* check iteration variable j to avoid out of bound write on data[5]

* flip last directly instead of polling again

* 1 bit is 70us and 0 bit is about 26-28us, fix the check on polling count
@lurch

lurch commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Changes look reasonable to me, but I don't have a DHT-11 or DHT-22 sensor to check that the code still works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants