Skip to content

Commit

Permalink
0.1.32 fix negative temp (again) (#5)
Browse files Browse the repository at this point in the history
* 0.1.32 fix negative temp (again)
  • Loading branch information
RobTillaart authored Feb 2, 2021
1 parent e75b40c commit b2164c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
12 changes: 5 additions & 7 deletions dht.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//
// FILE: dht.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.31
// VERSION: 0.1.32
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino, AVR optimized
// URL: https://github.com/RobTillaart/DHTlib
// http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// 0.1.32 2021-02-01 fix negative temperature DHT22 again (code from DHTNew)
// 0.1.31 2020-12-15 fix negative temperature DHT22 (code from DHTNew)
// 0.1.30 2020-06-30 own repo;
// 0.1.29 2018-09-02 fix negative temperature DHT12 - issue #111
Expand Down Expand Up @@ -113,12 +114,9 @@ int8_t dht::read(uint8_t pin)
bits[2] &= 0x83;

// CONVERT AND STORE
humidity = (bits[0] * 256 + bits[1]) * 0.1;
temperature = ((bits[2] & 0x7F) * 256 + bits[3]) * 0.1;
if (bits[2] & 0x80) // negative temperature
{
temperature = -temperature;
}
humidity = (bits[0] * 256 + bits[1]) * 0.1;
int16_t t = (bits[2] * 256 + bits[3]);
temperature = t * 0.1;

// HEXDUMP DEBUG
/*
Expand Down
27 changes: 15 additions & 12 deletions dht.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: dht.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.31
// VERSION: 0.1.32
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino. AVR optimized
// URL: https://github.com/RobTillaart/DHTlib
// http://arduino.cc/playground/Main/DHTLib
Expand All @@ -20,20 +20,22 @@
#include <Arduino.h>
#endif

#define DHT_LIB_VERSION "0.1.31"

#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT -2
#define DHTLIB_ERROR_CONNECT -3
#define DHTLIB_ERROR_ACK_L -4
#define DHTLIB_ERROR_ACK_H -5
#define DHT_LIB_VERSION (F("0.1.32"))

#define DHTLIB_DHT11_WAKEUP 18
#define DHTLIB_DHT_WAKEUP 1
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
#define DHTLIB_ERROR_TIMEOUT -2
#define DHTLIB_ERROR_CONNECT -3
#define DHTLIB_ERROR_ACK_L -4
#define DHTLIB_ERROR_ACK_H -5

#define DHTLIB_DHT11_WAKEUP 18
#define DHTLIB_DHT_WAKEUP 1

#define DHTLIB_DHT11_LEADING_ZEROS 1
#define DHTLIB_DHT_LEADING_ZEROS 6

#define DHTLIB_DHT11_LEADING_ZEROS 1
#define DHTLIB_DHT_LEADING_ZEROS 6

// max timeout is 100 usec.
// For a 16 Mhz proc 100 usec is 1600 clock cycles
Expand All @@ -46,6 +48,7 @@
#define DHTLIB_TIMEOUT (F_CPU/40000)
#endif


class dht
{
public:
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/DHTlib.git"
},
"version":"0.1.31",
"version":"0.1.32",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=DHTlib
version=0.1.31
version=0.1.32
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=AVR Optimized Library for DHT Temperature & Humidity Sensor on AVR only.
Expand Down

0 comments on commit b2164c3

Please sign in to comment.