Skip to content

Commit 238d970

Browse files
committed
0.2.0 DHT20
1 parent 471b9c5 commit 238d970

File tree

9 files changed

+140
-43
lines changed

9 files changed

+140
-43
lines changed

libraries/DHT20/.arduino-ci.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
116
compile:
217
# Choosing to run compilation tests on 2 different Arduino platforms
318
platforms:
@@ -8,4 +23,6 @@ compile:
823
- m4
924
- esp32
1025
# - esp8266
11-
# - mega2560
26+
# - mega2560
27+
- rpipico
28+

libraries/DHT20/CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Change Log DHT20
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.2.0] - 2022-10-30
10+
- add changelog.md
11+
- add rp2040 to build-CI
12+
- add workaround for #8 to readme.md
13+
- fix requestFrom() ambiguity
14+
- fix #8 - embed **resetSensor()** into **read()**.
15+
This makes reads slightly slower.
16+
- update readme.md
17+
18+
----
19+
20+
## [0.1.4] - 2022-09-18
21+
- add resetSensor() code.
22+
- add comments in .h file
23+
- add examples
24+
- stabilize readStatus()
25+
- update readme.md
26+
27+
## [0.1.3] - 2022-09-17
28+
- add wrapper status functions
29+
- improve performance read()
30+
- refactor, update readme.md
31+
32+
## [0.1.2] - 2022-09-16
33+
- fix #4 DHT20_ERROR_BYTES_ALL_ZERO error condition.
34+
- fix keywords
35+
- add readStatus() fix _readStatus()
36+
- add setWireTimeout(250000, true); // in comments
37+
38+
## [0.1.1] - 2022-09-10
39+
- add hardware schema to readme.md.
40+
- fix async interface (first version)
41+
42+
## [0.1.0] - 2022-01-11
43+
- initial version (based upon DHT20 datasheet)
44+

libraries/DHT20/DHT20.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
//
22
// FILE: DHT20.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.4
4+
// VERSION: 0.2.0
55
// PURPOSE: Arduino library for DHT20 I2C temperature and humidity sensor.
66
//
7-
// HISTORY:
8-
// 0.1.0 2022-01-11 initial version (based upon DHT20 datasheet)
9-
// 0.1.1 2022-09-10 add hardware schema to readme.md.
10-
// fix async interface (first version)
11-
// 0.1.2 2022-09-16 fix #4 DHT20_ERROR_BYTES_ALL_ZERO error condition.
12-
// fix keywords
13-
// add readStatus() fix _readStatus()
14-
// add setWireTimeout(250000, true); // in comments
15-
// 0.1.3 2022-09-17 add wrapper status functions
16-
// improve performance read()
17-
// refactor, update readme.md
18-
// 0.1.4 2022-09-18 add resetSensor() code.
19-
// add comments in .h file
20-
// add examples
21-
// stabilize readStatus()
22-
// update readme.md
7+
// HISTORY: see changelog.md
238

249

2510
#include "DHT20.h"
@@ -117,13 +102,16 @@ int DHT20::read()
117102
status = readData();
118103
if (status < 0) return status;
119104

120-
// convert it to meaningfull data
105+
// convert it to meaningful data
121106
return convert();
122107
}
123108

124109

125110
int DHT20::requestData()
126111
{
112+
// reset sensor if needed.
113+
resetSensor();
114+
127115
// GET CONNECTION
128116
_wire->beginTransmission(DHT20_ADDRESS);
129117
_wire->write(0xAC);
@@ -331,7 +319,7 @@ bool DHT20::_resetRegister(uint8_t reg)
331319
if (_wire->endTransmission() != 0) return false;
332320
delay(5);
333321

334-
int bytes = _wire->requestFrom(DHT20_ADDRESS, 3);
322+
int bytes = _wire->requestFrom(DHT20_ADDRESS, (uint8_t)3);
335323
for (int i = 0; i < bytes; i++)
336324
{
337325
value[i] = _wire->read();

libraries/DHT20/DHT20.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// FILE: DHT20.h
44
// AUTHOR: Rob Tillaart
55
// PURPOSE: Arduino library for DHT20 I2C temperature and humidity sensor.
6-
// VERSION: 0.1.4
6+
// VERSION: 0.2.0
77
// HISTORY: See DHT20.cpp
88
// URL: https://github.com/RobTillaart/DHT20
99
//
@@ -21,7 +21,7 @@
2121
#include "Arduino.h"
2222
#include "Wire.h"
2323

24-
#define DHT20_LIB_VERSION (F("0.1.4"))
24+
#define DHT20_LIB_VERSION (F("0.2.0"))
2525

2626
#define DHT20_OK 0
2727
#define DHT20_ERROR_CHECKSUM -10

libraries/DHT20/README.md

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ Arduino library for I2C DHT20 temperature and humidity sensor.
1313

1414
## Description
1515

16+
The DHT20 is a humidity an temperature sensor.
17+
18+
The sensor has a fixed address of **0x38**.
19+
It is not known if the address can be changed.
20+
1621
The library must be initiated by calling the **begin()** function,
1722
or **begin(dataPin, clockPin)** for **ESP32** and similar platforms.
1823

1924
Thereafter one has to call the **read()** function to do the actual reading,
20-
and with **getTemperature()** and **getHumidity()** to get the measured values.
21-
Calling these latter again will return the same values until a new **read()** is called.
25+
and call **getTemperature()** and **getHumidity()** to get the measured values.
26+
Calling these latter again will return the same values until a new **read()** is done.
2227

2328
The **read()** call of this sensor is blocking for 80+ milliseconds (datasheet 7.4)
2429
so the library also has a asynchronous interface. See below.
@@ -27,9 +32,30 @@ Since 0.1.3 and 0.1.4 the performance of **read()** has been optimized,
2732
still blocking but less long for about 45 milliseconds.
2833

2934

35+
### 0.2.0
36+
37+
In #8 a bug is described that the sensor "freezes".
38+
Cause is not well understood.
39+
40+
Two solutions / workarounds are found:
41+
- call **resetSensor()** before EVERY **read()**.
42+
This is the preferred solution.
43+
- use **Wire.setClock(200000)** 100 K and lower speeds freezes the sensor.
44+
With clock set to 200 K and above the sensor seems to work for longer periods.
45+
Tested several speeds on UNO, no pull ups, < 10 cm wire.
46+
47+
Note: setting the I2C clock possibly interferes with other devices on the I2C bus,
48+
so it is not a solution in the end.
49+
50+
The 0.2.0 version embeds the **resetSensor()** into **requestData()** to
51+
reset the sensor if needed in both synchronous and asynchronous calls.
52+
This keeps the API simple. The reads are 1-2 ms slower than 0.1.4. (< 50 ms).
53+
Still far below the 80 ms mentioned in the datasheet.
54+
55+
3056
### Connection
3157

32-
Always check datasheet
58+
Always check datasheet!
3359

3460
Front view
3561
```
@@ -43,7 +69,7 @@ Front view
4369

4470
### Tested
4571

46-
Verified to work with Arduino UNO and ESP32.
72+
Verified to work with Arduino UNO and ESP32 and ESP8266 (see #8)
4773
Please let me know if other platforms work (or not).
4874

4975

@@ -61,29 +87,32 @@ Please let me know if other platforms work (or not).
6187
### Core
6288

6389
- **int8_t read()** read the sensor and store the values internally.
64-
It returns the status of the read which should be 0.
90+
Returns the status of the read which should be 0 == **DHT20_OK**.
6591
- **float getHumidity()** returns last Humidity read.
92+
Multiple calls will return same value until a new **read()** is made.
6693
- **float getTemperature()** returns last Temperature read.
94+
Multiple calls will return same value until a new **read()** is made.
6795

6896

6997
### Offset
7098

71-
- **void setHumOffset(float offset)** set an offset to calibrate (1st order) the sensor.
72-
- **float getHumOffset()** return current offset, default 0.
73-
- **void setTempOffset(float offset)** set an offset to calibrate (1st order) the sensor.
74-
- **float getTempOffset()** return current offset, default 0.
99+
- **void setHumOffset(float offset)** set an offset to calibrate the sensor (1st order).
100+
- **float getHumOffset()** return current humidity offset, default 0.
101+
- **void setTempOffset(float offset)** set an offset to calibrate the sensor (1st order).
102+
- **float getTempOffset()** return current temperature offset, default 0.
75103

76104

77105
### Asynchronous interface
78106

79-
There are two timings that need to be considdered,
80-
- time between requests = 1000 ms
81-
- time between request and data ready = 80 ms
107+
There are two timings that need to be considered (from datasheet):
108+
- time between requests = 1000 ms.
109+
- time between request and data ready = 80 ms.
82110

83111
The async interface allows one to continue processing after a **requestData()** has been made.
84-
Note that there should be at least **1000 milliseconds** between subsequent requests.
112+
Note there should be at least **1000 milliseconds** between subsequent requests.
85113

86114
With **bool isMeasuring()** one can check if a new measurement is ready.
115+
Alternative is to delay for up to 80 ms.
87116
If so the sensor can be read with **readData()**.
88117

89118
To interpret the read bits to temperature, humidity and status one needs to call **convert()** as last step.
@@ -116,14 +145,17 @@ This function blocks a few milliseconds to optimize communication.
116145

117146
#### Experimental 0.1.4 resetSensor
118147

119-
Use with care, as this is not tested.
148+
Use with care!
120149

121150
- **uint8_t resetSensor()** if at startup the sensor does not return a status of 0x18,
122151
three registers 0x1B, 0x1C and 0x1E need to be reset.
123152
See datasheet 7.4 Sensor Reading Process, point 1.
124153
There is no documentation about the meaning of these registers.
125154
The code is based upon example code for the AHT20 (from manufacturer).
126155

156+
The call is needed to get the **read()** working well so it has been embedded into
157+
the read calls. (0.2.0)
158+
127159

128160
### Timing
129161

@@ -152,20 +184,20 @@ See examples
152184
## Future
153185

154186
#### must
155-
187+
- improve documentation.
188+
- investigate the bug from #8 further
156189

157190
#### should
158191

159192

160193
#### could
161-
162194
- improve unit tests.
163195
- investigate
164196
- sensor calibration (website aosong?)
165197
- investigate optimizing timing in readStatus()
166198
- delay(1) ==> microSeconds(???).
167-
- separate changelog.md
168199
- connected flag?
200+
- add **uint8_t getAddress()** to return the address (convenience).
169201

170202
#### won't
171203

libraries/DHT20/examples/DHT20/DHT20.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ void setup()
2424
{
2525
DHT.begin(); // ESP32 default pins 21 22
2626

27-
Wire.setClock(400000);
28-
2927
Serial.begin(115200);
3028
Serial.println(__FILE__);
3129
Serial.print("DHT20 LIBRARY VERSION: ");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
...Arduino\libraries\DHT20\examples\DHT20\DHT20.ino
2+
DHT20 LIBRARY VERSION: 0.2.0
3+
4+
IDE 1.8.19
5+
Arduino UNO
6+
7+
Type Humidity (%) Temp (°C) Time (µs) Status
8+
DHT20 76.2 19.2 45964 OK
9+
DHT20 76.1 19.2 45960 OK
10+
DHT20 75.8 19.2 45956 OK
11+
DHT20 75.6 19.2 45952 OK
12+
DHT20 75.4 19.2 45972 OK
13+
DHT20 75.2 19.2 45976 OK
14+
DHT20 75.1 19.2 45964 OK
15+
DHT20 74.9 19.2 45960 OK
16+
DHT20 74.8 19.2 45956 OK
17+
DHT20 74.6 19.2 45960 OK
18+

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

libraries/DHT20/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DHT20
2-
version=0.1.4
2+
version=0.2.0
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for I2C DHT20 temperature and humidity sensor.

0 commit comments

Comments
 (0)