Skip to content

Problem: wrong values at negative temperatures an ESP8266 and DHT22 #177

@argltuc

Description

@argltuc
  • Arduino board: ESP8266 / NodeMCU 1.0 (ESP12-E Module)
  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.13
  • installed DHT-sensor-library version: 1.4.1 / installed by Arduino IDE Lib manager

I use the DHT22 in combination with an ESP8266 and this lib.
When having negative temperatures, the resulting value of readTemperature() is -3278.6 at -0.1°C
To fix negatives values a recalculation is nessecary:

#include <stdint.h>
float temperature = dht.readTemperature();
if(temperature < 0)
 {
   temperature = (temperature = (INT16_MAX - temperature*-10)*-0.1; - temperature*-10)*-0.1;
 }

after some research, i figure out, that the values in data-array repressents an intager in ones complement, while the rest of data handling seems to be in BCD.
I will provide an PR to fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions