mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.4.14 DHTNEW
This commit is contained in:
parent
64e9b6503b
commit
3cbc47e955
@ -1,11 +1,28 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- due
|
||||
- zero
|
||||
- leonardo
|
||||
# - due
|
||||
# - zero
|
||||
#- leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
- mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
126
libraries/DHTNEW/CHANGELOG.md
Normal file
126
libraries/DHTNEW/CHANGELOG.md
Normal file
@ -0,0 +1,126 @@
|
||||
# Change Log DHTNEW
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.4.14] 2022-10-13
|
||||
- Fix #79, experimental support for Si7021.
|
||||
- Add RP2040 pico in build-CI
|
||||
- Add CHANGELOG.md
|
||||
|
||||
## [0.4.13] 2022-07-05
|
||||
- Fix #76, disable interrupts for ESP32.
|
||||
|
||||
## [0.4.12] 2022-01-31
|
||||
- Fix #72, delayMicroseconds() for wakeUp
|
||||
|
||||
## [0.4.11] 2021-12-16
|
||||
- update library.json, license, minor edits (clean up),
|
||||
- add constants to unit tests
|
||||
|
||||
## [0.4.10] 2021-11-18
|
||||
- update build-CI - compilation test on M4 and ESP32 of examples
|
||||
- update readme.md, badges, typos, reorganizing
|
||||
- added note: MKR1010 Wifi support - setDisableIRQ(false)
|
||||
- minor edits in examples
|
||||
- changed TIMEOUT_C to 90us (after endurance test on MKR1010 Wifi)
|
||||
|
||||
## [0.4.9] - 2021-06-13
|
||||
- add optional flag DHTLIB_VALUE_OUT_OF_RANGE
|
||||
|
||||
## [0.4.8] - 2021-05-27
|
||||
- fixes to improve Arduino-lint
|
||||
|
||||
## [0.4.7] - 2021-04-09
|
||||
- fix #60 negative temperatures below -25.5°C + readme.md
|
||||
|
||||
## [0.4.6] - 2021-04-09
|
||||
- fix #57 negative temperatures DHT22
|
||||
- Do not use 0.4.5 and 0.4.4 as these are incorrect for negative temperature.
|
||||
|
||||
## [0.4.5] - 2021-02-14
|
||||
- fix -0°C encoding of DHT22 ( bit pattern 0x8000 )
|
||||
|
||||
## [0.4.4] - 2021-02-01
|
||||
- fix negative temperatures DHT22 (again)
|
||||
|
||||
## [0.4.3] - 2021-01-13
|
||||
- add reset(), add lastRead()
|
||||
|
||||
## [0.4.2] - 2020-12-15
|
||||
- fix negative temperatures
|
||||
|
||||
## [0.4.1] - 2020-11-11
|
||||
- getType() attempts to detect sensor type
|
||||
- add Arduino -CI + readme
|
||||
|
||||
## [0.4.0] - 2020-11-10
|
||||
- added DHTLIB_WAITING_FOR_READ as return value of read (minor break of interface)
|
||||
|
||||
----
|
||||
|
||||
## [0.3.4] - 2020-09-23
|
||||
- Added **waitFor(state, timeout)** to follow timing from datasheet.
|
||||
- Restored disableIRQ flag as problems occurred on AVR.
|
||||
The default of this flag on AVR is false so interrupts are allowed.
|
||||
- This need some investigation
|
||||
- Fix wake up timing for DHT11 as it does not behave according datasheet.
|
||||
- fix wakeupDelay bug in setType();
|
||||
|
||||
## [0.3.3] - 2020-08-18
|
||||
- fix #29, create explicit delay between pulling line HIGH and
|
||||
waiting for LOW in handshake to trigger the sensor.
|
||||
- On fast ESP32 this fails because the capacity / voltage of the long wire
|
||||
- cannot rise fast enough to be read back as HIGH.
|
||||
|
||||
## [0.3.2] - 2020-07-17
|
||||
- fix #23 added get/setSuppressError(); overridable DHTLIB_INVALID_VALUE
|
||||
|
||||
## [0.3.1] - 2020-07-08
|
||||
- added powerUp() powerDown();
|
||||
|
||||
## [0.3.0] - 2020-06-12
|
||||
- added getReadDelay & setReadDelay to tune reading interval
|
||||
- removed get/setDisableIRQ; adjusted wakeup timing; refactor
|
||||
|
||||
----
|
||||
|
||||
## [0.2.2] - 2020-06-08
|
||||
- added ERROR_SENSOR_NOT_READY and differentiate timeout errors
|
||||
|
||||
## [0.2.1] - 2020-05-27
|
||||
- Fix #11 - Adjust bit timing threshold
|
||||
|
||||
## [0.2.0] - 2020-05-02
|
||||
- made temperature and humidity private (Kudo's to Mr-HaleYa),
|
||||
|
||||
----
|
||||
|
||||
## [0.1.7] - 2020-05-01
|
||||
- prevent premature read; add waitForReading flag (Kudo's to Mr-HaleYa),
|
||||
|
||||
## [0.1.6] - 2020-04-09
|
||||
- #pragma once, readme.md, own repo
|
||||
|
||||
## [0.1.5] - 2019-01-20
|
||||
- fix negative temperature DHT22 - issue #120
|
||||
|
||||
## [0.1.4] - 2018-04-03
|
||||
- add get-/setDisableIRQ(bool b)
|
||||
|
||||
## [0.1.3] - 2018-01-08
|
||||
- removed begin() + moved detection to read() function
|
||||
|
||||
## [0.1.2] - 2018-01-08
|
||||
- improved begin() + refactor()
|
||||
|
||||
## [0.1.1] - 2017-07-29
|
||||
- add begin() to determine type once and for all instead of every call + refactor
|
||||
|
||||
## [0.1.0] - 2017-07-24
|
||||
- initial version based upon DHTStable
|
||||
|
||||
|
@ -1,67 +1,22 @@
|
||||
//
|
||||
// FILE: dhtnew.cpp
|
||||
// AUTHOR: Rob.Tillaart@gmail.com
|
||||
// VERSION: 0.4.13
|
||||
// VERSION: 0.4.14
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTNEW
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2017-07-24 initial version based upon DHTStable
|
||||
// 0.1.1 2017-07-29 add begin() to determine type once and for all instead of every call + refactor
|
||||
// 0.1.2 2018-01-08 improved begin() + refactor()
|
||||
// 0.1.3 2018-01-08 removed begin() + moved detection to read() function
|
||||
// 0.1.4 2018-04-03 add get-/setDisableIRQ(bool b)
|
||||
// 0.1.5 2019-01-20 fix negative temperature DHT22 - issue #120
|
||||
// 0.1.6 2020-04-09 #pragma once, readme.md, own repo
|
||||
// 0.1.7 2020-05-01 prevent premature read; add waitForReading flag (Kudo's to Mr-HaleYa),
|
||||
// 0.2.0 2020-05-02 made temperature and humidity private (Kudo's to Mr-HaleYa),
|
||||
// 0.2.1 2020-05-27 Fix #11 - Adjust bit timing threshold
|
||||
// 0.2.2 2020-06-08 added ERROR_SENSOR_NOT_READY and differentiate timeout errors
|
||||
// 0.3.0 2020-06-12 added getReadDelay & setReadDelay to tune reading interval
|
||||
// removed get/setDisableIRQ; adjusted wakeup timing; refactor
|
||||
// 0.3.1 2020-07-08 added powerUp() powerDown();
|
||||
// 0.3.2 2020-07-17 fix #23 added get/setSuppressError(); overridable DHTLIB_INVALID_VALUE
|
||||
// 0.3.3 2020-08-18 fix #29, create explicit delay between pulling line HIGH and
|
||||
// waiting for LOW in handshake to trigger the sensor.
|
||||
// On fast ESP32 this fails because the capacity / voltage of the long wire
|
||||
// cannot rise fast enough to be read back as HIGH.
|
||||
// 0.3.4 2020-09-23 Added **waitFor(state, timeout)** to follow timing from datasheet.
|
||||
// Restored disableIRQ flag as problems occurred on AVR. The default of
|
||||
// this flag on AVR is false so interrupts are allowed.
|
||||
// This need some investigation
|
||||
// Fix wake up timing for DHT11 as it does not behave according datasheet.
|
||||
// fix wakeupDelay bug in setType();
|
||||
// 0.4.0 2020-11-10 added DHTLIB_WAITING_FOR_READ as return value of read (minor break of interface)
|
||||
// 0.4.1 2020-11-11 getType() attempts to detect sensor type
|
||||
// 2020-12-12 add Arduino -CI + readme
|
||||
// 0.4.2 2020-12-15 fix negative temperatures
|
||||
// 0.4.3 2021-01-13 add reset(), add lastRead()
|
||||
// 0.4.4 2021-02-01 fix negative temperatures DHT22 (again)
|
||||
// 0.4.5 2021-02-14 fix -0°C encoding of DHT22 ( bit pattern 0x8000 )
|
||||
// 0.4.6 2021-04-09 fix #57 negative temperatures DHT22
|
||||
// Do not use 0.4.5 and 0.4.4 as these are incorrect for negative temperature.
|
||||
// 0.4.7 2021-04-09 fix #60 negative temperatures below -25.5°C + readme.md
|
||||
// 0.4.8 2021-05-27 fixes to improve Arduino-lint
|
||||
// 0.4.9 2021-06-13 add optional flag DHTLIB_VALUE_OUT_OF_RANGE
|
||||
// 0.4.10 2021-11-18 update build-CI - compilation test on M4 and ESP32 of examples
|
||||
// update readme.md, badges, typos, reorganizing
|
||||
// added note: MKR1010 Wifi support - setDisableIRQ(false)
|
||||
// minor edits in examples
|
||||
// changed TIMEOUT_C to 90us (after endurance test on MKR1010 Wifi)
|
||||
// 0.4.11 2021-12-16 update library.json, license, minor edits (clean up),
|
||||
// add constants to unit tests
|
||||
// 0.4.12 2022-01-31 Fix #72, delayMicroseconds() for wakeUp
|
||||
// 0.4.13 2022-07-05 Fix #76, disable interrupts for ESP32.
|
||||
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "dhtnew.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// these defines are not for user to adjust
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
// these defines are not for user to adjust (microseconds)
|
||||
#define DHTLIB_DHT11_WAKEUP (18 * 1100UL)
|
||||
#define DHTLIB_DHT_WAKEUP (1 * 1100UL)
|
||||
// experimental 0.4.14
|
||||
#define DHTLIB_SI7021_WAKEUP (500)
|
||||
|
||||
|
||||
// READ_DELAY for blocking read
|
||||
@ -75,7 +30,7 @@
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
// PUBLIC
|
||||
//
|
||||
DHTNEW::DHTNEW(uint8_t pin)
|
||||
{
|
||||
@ -104,7 +59,7 @@ void DHTNEW::reset()
|
||||
#if defined(__AVR__)
|
||||
_disableIRQ = false;
|
||||
#endif
|
||||
// #if defined(MKR1010) // TODO find out real define
|
||||
// #if defined(MKR1010) // TODO find out real define
|
||||
// _disableIRQ = false;
|
||||
// #endif
|
||||
}
|
||||
@ -129,6 +84,12 @@ void DHTNEW::setType(uint8_t type)
|
||||
_type = type;
|
||||
_wakeupDelay = DHTLIB_DHT_WAKEUP;
|
||||
}
|
||||
// experimental 0.4.14
|
||||
if (type == 70)
|
||||
{
|
||||
_type = type;
|
||||
_wakeupDelay = DHTLIB_SI7021_WAKEUP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -159,6 +120,8 @@ int DHTNEW::read()
|
||||
return _read();
|
||||
}
|
||||
|
||||
// AUTODETECT
|
||||
|
||||
_type = 22;
|
||||
_wakeupDelay = DHTLIB_DHT_WAKEUP;
|
||||
int rv = _read();
|
||||
@ -169,6 +132,12 @@ int DHTNEW::read()
|
||||
rv = _read();
|
||||
if (rv == DHTLIB_OK) return rv;
|
||||
|
||||
// experimental 0.4.14
|
||||
_type = 70;
|
||||
_wakeupDelay = DHTLIB_SI7021_WAKEUP;
|
||||
rv = _read();
|
||||
if (rv == DHTLIB_OK) return rv;
|
||||
|
||||
_type = 0; // retry next time
|
||||
return rv;
|
||||
}
|
||||
@ -331,16 +300,24 @@ int DHTNEW::_readSensor()
|
||||
pinMode(_dataPin, OUTPUT);
|
||||
digitalWrite(_dataPin, LOW);
|
||||
|
||||
// WAKE UP - add 10% extra for timing inaccuracies in sensor.
|
||||
uint32_t startWakeup = micros();
|
||||
do
|
||||
// HANDLE SI7021 separately (see #79)
|
||||
if (_type == 70)
|
||||
{
|
||||
// HANDLE PENDING IRQ
|
||||
yield();
|
||||
// 180 gives good wakeup delay on UNO for DHT22 / DHT11 (issue #72)
|
||||
delayMicroseconds(180UL);
|
||||
delayMicroseconds(DHTLIB_SI7021_WAKEUP); // hardcoded for now
|
||||
}
|
||||
else
|
||||
{
|
||||
// WAKE UP - add 10% extra for timing inaccuracies in sensor.
|
||||
uint32_t startWakeup = micros();
|
||||
do
|
||||
{
|
||||
// HANDLE PENDING IRQ
|
||||
yield();
|
||||
// 180 gives good wakeup delay on UNO for DHT22 / DHT11 (issue #72)
|
||||
delayMicroseconds(180UL);
|
||||
}
|
||||
while((micros() - startWakeup) < _wakeupDelay);
|
||||
}
|
||||
while((micros() - startWakeup) < (_wakeupDelay * 1100UL));
|
||||
|
||||
// HOST GIVES CONTROL TO SENSOR
|
||||
digitalWrite(_dataPin, HIGH);
|
||||
@ -350,7 +327,7 @@ int DHTNEW::_readSensor()
|
||||
// DISABLE INTERRUPTS when clock in the bits
|
||||
if (_disableIRQ)
|
||||
{
|
||||
#if defined(ESP32)
|
||||
#if defined(ESP32)
|
||||
portDISABLE_INTERRUPTS();
|
||||
#else
|
||||
noInterrupts();
|
||||
@ -379,7 +356,7 @@ int DHTNEW::_readSensor()
|
||||
for (uint8_t i = 40; i != 0; i--)
|
||||
{
|
||||
// EACH BIT START WITH ~50 us LOW
|
||||
if (_waitFor(HIGH, 90))
|
||||
if (_waitFor(HIGH, 90))
|
||||
{
|
||||
// Most critical timeout
|
||||
// Serial.print("IC: ");
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: dhtnew.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.4.13
|
||||
// VERSION: 0.4.14
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTNEW
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define DHTNEW_LIB_VERSION (F("0.4.13"))
|
||||
#define DHTNEW_LIB_VERSION (F("0.4.14"))
|
||||
|
||||
|
||||
#define DHTLIB_OK 0
|
||||
@ -104,7 +104,7 @@ public:
|
||||
|
||||
private:
|
||||
uint8_t _dataPin = 0;
|
||||
uint8_t _wakeupDelay = 0;
|
||||
uint32_t _wakeupDelay = 0;
|
||||
uint8_t _type = 0;
|
||||
float _humOffset = 0.0;
|
||||
float _tempOffset = 0.0;
|
||||
|
@ -30,6 +30,7 @@ void setup()
|
||||
// mySensor.setDisableIRQ(false);
|
||||
|
||||
Serial.println("BEFORE OFFSET");
|
||||
delay(2000);
|
||||
mySensor.read();
|
||||
Serial.print(mySensor.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
|
@ -13,7 +13,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DHTNEW.git"
|
||||
},
|
||||
"version": "0.4.13",
|
||||
"version": "0.4.14",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DHTNEW
|
||||
version=0.4.13
|
||||
version=0.4.14
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for DHT temperature and humidity sensor, with automatic sensortype recognition.
|
||||
|
@ -19,6 +19,13 @@ This is the main development library of all my DHT libraries.
|
||||
Supports DHT11, DHT22, DHT33, DHT44, AM2301, AM2302, AM2303 as these all have the same protocol.
|
||||
Note there are differences e.g. DHT11 has no negative temperature, no decimals, and a longer wakeup time.
|
||||
|
||||
#### Sonoff Si7021
|
||||
|
||||
Since 0.4.14 there is **experimental** support for the Sonoff Si7021 .
|
||||
No hardware yet to test this myself, but it is confirmed to work.(see #79)
|
||||
Seems the Sonoff Si7021 sensor is very sensitive in the wakeup timing.
|
||||
This behavior needs to be investigated in the future.
|
||||
|
||||
|
||||
## DHT PIN layout from left to right
|
||||
|
||||
@ -58,8 +65,16 @@ Note there are differences e.g. DHT11 has no negative temperature, no decimals,
|
||||
however it does not reset the sensor in a hardware way.
|
||||
- **uint8_t getType()** 0 = unknown, 11 or 22.
|
||||
In case of 0, **getType()** will try to determine type.
|
||||
Since 0.4.14 type 70 is added for **experimental** Sonoff Si7021 support.
|
||||
- **void setType(uint8_t type = 0)** allows to force the type of the sensor.
|
||||
|
||||
| type | sensors | notes |
|
||||
|:------:|:---------------:|:---------------|
|
||||
| 0 | not defined | |
|
||||
| 11 | DHT11 | |
|
||||
| 22 | DHT22 a.o | most others |
|
||||
| 70 | Sonoff Si7021 | experimental |
|
||||
|
||||
|
||||
### Base interface
|
||||
|
||||
@ -217,18 +232,28 @@ updated TIMEOUT_C from 70 -> 90 us to minimize its occurrence - See https://gith
|
||||
added ```while(!Serial);``` in examples to they work for MKR1010 Wifi.
|
||||
27. (0.4.11)
|
||||
update library.json, license, minor edits (cleanup), unit tests
|
||||
28. (0.4.12)
|
||||
Fix #72, delayMicroseconds() for wakeUp
|
||||
29. (0.4.13)
|
||||
Fix #76, disable interrupts for ESP32.
|
||||
30. (0.4.14)
|
||||
added experimental support for Si7021.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
|
||||
- move history to separate CHANGELOG.md file
|
||||
|
||||
#### should
|
||||
|
||||
- test on more boards
|
||||
- investigate temperature constraining (type dependant.
|
||||
- update documentation
|
||||
- move history to separate release_notes.md file ?
|
||||
- improve unit test
|
||||
- fix DHTLIB_VALUE_OUT_OF_RANGE code
|
||||
- #if defined(MKR1010) // TODO find out real define
|
||||
-
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user