Skip to content

Commit 5e1c7a2

Browse files
committed
0.4.20 DHTNEW
1 parent 38a0039 commit 5e1c7a2

File tree

27 files changed

+376
-311
lines changed

27 files changed

+376
-311
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# These are supported funding model platforms
22

3-
github: RobTillaart
3+
GitHub: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
45

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
21
name: Arduino-lint
32

43
on: [push, pull_request]
54
jobs:
65
lint:
76
runs-on: ubuntu-latest
7+
timeout-minutes: 5
88
steps:
9-
- uses: actions/checkout@v3
9+
- uses: actions/checkout@v4
1010
- uses: arduino/arduino-lint-action@v1
1111
with:
1212
library-manager: update
13-
compliance: strict
13+
compliance: strict

libraries/DHTNEW/.github/workflows/arduino_test_runner.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ on: [push, pull_request]
66
jobs:
77
runTest:
88
runs-on: ubuntu-latest
9+
timeout-minutes: 20
910

1011
steps:
11-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1213
- uses: ruby/setup-ruby@v1
1314
with:
1415
ruby-version: 2.6
1516
- run: |
17+
sudo sysctl vm.mmap_rnd_bits=28
1618
gem install arduino_ci
1719
arduino_ci.rb

libraries/DHTNEW/.github/workflows/jsoncheck.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 5
1213
steps:
13-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1415
- name: json-syntax-check
15-
uses: limitusus/json-syntax-check@v1
16+
uses: limitusus/json-syntax-check@v2
1617
with:
17-
pattern: "\\.json$"
18-
18+
pattern: "\\.json$"

libraries/DHTNEW/CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9-
## [0.4.19] - 2023-10-25
9+
## [0.4.20] - 2024-03-24
10+
- fix #95, units of T & H
11+
- update GitHub actions
12+
- refactor **setType()** map invalid types to 0
1013
- update readme.md
14+
- update unit test (minor)
15+
- minor edits
16+
1117

18+
## [0.4.19] - 2023-10-25
19+
- update readme.md
1220

1321
## [0.4.18] - 2023-01-09
1422
- update license to 2023

libraries/DHTNEW/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017-2023 Rob Tillaart
3+
Copyright (c) 2017-2024 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/DHTNEW/dhtnew.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: dhtnew.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.4.19
4+
// VERSION: 0.4.20
55
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
66
// URL: https://github.com/RobTillaart/DHTNEW
77
//
@@ -47,10 +47,10 @@ void DHTNEW::reset()
4747

4848
_wakeupDelay = 0;
4949
_type = 0;
50-
_humOffset = (float)0.0;
51-
_tempOffset = (float)0.0;
52-
_humidity = (float)0.0;
53-
_temperature = (float)0.0;
50+
_humOffset = 0.0;
51+
_tempOffset = 0.0;
52+
_humidity = 0.0;
53+
_temperature = 0.0;
5454
_lastRead = 0;
5555
_disableIRQ = true;
5656
_waitForRead = false;
@@ -74,18 +74,22 @@ uint8_t DHTNEW::getType()
7474

7575
void DHTNEW::setType(uint8_t type)
7676
{
77-
if ((type == 0) || (type == 11))
77+
// default type == 0 or unsupported
78+
_type = 0;
79+
_wakeupDelay = DHTLIB_DHT11_WAKEUP;
80+
81+
if ((type == 22) || (type == 23))
7882
{
7983
_type = type;
80-
_wakeupDelay = DHTLIB_DHT11_WAKEUP;
84+
_wakeupDelay = DHTLIB_DHT_WAKEUP;
8185
}
82-
if ((type == 22) || (type == 23))
86+
else if (type == 11)
8387
{
8488
_type = type;
85-
_wakeupDelay = DHTLIB_DHT_WAKEUP;
89+
_wakeupDelay = DHTLIB_DHT11_WAKEUP;
8690
}
8791
// experimental 0.4.14
88-
if (type == 70)
92+
else if (type == 70)
8993
{
9094
_type = type;
9195
_wakeupDelay = DHTLIB_SI7021_WAKEUP;
@@ -192,7 +196,7 @@ int DHTNEW::_read()
192196
int16_t t = ((_bits[2] & 0x7F) * 256 + _bits[3]);
193197
if (t == 0)
194198
{
195-
_temperature = (float)0.0; // prevent -0.0;
199+
_temperature = 0.0; // prevent -0.0;
196200
}
197201
else
198202
{
@@ -205,22 +209,22 @@ int DHTNEW::_read()
205209
}
206210

207211

208-
// HEXDUMP DEBUG
212+
// HEXDUMP DEBUG
209213
/*
210214
Serial.println();
211-
// CHECKSUM
215+
// CHECKSUM
212216
if (_bits[4] < 0x10) Serial.print(0);
213217
Serial.print(_bits[4], HEX);
214218
Serial.print(" ");
215-
// TEMPERATURE
219+
// TEMPERATURE
216220
if (_bits[2] < 0x10) Serial.print(0);
217221
Serial.print(_bits[2], HEX);
218222
if (_bits[3] < 0x10) Serial.print(0);
219223
Serial.print(_bits[3], HEX);
220224
Serial.print(" ");
221225
Serial.print(_temperature, 1);
222226
Serial.print(" ");
223-
// HUMIDITY
227+
// HUMIDITY
224228
if (_bits[0] < 0x10) Serial.print(0);
225229
Serial.print(_bits[0], HEX);
226230
if (_bits[1] < 0x10) Serial.print(0);
@@ -241,13 +245,13 @@ int DHTNEW::_read()
241245
}
242246
#endif
243247

244-
if (_humOffset != (float)0.0)
248+
if (_humOffset != 0.0)
245249
{
246250
_humidity += _humOffset;
247-
if (_humidity < 0) _humidity = 0;
248-
if (_humidity > 100) _humidity = 100;
251+
if (_humidity > 100) _humidity = 100;
252+
else if (_humidity < 0) _humidity = 0;
249253
}
250-
if (_tempOffset != (float)0.0)
254+
if (_tempOffset != 0.0)
251255
{
252256
_temperature += _tempOffset;
253257
}
@@ -266,7 +270,7 @@ int DHTNEW::_read()
266270
void DHTNEW::powerUp()
267271
{
268272
digitalWrite(_dataPin, HIGH);
269-
// do a dummy read to sync the sensor
273+
// do a dummy read to synchronise the sensor
270274
read();
271275
};
272276

@@ -298,7 +302,10 @@ int DHTNEW::_readSensor()
298302
uint8_t idx = 0;
299303

300304
// EMPTY BUFFER
301-
for (uint8_t i = 0; i < 5; i++) _bits[i] = 0;
305+
for (uint8_t i = 0; i < 5; i++)
306+
{
307+
_bits[i] = 0;
308+
}
302309

303310
// REQUEST SAMPLE - SEND WAKEUP TO SENSOR
304311
pinMode(_dataPin, OUTPUT);
@@ -412,7 +419,7 @@ bool DHTNEW::_waitFor(uint8_t state, uint32_t timeout)
412419
uint8_t count = 2;
413420
while ((micros() - start) < timeout)
414421
{
415-
// d elayMicroseconds(1); // less # reads ==> minimizes # glitch reads
422+
// delayMicroseconds(1); // less # reads ==> minimizes # glitch reads
416423
if (digitalRead(_dataPin) == state)
417424
{
418425
count--;

libraries/DHTNEW/dhtnew.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: dhtnew.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.4.19
5+
// VERSION: 0.4.20
66
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
77
// URL: https://github.com/RobTillaart/DHTNEW
88
//
@@ -18,7 +18,7 @@
1818
#include "Arduino.h"
1919

2020

21-
#define DHTNEW_LIB_VERSION (F("0.4.19"))
21+
#define DHTNEW_LIB_VERSION (F("0.4.20"))
2222

2323

2424
#define DHTLIB_OK 0
@@ -59,12 +59,13 @@ class DHTNEW
5959
DHTNEW(uint8_t pin);
6060

6161
// resets all internals to construction time
62-
// might help to reset a sensor behaving badly..
62+
// might help to reset a sensor behaving badly
6363
void reset();
6464

6565
// 0 = unknown
6666
// 11 = DHT11 and compatibles
6767
// 22 = DHT22 and compatibles
68+
// 23 = mapped to 22 for now (AM23xx)
6869
// 70 = Sonoff Si7021
6970
uint8_t getType();
7071
void setType(uint8_t type = 0);
@@ -108,10 +109,10 @@ class DHTNEW
108109
uint8_t _dataPin = 0;
109110
uint32_t _wakeupDelay = 0;
110111
uint8_t _type = 0;
111-
float _humOffset = (float)0.0;
112-
float _tempOffset = (float)0.0;
113-
float _humidity = (float)0.0;
114-
float _temperature = (float)0.0;
112+
float _humOffset = 0.0;
113+
float _tempOffset = 0.0;
114+
float _humidity = 0.0;
115+
float _temperature = 0.0;
115116
uint32_t _lastRead = 0;
116117
bool _disableIRQ = true;
117118
bool _waitForRead = false;

libraries/DHTNEW/examples/dhtnew_adaptive_delay/dhtnew_adaptive_delay.ino

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@
66
//
77

88
//
9-
// DHT PIN layout from left to right
10-
// =================================
11-
// FRONT : DESCRIPTION
12-
// pin 1 : VCC
13-
// pin 2 : DATA
14-
// pin 3 : Not Connected
15-
// pin 4 : GND
16-
17-
// Note:
18-
// Adaptive delay makes no sense anymore as the DHTNEW lib catches reads that
19-
// are done faster than READ_DELAY apart (see dhtnew.cpp file).
20-
// that said it is the goal to get this adaptability into the library one day.
21-
// A way to do this is to add a function auto_calibrate() that finds the timing
22-
// where reading fails and use that value + safety margin (20%?)
9+
// DHT PIN layout from left to right
10+
// =================================
11+
// FRONT : DESCRIPTION
12+
// pin 1 : VCC
13+
// pin 2 : DATA
14+
// pin 3 : Not Connected
15+
// pin 4 : GND
16+
17+
// Note:
18+
// Adaptive delay makes no sense anymore as the DHTNEW lib catches reads that
19+
// are done faster than READ_DELAY apart (see dhtnew.cpp file).
20+
// that said it is the goal to get this adaptability into the library one day.
21+
// A way to do this is to add a function auto_calibrate() that finds the timing
22+
// where reading fails and use that value + safety margin (20%?)
2323

2424

2525
#include <dhtnew.h>
2626

27-
DHTNEW mySensor(5); // ESP 16 UNO 5 MKR1010 5
27+
DHTNEW mySensor(5); // ESP 16 UNO 5 MKR1010 5
2828

2929

3030
void setup()
3131
{
32-
while(!Serial); // MKR1010 needs this
32+
while(!Serial); // MKR1010 needs this
3333

3434
Serial.begin(115200);
3535
Serial.println("dhtnew_adaptive_delay.ino");
3636
Serial.print("LIBRARY VERSION: ");
3737
Serial.println(DHTNEW_LIB_VERSION);
3838
Serial.println();
3939

40-
// MKR1010 needs this
41-
// mySensor.setDisableIRQ(false);
40+
// MKR1010 needs this
41+
// mySensor.setDisableIRQ(false);
4242

4343
Serial.println("\n1. Type detection test, first run might take longer to determine type");
4444
Serial.println("STAT\tHUMI\tTEMP\tTIME\tTYPE");
@@ -97,7 +97,7 @@ void loop()
9797
void test()
9898
{
9999
static uint16_t dht_delay = 600;
100-
// READ DATA
100+
// READ DATA
101101
uint32_t start = micros();
102102
int chk = mySensor.read();
103103
uint32_t stop = micros();
@@ -144,7 +144,7 @@ void test()
144144
}
145145

146146
dht_delay = constrain(dht_delay, 100, 5000);
147-
// DISPLAY DATA
147+
// DISPLAY DATA
148148
Serial.print(mySensor.getHumidity(), 1);
149149
Serial.print(",\t");
150150
Serial.print(mySensor.getTemperature(), 1);
@@ -159,5 +159,5 @@ void test()
159159
}
160160

161161

162-
// -- END OF FILE --
162+
// -- END OF FILE --
163163

libraries/DHTNEW/examples/dhtnew_array/dhtnew_array.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void loop()
5555

5656
void test(int idx)
5757
{
58-
// READ DATA
58+
// READ DATA
5959
uint32_t start = micros();
6060
int chk = ar[idx].read();
6161
uint32_t stop = micros();
@@ -99,7 +99,7 @@ void test(int idx)
9999
break;
100100
}
101101

102-
// DISPLAY DATA
102+
// DISPLAY DATA
103103
Serial.print(ar[idx].getHumidity(), 1);
104104
Serial.print(",\t");
105105
Serial.print(ar[idx].getTemperature(), 1);
@@ -112,5 +112,5 @@ void test(int idx)
112112
}
113113

114114

115-
// -- END OF FILE --
115+
// -- END OF FILE --
116116

0 commit comments

Comments
 (0)