You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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():
Also my finding - I have fixed this code in DHT.cpp.
case DHT22:
case DHT21:
int16_t d = ((int16_t)data[2]) << 8 | data[3];
// msb set == negativ
if (d & 0x8000) {
d &= 0x7fff;
// 0x8000 == 0x0000 == 0)
if ( d == 0 ) d = 0x7fff;
d = 0x7fff - d;
d *= -1;
}
f = d * 0.1f;
if (S) {
f = convertCtoF(f);
}
break;
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():
The text was updated successfully, but these errors were encountered: