Skip to content

Commit 1107c65

Browse files
committed
0.3.1 DHT12
1 parent 8eea2d1 commit 1107c65

File tree

12 files changed

+113
-68
lines changed

12 files changed

+113
-68
lines changed

libraries/DHT12/.arduino-ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ compile:
22
# Choosing to run compilation tests on 2 different Arduino platforms
33
platforms:
44
- uno
5-
- leonardo
6-
- due
7-
- zero
5+
# - due
6+
# - zero
7+
# - leonardo
8+
- m4
9+
- esp32
10+
# - esp8266
11+
# - mega2560

libraries/DHT12/.github/workflows/arduino_test_runner.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ name: Arduino CI
44
on: [push, pull_request]
55

66
jobs:
7-
arduino_ci:
7+
runTest:
88
runs-on: ubuntu-latest
99

1010
steps:
1111
- uses: actions/checkout@v2
12-
- uses: Arduino-CI/action@master
13-
# Arduino-CI/[email protected]
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb

libraries/DHT12/DHT12.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
// PURPOSE: I2C library for DHT12 for Arduino.
66
//
77
// HISTORY:
8-
// 0.1.0: 2017-12-11 initial version
9-
// 0.1.1: 2017-12-19 added ESP8266 - issue #86
8+
// 0.1.0 2017-12-11 initial version
9+
// 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-
// 0.2.0 2020-04-11 explicit constructors, select other Wire interface, #pragma once
13-
// 0.2.1 2020-06-07 fix library.json
14-
// 0.3.0 2020-12-19 add arduino-CI + unit test
11+
// 0.1.2 2018-09-02 fix negative temperature DHT12 - issue #111
12+
// 0.2.0 2020-04-11 explicit constructors, select other Wire interface,
13+
// #pragma once
14+
// 0.2.1 2020-06-07 fix library.json
15+
// 0.3.0 2020-12-19 add Arduino-CI + unit test
1516
// temperature and humidity made private
16-
//
17+
// 0.3.1 2021-10-25 add lastRead, update Arduino-CI, badges
1718

1819

1920
#include "DHT12.h"
@@ -68,6 +69,8 @@ int8_t DHT12::read()
6869
uint8_t checksum = _bits[0] + _bits[1] + _bits[2] + _bits[3];
6970
if (_bits[4] != checksum) return DHT12_ERROR_CHECKSUM;
7071

72+
_lastRead = millis();
73+
7174
return DHT12_OK;
7275
}
7376

@@ -95,4 +98,5 @@ int DHT12::_readSensor()
9598
return bytes;
9699
}
97100

101+
98102
// -- END OF FILE --

libraries/DHT12/DHT12.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
// FILE: DHT12.h
44
// AUTHOR: Rob Tillaart
55
// PURPOSE: DHT_I2C library for Arduino .
6-
// VERSION: 0.3.0
6+
// VERSION: 0.3.1
77
// HISTORY: See DHT12.cpp
88
// URL: https://github.com/RobTillaart/DHT12
99
//
1010

11+
1112
#include "Arduino.h"
1213
#include "Wire.h"
1314

14-
#define DHT12_LIB_VERSION "0.3.0"
15+
#define DHT12_LIB_VERSION "0.3.1"
1516

1617
#define DHT12_OK 0
1718
#define DHT12_ERROR_CHECKSUM -10
1819
#define DHT12_ERROR_CONNECT -11
1920
#define DHT12_MISSING_BYTES -12
2021

22+
2123
class DHT12
2224
{
2325
public:
@@ -37,16 +39,19 @@ class DHT12
3739
void setTempOffset(float offset) { _tempOffset = offset; };
3840
float getHumOffset() { return _humOffset; };
3941
float getTempOffset() { return _tempOffset; };
42+
uint32_t lastRead() { return _lastRead; };
4043

4144
private:
4245
float _humidity;
4346
float _temperature;
4447
float _humOffset;
4548
float _tempOffset;
4649
uint8_t _bits[5];
50+
uint32_t _lastRead;
4751

4852
int _readSensor();
4953
TwoWire* _wire;
5054
};
5155

56+
5257
// -- END OF FILE --

libraries/DHT12/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

22
[![Arduino CI](https://github.com/RobTillaart/DHT12/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/DHT12/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DHT12/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/DHT12/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DHT12/actions/workflows/jsoncheck.yml)
35
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DHT12/blob/master/LICENSE)
46
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DHT12.svg?maxAge=3600)](https://github.com/RobTillaart/DHT12/releases)
57

@@ -8,38 +10,46 @@
810

911
Arduino library for I2C DHT12 temperature and humidity sensor.
1012

13+
1114
## Description
1215

1316
The library should be initiated by calling the **begin()** function,
14-
optionally **begin(datapin, clockpin)** for **ESP32** and similar platforms.
17+
optionally **begin(dataPin, clockPin)** for **ESP32** and similar platforms.
1518

1619
Thereafter one has to call the **read()** function to do the actual reading,
1720
and with **getTemperature()** and **getHumidity()** to get the read values.
1821
Calling these latter again will return the same values until a new **read()** is called.
1922

23+
2024
## Interface
2125

26+
2227
### Constructor
2328
- **DHT12(TwoWire \*wire)** constructor, using a specific Wire (I2C bus).
24-
- **begin(dataPin, clockPin)** begin for ESP32 et al, to set I2C bus pins
29+
- **begin(uint8_t dataPin, uint8_t clockPin)** begin for ESP32 et al, to set I2C bus pins
2530
- **begin()** initializer for non ESP32.
2631

32+
2733
### Core
28-
- **read()** read the sensor and store the values intenally. It returns the status of the read which should be 0.
29-
- **getHumidity()** returns last Humidity read, or -999 in case of error.
30-
- **getTemperature()** returns last Temperature read, or -999 in case of error.
34+
- **int8_t read()** read the sensor and store the values internally. It returns the status of the read which should be 0.
35+
- **float getHumidity()** returns last Humidity read, or -999 in case of error.
36+
- **float getTemperature()** returns last Temperature read, or -999 in case of error.
37+
- **uint32_t lastRead()** returns the timestamp in milliseconds since startup of the last successful read. (added in 0.3.1)
38+
3139

3240
### Offset
3341
- **void setHumOffset(float offset)** set an offset to calibrate (1st order) the sensor.
3442
- **float getHumOffset()** return current offset, default 0.
3543
- **void setTempOffset(float offset)** set an offset to calibrate (1st order) the sensor
3644
- **float getTempOffset()** return current offset, default 0.
37-
45+
46+
3847
### version 0.3.0
3948

4049
- The members **temperature** and **humidity** became private in 0.3.0.
4150
- added offset for temperature and humidity.
4251

52+
4353
## Operation
4454

4555
See examples
Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
//
22
// FILE: DHT12.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.0
4+
// VERSION: 0.3.1
55
// PURPOSE: Demo for DHT12 I2C humidity & temperature sensor
66
//
7-
// HISTORY:
8-
// 0.1.0 2017-12-11 initial version
9-
// 0.1.1 2020-04-11 minor changes
10-
// 0.3.0 2020-12-19 compatible new version
7+
// HISTORY:
8+
// 0.1.0 2017-12-11 initial version
9+
// 0.1.1 2020-04-11 minor changes
10+
// 0.3.0 2020-12-19 compatible new version
11+
// 0.3.1 2021-10-25 add lastRead
12+
1113

1214
#include "DHT12.h"
1315

1416
DHT12 DHT(&Wire);
1517

18+
1619
void setup()
1720
{
1821
DHT.begin();
@@ -28,35 +31,38 @@ void setup()
2831
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
2932
}
3033

34+
3135
void loop()
3236
{
33-
// READ DATA
34-
Serial.print("DHT12, \t");
35-
int status = DHT.read();
36-
switch (status)
37+
if (millis() - DHT.lastRead() >= 2000)
3738
{
38-
case DHT12_OK:
39-
Serial.print("OK,\t");
40-
break;
41-
case DHT12_ERROR_CHECKSUM:
42-
Serial.print("Checksum error,\t");
43-
break;
44-
case DHT12_ERROR_CONNECT:
45-
Serial.print("Connect error,\t");
46-
break;
47-
case DHT12_MISSING_BYTES:
48-
Serial.print("Missing bytes,\t");
49-
break;
50-
default:
51-
Serial.print("Unknown error,\t");
52-
break;
39+
// READ DATA
40+
Serial.print("DHT12, \t");
41+
int status = DHT.read();
42+
switch (status)
43+
{
44+
case DHT12_OK:
45+
Serial.print("OK,\t");
46+
break;
47+
case DHT12_ERROR_CHECKSUM:
48+
Serial.print("Checksum error,\t");
49+
break;
50+
case DHT12_ERROR_CONNECT:
51+
Serial.print("Connect error,\t");
52+
break;
53+
case DHT12_MISSING_BYTES:
54+
Serial.print("Missing bytes,\t");
55+
break;
56+
default:
57+
Serial.print("Unknown error,\t");
58+
break;
59+
}
60+
// DISPLAY DATA, sensor has only one decimal.
61+
Serial.print(DHT.getHumidity(), 1);
62+
Serial.print(",\t");
63+
Serial.println(DHT.getTemperature(), 1);
5364
}
54-
// DISPLAY DATA, sensor has only one decimal.
55-
Serial.print(DHT.getHumidity(), 1);
56-
Serial.print(",\t");
57-
Serial.println(DHT.getTemperature(), 1);
58-
59-
delay(2000);
6065
}
6166

62-
// -- END OF FILE --
67+
68+
// -- END OF FILE --
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
//
22
// FILE: DHT12 _plotter.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.0
4+
// VERSION: 0.3.1
55
// PURPOSE: Demo for DHT12 I2C humidity & temperature sensor
66
//
7-
// HISTORY:
8-
// 0.1.0 2020-04-11 initial version
9-
// 0.3.0 2020-12-19 compatible new version
7+
// HISTORY:
8+
// 0.1.0 2020-04-11 initial version
9+
// 0.3.0 2020-12-19 compatible new version
10+
// 0.3.1 2021-10-25 add lastRead
11+
1012

1113
#include "DHT12.h"
1214

1315
DHT12 DHT(&Wire);
1416

17+
1518
void setup()
1619
{
1720
DHT.begin();
1821
Serial.begin(115200);
1922
Serial.println("Humidity, Temperature");
2023
}
2124

25+
2226
void loop()
2327
{
24-
// note no error checking
25-
DHT.read();
26-
Serial.print(DHT.getHumidity(), 1);
27-
Serial.print(", ");
28-
Serial.println(DHT.getTemperature(), 1);
29-
delay(1000);
28+
if (millis() - DHT.lastRead() >= 1000)
29+
{
30+
// note no error checking
31+
DHT.read();
32+
Serial.print(DHT.getHumidity(), 1);
33+
Serial.print(", ");
34+
Serial.println(DHT.getTemperature(), 1);
35+
}
3036
}
3137

3238
// -- END OF FILE --

libraries/DHT12/examples/DHT12_test_esp/DHT12_test_esp.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//
22
// FILE: DHT12_test_esp.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.0
4+
// VERSION: 0.3.1
55
// PURPOSE: Demo for DHT12 I2C humidity & temperature sensor
66
//
7-
// HISTORY:
8-
// 0.1.0 2020-04-11 initial version
9-
// 0.3.0 2020-12-19 compatible new version
7+
// HISTORY:
8+
// 0.1.0 2020-04-11 initial version
9+
// 0.3.0 2020-12-19 compatible new version
10+
// 0.3.1 2021-10-25 add lastRead
1011

1112

1213
#include "DHT12.h"
@@ -34,6 +35,7 @@ void setup()
3435
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
3536
}
3637

38+
3739
void loop()
3840
{
3941
// READ DATA

libraries/DHT12/keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ setHumOffset KEYWORD2
1212
setTempOffset KEYWORD2
1313
getHumOffset KEYWORD2
1414
getTempOffset KEYWORD2
15+
lastRead KEYWORD2
16+
1517

1618
# Constants (LITERAL1)
1719
DHT12_VERSION LITERAL2

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/DHT12.git"
1717
},
18-
"version": "0.3.0",
18+
"version": "0.3.1",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*"

0 commit comments

Comments
 (0)