Hi,
Nice library. However, it does not work correctly for negative temperatures. I'm using version 0.1.04. When a negative temperature is measured the class will return DHTLIB_ERROR_CHECKSUM. The problem is at line 74 in dht.cpp. Here bits[2] is modified, which makes the checksum calculation incorrect. There are, of course, many ways to fix the problem. I have fixed it by changing the code in the following way.
Old Code:
int sign = 1;
if (bits[2] & 0x80) // negative temperature
{
bits[2] = bits[2] & 0x7F;
sign = -1;
}
temperature = sign * word(bits[2], bits[3]) * 0.1;
New Code:
if (bits[2] & 0x80) // negative temperature
{
temperature = word(bits[2]&0x7F, bits[3]) * 0.1;
temperature = -1.0 * temperature;
}
else
{
temperature = word(bits[2], bits[3]) * 0.1;
}
Thanks for the library, and with this fix it is just perfect for me!