Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #100, negative representation #101

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.5.0] - 2024-11-22
- fix #100, different negative algorithm support
- time to bump version

----

## [0.4.21] - 2024-10-09
- add dhtnew_pulse_diag_ext.ino for extended diagnosis.

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ Feedback (both positive and negative) about the AM232X sensors is welcome.
**Note: check the datasheet how to connect!**


### 0.5.0 Negative temperature

Apparently there are DHT22's which use another representation for negative temperatures.
Since 0.5.0 the library automatically detects which representation is used by the sensor
and chooses the correct algorithm to decode the negative temperature.

See issue #100 (solution) and #57 and #52 before.
See also https://arduino.stackexchange.com/questions/86448/dht22-sensor-reading-code-interprets-negative-values-weirdly


### Related

- https://github.com/RobTillaart/DHTNew
- https://github.com/RobTillaart/DHTStable
- https://github.com/RobTillaart/DHT_Simulator
- https://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html (interesting)
- https://github.com/RobTillaart/Temperature (conversions, dewPoint, heatindex etc)
- https://github.com/RobTillaart/Temperature (conversions, dewPoint, heat index etc.)


## DHT PIN layout from left to right
Expand Down
28 changes: 20 additions & 8 deletions dhtnew.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: dhtnew.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.4.21
// VERSION: 0.5.0
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: https://github.com/RobTillaart/DHTNEW
//
Expand Down Expand Up @@ -193,17 +193,29 @@ int DHTNEW::_read()
else // DHT22, DHT33, DHT44, compatible + Si7021
{
_humidity = (_bits[0] * 256 + _bits[1]) * 0.1;
int16_t t = ((_bits[2] & 0x7F) * 256 + _bits[3]);
if (t == 0)

// positive temperature?
if ((_bits[2] & 0x80) != 0x80 )
{
_temperature = 0.0; // prevent -0.0;
int16_t t = ((_bits[2] & 0x7F) * 256 + _bits[3]);
if (t == 0)
{
_temperature = 0.0; // prevent -0.0;
}
_temperature = t * 0.1;
}
else
else // negative temperature
{
_temperature = t * 0.1;
if((_bits[2] & 0x80) == 0x80 )
// See issue #100 - 2 different representations
if ((_bits[2] & 0x40) != 0x40 )
{
int16_t t = ((_bits[2] & 0x7F) * 256 + _bits[3]);
_temperature = t * -0.1;
}
else
{
_temperature = -_temperature;
int16_t t = (_bits[2] << 8) + _bits[3]; // 16 bits, as raw int
_temperature = t * 0.1;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dhtnew.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: dhtnew.h
// AUTHOR: Rob Tillaart
// VERSION: 0.4.21
// VERSION: 0.5.0
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: https://github.com/RobTillaart/DHTNEW
//
Expand All @@ -18,7 +18,7 @@
#include "Arduino.h"


#define DHTNEW_LIB_VERSION (F("0.4.21"))
#define DHTNEW_LIB_VERSION (F("0.5.0"))


#define DHTLIB_OK 0
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/DHTNEW.git"
},
"version": "0.4.21",
"version": "0.5.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=DHTNEW
version=0.4.21
version=0.5.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for DHT temperature and humidity sensor, with automatic sensortype recognition.
Expand Down
Loading