Skip to content

DHT22 negative temperatures are not handled correctly. #9

Closed
@jerryneedell

Description

@jerryneedell

The DHT22 sensor returs a 16 bit temperature with bits 0-14 containing the magnitude and the MSB indicating the sign. The driver as written incorrectly treat the value as a twos-complement signed integer and gives incorrect results below 0 C .
I put the sensor in a freezer.
the dht_simpletest converts to F so this example shows the error as the temperature crosses 32 F

Temp: 32.9 F Humidity: 23.4% 
Temp: 32.7 F Humidity: 23.5% 
Temp: 32.5 F Humidity: 23.6% 
Temp: 32.4 F Humidity: 23.7% 
Temp: 32.2 F Humidity: 23.8% 
Temp: 32.0 F Humidity: 23.8% 
Temp: 5930.4 F Humidity: 24.0% 
Temp: 5930.4 F Humidity: 24.1% 
Temp: 5930.5 F Humidity: 24.2% 
Temp: 5930.7 F Humidity: 24.3% 
Temp: 5930.9 F Humidity: 24.4% 
Temp: 5931.1 F Humidity: 24.5% 
Temp: 5931.3 F Humidity: 24.5% 
Temp: 5931.4 F Humidity: 24.7% 
Temp: 5931.6 F Humidity: 24.8% 
Temp: 5931.6 F Humidity: 25.1% 
Temp: 5931.8 F Humidity: 25.7% 
Temp: 5931.6 F Humidity: 26.3% 
Temp: 5931.6 F Humidity: 26.9% 
Temp: 5931.6 F Humidity: 27.6% 
Temp: 5931.3 F Humidity: 28.7% 
Temp: 5931.1 F Humidity: 29.2% 
Temp: 5930.9 F Humidity: 29.7% 
Temp: 5930.5 F Humidity: 30.2% 
Temp: 5930.4 F Humidity: 30.9% 
Temp: 32.0 F Humidity: 31.4% 
Temp: 32.5 F Humidity: 32.7% 
Temp: 32.9 F Humidity: 33.3%

Note - the DHT 11 appear to only measure down to 1 C - so there is no problem there.

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