adafruit / DHT-sensor-library

Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors
https://learn.adafruit.com/dht
MIT License
1.94k stars 1.43k forks source link

Problem: wrong values at negative temperatures an ESP8266 and DHT22 #177

Open argltuc opened 3 years ago

argltuc commented 3 years ago

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 <stdint.h>
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.

Maaajaaa commented 2 years ago

I tried to repeat the bug with an ESP32 but all negative celsius temperatures that I got (though I did not get -0.1 in particular) seemed correct to me. Does this only concern -0.1C in partocular?

argltuc commented 2 years ago

If i remember correctly all negative values were wrong. Less temperature results in respective higher value then -3278.6. Currently i can't repeat my measurements, since all my DHT22 sensor are used and fully integrated in some projects.

tranquil-c commented 1 year ago

I have been seeing this issue and have yet to narrow down on the cause.

I'm using version 1.4.4 of this library and building with PlatformIO:

I've observed it twice now. On both occasions the temperature decreased, crossing 0 degrees, over the course of roughly an hour.

I'll be investigating the issue and will provide an update should I find anything notable.

naymore commented 7 months ago

I know this thread is quite a bit old but I couldn't find any real solution to the problem. I'm using v1.4.6 of this library (on an ESP8266) and I can confirm the problem is real.