-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
DHT12 - Evaluating negative temperatures #165
Comments
I've the same problem with the DHT22. In my case, the temperature data from the DHT22 is 2's complement. The current code thinks the data is signed binary and returns incorrect values for negative temperatures (e.g.-3257.9 for -18.9). The following code fixes the problem. It combines the temperature data in data[2] and data[3] into a signed 16 bit integer (int16_t) which is then converted to a float when multiplied by 0.1. I don't know if this applies to DHT11 and 12 also. case DHT22: I'll let someone else update the code in GITHUB |
Arduino board: Not relevant (based on visual inspection of code)
Arduino IDE version (found in Arduino -> About Arduino menu): Also not relevant (based on visual inspection of code
List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too):
In file: DHT.cpp,
In function: float DHT::readTemperature(bool S, bool force)
While handling the DHT12 (extracting the float value from the 5-byte data received from the device
Code lines 100-105 are:
case DHT12:
f = data[2];
f += (data[3] & 0x0f) * 0.1;
if (data[2] & 0x80) {
f *= -1;
}
Bit 7 of data[2] is included in the float value, AND is used as a sign bit.
Surely this can't be right.
E.g. if data[2] = 0x80 and data[3]=0x00
then this will return a temperature of -128.0 degreesC
The text was updated successfully, but these errors were encountered: