From 029405387d62717d6e23ddb716cba802f8e4ef6f Mon Sep 17 00:00:00 2001 From: Benjamin Kormann Date: Sun, 29 Dec 2024 18:19:00 +0100 Subject: [PATCH] modified interpretation of temperature values in byte 2 and 3, such that negative temperature values are handled correctly --- DHT.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DHT.cpp b/DHT.cpp index a48ac74..1a1f3df 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -84,6 +84,7 @@ void DHT::begin(uint8_t usec) { */ float DHT::readTemperature(bool S, bool force) { float f = NAN; + short s = 0; if (read(force)) { switch (_type) { @@ -108,6 +109,12 @@ float DHT::readTemperature(bool S, bool force) { } break; case DHT22: + s = ((short) data[2]) << 8 | data[3]; + f = s * 0.1; + if (S) { + f = convertCtoF(f); + } + break; case DHT21: f = ((word)(data[2] & 0x7F)) << 8 | data[3]; f *= 0.1;