RobTillaart / DHTNew

Arduino library for DHT11 and DHT22 with automatic sensor recognition
MIT License
99 stars 15 forks source link

Problem: DHT22 sends minus 0 degree as sign-mag #54

Closed argltuc closed 3 years ago

argltuc commented 3 years ago

Problem is related to #52

Solution: Since all negative temperatures of DHT22 are send in two's complement, it is possible to detect sign-magnitude values and to catch if sensor outputs 0x8000 for a temperature lower then 0°C but higher then -0.1°C

RobTillaart commented 3 years ago

Looks good

argltuc commented 3 years ago

uh, I forgott to ingrease version numbers in library.json and library.properties. sorry...

RobTillaart commented 3 years ago

No problem, didn't notice either only after merging :)

I pushed a fix

RobTillaart commented 3 years ago

0.4.5 released

Anrijs commented 3 years ago

Instead of setting temperature to 0, it should invert sign and 0x80 should be removed from _bits[2]. This works for me:

int16_t t = ((_bits[2] & 0x7F) * 256 + _bits[3]);
if(_bits[2] == 0x80)
  _temperature = t * -0.1; 
else
  _temperature = t * 0.1;