-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting high negative values on Sensor DHT22 with negative Temperatures #3494
Comments
My first impression is that you may need to convert 2-complement values. case P005_DHT22:
int16_t temp_temperature = ((dht_dat[2] & 0x7f) * 256 + dht_dat[3]);
if (dht_dat[2] & 0x80) {
temp_temperature *= -1;
}
temperature = temp_temperature * 0.1f;
humidity = ((dht_dat[0] * 256) + dht_dat[1])/10;
break; Otherwise you're throwing away negative readings. |
Gives compile error.
Is compileable but result in high negative number like without the patch. |
Hi @tomcatxx Is dht_dat by any chance an unsigned integer type (uint8_t), then you should cast that first so you don't need the multiplication with -1. Probably there is no sign extension this way. |
If you use the DHT22 Plugin you get values like -3276,8 for Temperatures <=0°C
The way I fixed it was taking this example: https://github.com/RobTillaart/Arduino/blob/master/libraries/DHTstable/dht.cpp
But I still got -3276.80 at 0.0 °C. For this I just found a dirty way.
Here the way I fixed the whole problem. Maybe someone with more C++ experiance can fix it cleaner....
_P005_DHT.ino:
The text was updated successfully, but these errors were encountered: