adafruit / adafruit/DHT-sensor-library
Problem: wrong values at negative temperatures an ESP8266 and DHT22
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
- Arduino board: ESP8266 / NodeMCU 1.0 (ESP12-E Module)
- Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.13
- installed DHT-sensor-library version: 1.4.1 / installed by Arduino IDE Lib manager
I use the DHT22 in combination with an ESP8266 and this lib.
When having negative temperatures, the resulting value of readTemperature() is -3278.6 at -0.1°C
To fix negatives values a recalculation is nessecary:
```
#include
float temperature = dht.readTemperature();
if(temperature < 0)
{
temperature = (temperature = (INT16_MAX - temperature*-10)*-0.1; - temperature*-10)*-0.1;
}
```
after some research, i figure out, that the values in data-array repressents an intager in ones complement, while the rest of data handling seems to be in BCD.
I will provide an PR to fix this issue.
Contributor guide
Research direction
The entry point named is readTemperature(); reproduce the negative-temperature case with an ESP8266/NodeMCU and DHT22, then inspect the library's temperature data handling. Done means negative readings such as -0.1°C are returned correctly without caller-side recalculation; no test file is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100