winlinvip / SimpleDHT

Simple, Stable and Fast Arduino Temp & Humidity Sensors for DHT11 and DHT22. http://learn.adafruit.com/dht
MIT License
144 stars 61 forks source link

Fix negative temperatures for DHT22 #16

Closed danielfaust closed 6 years ago

danielfaust commented 6 years ago

This commit fixes issue https://github.com/winlinvip/SimpleDHT/issues/14 The MSB carries the sign information, which is filtered with & 0x8000. If the flag is present, the remainder will get multiplied by -1. All the remaining bits contain the value and are filtered with & 0x7FFF.

winlinvip commented 6 years ago

👍

winlinvip commented 6 years ago

Release 1.0.8.

winlinvip commented 6 years ago

It seems that you only fixed for DHT22, not for DHT11? Could you please fix it for DHT11 at https://github.com/winlinvip/SimpleDHT/blob/master/SimpleDHT.cpp#L112 ?

danielfaust commented 6 years ago

I don't have a DHT11 to test with. But since the DHT11 only works with temperatures equal to or above 0 °C, I think that sign flag never gets set. I preferred not to touch that code.

Good for 0-50°C temperature readings ±2°C accuracy

winlinvip commented 6 years ago

👌 Agreed, I will release a new version.