From 57fe95c1be265743ca02b93cf6b1cf193d5430ea Mon Sep 17 00:00:00 2001 From: Simon IJskes Date: Fri, 8 Feb 2019 22:18:10 +0100 Subject: [PATCH 1/2] split off the DHT11 conversion, corrected the algorithm for temperatures below 0 degrees celsius. --- DHT.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/DHT.cpp b/DHT.cpp index 463a61f..037c104 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -39,6 +39,15 @@ float DHT::readTemperature(bool S, bool force) { if (read(force)) { switch (_type) { case DHT11: + f = data[2]; + if (data[3] & 0x80) { + f *= -1 -f ; + } + f += (data[3] & 0x0f) * 0.1; + if(S) { + f = convertCtoF(f); + } + break; case DHT12: f = data[2]; f += (data[3] & 0x0f) * 0.1; From 8b9624479edcfa4aa9da5ed3ce9f23fe95fb1f74 Mon Sep 17 00:00:00 2001 From: Simon IJskes Date: Mon, 11 Feb 2019 12:33:06 +0100 Subject: [PATCH 2/2] removed '*' copy error. --- DHT.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DHT.cpp b/DHT.cpp index 037c104..b97dc19 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -41,7 +41,7 @@ float DHT::readTemperature(bool S, bool force) { case DHT11: f = data[2]; if (data[3] & 0x80) { - f *= -1 -f ; + f = -1 - f ; } f += (data[3] & 0x0f) * 0.1; if(S) { @@ -164,11 +164,11 @@ bool DHT::read(bool force) { pinMode(_pin, OUTPUT); digitalWrite(_pin, LOW); switch(_type) { - case DHT22: - case DHT21: + case DHT22: + case DHT21: delayMicroseconds(1100); // data sheet says "at least 1ms" break; - case DHT11: + case DHT11: default: delay(20); //data sheet says at least 18ms, 20ms just to be safe break;