adafruit / adafruit/DHT-sensor-library
Problem: DHT22 does not send data in sign-magnitude format
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
- Arduino board 1: ESP8266 / NodeMCU 1.0 (ESP12-E Module)
- Arduino board 2: ESP-WROOM-32 / ESP32 DEVKIT V1
- 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
This problem is directly connected to #177
After some more research on negative temperatures with DHT22 and ESP8266 / ESP32, i figure out, that my DHT22 sensor does not send data as expected.
This library assumed, sensor temperature data is in sign-magnitude format. This is also documented here: https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf
But this DHT22 which I have available for testing, seems to send data in two's complement format. With one exception:
During transition from positive to negative values, there is one point with sign-magnitude.
Going from 0.1°C (0x0001) -> 0°C (0x0000) -> -0°C (0x8000) -> -0.1°C (0xFFFF)
I have also a log of this, where I add a hex print of data[2]/data[3] at end of readTemperature():
```
22:07:01.473 -> 0003 0.3
22:07:01.473 -> Temperature: 0.30C
22:07:03.485 -> 8000 -3276.8
22:07:03.485 -> Temperature: -3276.80C
22:07:05.500 -> FFFD -0.3
22:07:05.500 -> Temperature: -0.30C
```
Contributor guide
Research direction
Start at readTemperature(), inspect how data[2] and data[3] are converted, and compare that behavior with the AM2302 datasheet and the reported ESP8266/ESP32 logs. Determine the expected handling of the observed negative-temperature encoding and verify that positive, zero, and negative readings produce correct values without regressing the documented format.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100