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
The current release 1.4.6 of DHT-sensor-library supports various DHTxx sensors. I tested several DHT22 sensors on ESP8266 and Arduino Uno experiencing correct behavior for humidity and positive temperature values. As soon as the temperature drops below zero, incorrect negative values are determined by float DHT::readTemperature(bool S, bool force) function in DHT.cpp.
The data sheet of (DHT22) explains the temperature data extraction on page 3. The MCU receives 40 bits (5 * 8 bits) with the following structure:
1st 16 bits: RH data (relative humidity)
2nd 16 bits: T data (temperature)
last 8 bits: check sum
The current implementation follows the description of the data sheet, but returns incorrect data. A detailed inspection revealed, that temperature data is returned as a 16 bit signed integer value, hence no distinction between negative or positive values is needed. The float DHT::readTemperature(bool S, bool force) function in DHT.cpp must be adapted to:
float DHT::readTemperature(bool S, bool force) {
float f = NAN;
short s = 0;
...
case DHT22:
s = ((short) data[2]) << 8 | data[3];
f = s * 0.1;
if (S) {
f = convertCtoF(f);
}
break;
...
The above mentioned patch solves the previous issue of incorrect negative temperature values. It seems like an inconsistency between documentation (data sheet) and sensor implementation or it might be a sensor variant to be supported by the DHT-sensor-library.
The text was updated successfully, but these errors were encountered:
The current release 1.4.6 of DHT-sensor-library supports various DHTxx sensors. I tested several DHT22 sensors on ESP8266 and Arduino Uno experiencing correct behavior for humidity and positive temperature values. As soon as the temperature drops below zero, incorrect negative values are determined by
float DHT::readTemperature(bool S, bool force)
function inDHT.cpp
.The data sheet of (DHT22) explains the temperature data extraction on page 3. The MCU receives 40 bits (5 * 8 bits) with the following structure:
The current implementation follows the description of the data sheet, but returns incorrect data. A detailed inspection revealed, that temperature data is returned as a 16 bit signed integer value, hence no distinction between negative or positive values is needed. The
float DHT::readTemperature(bool S, bool force)
function inDHT.cpp
must be adapted to:The above mentioned patch solves the previous issue of incorrect negative temperature values. It seems like an inconsistency between documentation (data sheet) and sensor implementation or it might be a sensor variant to be supported by the DHT-sensor-library.
The text was updated successfully, but these errors were encountered: