Skip to content

Commit dee30a3

Browse files
committed
Fix issue #111 - DHT12 negative temperature
1 parent 768fd8c commit dee30a3

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

libraries/DHT12/DHT12.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//
22
// FILE: DHT12.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.1
4+
// VERSION: 0.1.2
55
// PURPOSE: I2C library for DHT12 for Arduino.
66
//
77
// HISTORY:
88
// 0.1.0: 2017-12-11 initial version
99
// 0.1.1: 2017-12-19 added ESP8266 - issue #86
1010
// Verified by Viktor Balint
11+
// 0.1.2: 2018-09-02 fix negative temperature DHT12 - issue #111
12+
//
1113
//
1214
// Released to the public domain
1315
//
@@ -42,8 +44,8 @@ int8_t DHT12::read()
4244

4345
// CONVERT AND STORE
4446
humidity = bits[0] + bits[1] * 0.1;
45-
temperature = (bits[2] & 0x7F) + bits[3] * 0.1;
46-
if (bits[2] & 0x80)
47+
temperature = bits[2] + (bits[3] & 0x7F) * 0.1;
48+
if (bits[3] & 0x80)
4749
{
4850
temperature = -temperature;
4951
}

libraries/DHT12/DHT12.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// FILE: DHT12.h
55
// AUTHOR: Rob Tillaart
66
// PURPOSE: DHT_I2C library for Arduino .
7-
// VERSION: 0.1.1
7+
// VERSION: 0.1.2
88
// HISTORY: See DHT12.cpp
99
// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/
1010
//
@@ -14,7 +14,7 @@
1414
#include "Wire.h"
1515
#include "Arduino.h"
1616

17-
#define DHT12_VERSION "0.1.1"
17+
#define DHT12_VERSION "0.1.2"
1818

1919
#define DHT12_OK 0
2020
#define DHT12_ERROR_CHECKSUM -10

libraries/DHT12/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/Arduino.git"
1717
},
18-
"version":"0.1.1",
18+
"version":"0.1.2",
1919
"frameworks": "arduino",
2020
"platforms": "*",
2121
"export": {

libraries/DHT12/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DHT12
2-
version=0.1.1
2+
version=0.1.2
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=I2C Library for DHT12 Temperature and Humidity.

libraries/DHTlib/dht.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//
22
// FILE: dht.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.28
4+
// VERSION: 0.1.29
55
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
66
// URL: http://arduino.cc/playground/Main/DHTLib
77
//
88
// HISTORY:
9+
// 0.1.29 2018-09-02 fix negative temperature DHT12 - issue #111
910
// 0.1.28 2018-04-03 refactor
1011
// 0.1.27 2018-03-26 added _disableIRQ flag
1112
// 0.1.26 2017-12-12 explicit support for AM23XX series and DHT12
@@ -85,8 +86,8 @@ int8_t dht::read12(uint8_t pin)
8586

8687
// CONVERT AND STORE
8788
humidity = bits[0] + bits[1] * 0.1;
88-
temperature = (bits[2] & 0x7F) + bits[3] * 0.1;
89-
if (bits[2] & 0x80) // negative temperature
89+
temperature = bits[2] + (bits[3] & 0x7F) * 0.1;
90+
if (bits[3] & 0x80) // negative temperature
9091
{
9192
temperature = -temperature;
9293
}

libraries/DHTlib/dht.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: dht.h
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.28
4+
// VERSION: 0.1.29
55
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
66
// URL: http://arduino.cc/playground/Main/DHTLib
77
//
@@ -19,7 +19,7 @@
1919
#include <Arduino.h>
2020
#endif
2121

22-
#define DHT_LIB_VERSION "0.1.28"
22+
#define DHT_LIB_VERSION "0.1.29"
2323

2424
#define DHTLIB_OK 0
2525
#define DHTLIB_ERROR_CHECKSUM -1

libraries/DHTlib/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/Arduino.git"
1717
},
18-
"version":"0.1.28",
18+
"version":"0.1.29",
1919
"frameworks": "arduino",
2020
"platforms": "*",
2121
"export": {

libraries/DHTlib/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DHTlib
2-
version=0.1.28
2+
version=0.1.29
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Optimized Library for DHT Temperature & Humidity Sensor on AVR only.

0 commit comments

Comments
 (0)