adafruit / adafruit/DHT-sensor-library

DHT12 - Evaluating negative temperatures

Open
#165 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.2k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

- Arduino board: Not relevant (based on visual inspection of code)

- Arduino IDE version (found in Arduino -> About Arduino menu): Also not relevant (based on visual inspection of code

- List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too):

In file: DHT.cpp,
In function: float DHT::readTemperature(bool S, bool force)
While handling the DHT12 (extracting the float value from the 5-byte data received from the device
Code lines 100-105 are:
case DHT12:
f = data[2];
f += (data[3] & 0x0f) * 0.1;
if (data[2] & 0x80) {
f *= -1;
}

Bit 7 of data[2] is included in the float value, AND is used as a sign bit.
Surely this can't be right.
E.g. if data[2] = 0x80 and data[3]=0x00
then this will return a temperature of -128.0 degreesC

Contributor guide

Open the contributing guide

Research direction

Read DHT.cpp and inspect DHT::readTemperature(bool S, bool force), especially the DHT12 handling at lines 100-105. Reproduce the reported case with data[2] = 0x80 and data[3] = 0x00, then verify that the decoded negative temperature no longer includes the sign bit in its magnitude.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.