fix: restore correct COUNT values for DHT timing threshold#28
Merged
Conversation
Commit 69cabab incorrectly reduced all COUNT values, breaking DHT11 sensor reads on 16 MHz AVR (Arduino Uno R3) and likely other platforms. COUNT is the threshold to distinguish '0' bits (~26µs pulse) from '1' bits (~70µs pulse) in the DHT protocol. The reduced values caused all bits to be read as '1', producing garbage data. Restore the previously working values from before 69cabab. Fixes #27.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
COUNTis the pulse-width threshold used to distinguish '0' bits (~26µs) from '1' bits (~70µs) in the DHT single-wire protocol. The read loop countsdelayMicroseconds(1)iterations while the pin stays in a given state, then comparescounter > _count.On 16 MHz AVR, each loop iteration takes ~4-5µs (due to
digitalReadoverhead), so:With COUNT=2 (the broken value), even a '0' bit exceeds the threshold, causing all bits to be read as '1' → garbage data.
Fix
Restore the battle-tested COUNT values from before 69cabab. Also fix the new frequency entries (10 MHz, 20 MHz, 40 MHz) that were added with incorrect values.
Fixes #27.
Test plan