mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.0 DHT20
This commit is contained in:
parent
c3af1c2dda
commit
f0f20a91e1
@ -6,10 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.0] - 2023-10-25
|
||||
- simplify begin()
|
||||
- updated all examples
|
||||
- update readme.md
|
||||
|
||||
----
|
||||
|
||||
## [0.2.3] - 2023-07-27
|
||||
- fix #12 add time out to read function
|
||||
|
||||
|
||||
## [0.2.2] - 2022-12-21
|
||||
- update keywords.txt
|
||||
- add defaults to offset functions.
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: DHT20.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.3
|
||||
// VERSION: 0.3.0
|
||||
// PURPOSE: Arduino library for DHT20 I2C temperature and humidity sensor.
|
||||
|
||||
|
||||
@ -31,27 +31,11 @@ DHT20::DHT20(TwoWire *wire)
|
||||
|
||||
bool DHT20::begin()
|
||||
{
|
||||
_wire->begin();
|
||||
// _wire->setWireTimeout(DHT20_WIRE_TIME_OUT, true);
|
||||
return isConnected();
|
||||
}
|
||||
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
bool DHT20::begin(const uint8_t dataPin, const uint8_t clockPin)
|
||||
{
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
{
|
||||
_wire->begin(dataPin, clockPin);
|
||||
} else {
|
||||
_wire->begin();
|
||||
}
|
||||
// _wire->setWireTimeout(DHT20_WIRE_TIME_OUT, true);
|
||||
return isConnected();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool DHT20::isConnected()
|
||||
{
|
||||
_wire->beginTransmission(DHT20_ADDRESS);
|
||||
|
@ -3,7 +3,7 @@
|
||||
// FILE: DHT20.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Arduino library for DHT20 I2C temperature and humidity sensor.
|
||||
// VERSION: 0.2.3
|
||||
// VERSION: 0.3.0
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#define DHT20_LIB_VERSION (F("0.2.3"))
|
||||
#define DHT20_LIB_VERSION (F("0.3.0"))
|
||||
|
||||
#define DHT20_OK 0
|
||||
#define DHT20_ERROR_CHECKSUM -10
|
||||
@ -38,10 +38,6 @@ public:
|
||||
// fixed address 0x38
|
||||
DHT20(TwoWire *wire = &Wire);
|
||||
|
||||
// start the I2C
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
bool begin(const uint8_t dataPin, const uint8_t clockPin);
|
||||
#endif
|
||||
bool begin();
|
||||
bool isConnected();
|
||||
uint8_t getAddress();
|
||||
|
@ -2,8 +2,11 @@
|
||||
[![Arduino CI](https://github.com/RobTillaart/DHT20/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/DHT20/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/DHT20/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/DHT20/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/DHT20/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/DHT20.svg)](https://github.com/RobTillaart/DHT20/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/DHT20/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/DHT20.svg?maxAge=3600)](https://github.com/RobTillaart/DHT20/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/DHT20.svg)](https://registry.platformio.org/libraries/robtillaart/DHT20)
|
||||
|
||||
|
||||
# DHT20
|
||||
@ -52,6 +55,11 @@ reset the sensor if needed in both synchronous and asynchronous calls.
|
||||
This keeps the API simple. The reads are 1-2 ms slower than 0.1.4. (< 50 ms).
|
||||
Still far below the 80 ms mentioned in the datasheet.
|
||||
|
||||
### 0.3.0
|
||||
|
||||
User should call Wire.begin(), and setting I2C pins himself.
|
||||
It is removed from the specific ESP32 begin() call to be more generic.
|
||||
|
||||
|
||||
#### Tested
|
||||
|
||||
@ -140,7 +148,6 @@ and should only be used if you are in a need for speed.
|
||||
#### Constructor
|
||||
|
||||
- **DHT20(TwoWire \*wire = &Wire)** constructor, using a specific Wire (I2C bus).
|
||||
- **bool begin(uint8_t dataPin, uint8_t clockPin)** begin for ESP32 et al, to set I2C bus pins.
|
||||
- **bool begin()** initializer for non ESP32. Returns true if connected.
|
||||
- **bool isConnected()** returns true if the address of the DHT20 can be seen on the I2C bus.
|
||||
- **uint8_t getAddress()** returns the (fixed) address - convenience.
|
||||
@ -269,3 +276,12 @@ the read calls. (0.2.0)
|
||||
- **bool getIgnoreChecksum()** get checksum flag. for completeness.
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
//
|
||||
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
@ -22,14 +21,16 @@ uint8_t count = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
//
|
||||
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
@ -31,6 +30,7 @@ void setup()
|
||||
|
||||
Serial.println("\nNOTE: datasheet states 400 KHz as maximum.\n");
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21, 22
|
||||
delay(2000);
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
//
|
||||
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
@ -22,21 +21,21 @@ uint32_t counter = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
DHT.begin(); // ESP32 default 21, 22
|
||||
|
||||
Wire.setClock(400000);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
DHT.begin(); // ESP32 default 21, 22
|
||||
|
||||
delay(2000);
|
||||
|
||||
// start with initial request
|
||||
Serial.println(DHT.requestData());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
//
|
||||
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
@ -57,7 +56,7 @@ uint32_t stop, start;
|
||||
|
||||
int displayAddress = 0x27;
|
||||
|
||||
// lcd object is created as a placeholder as the actual address is determined in setupDisplay()
|
||||
// LCD object is created as a placeholder as the actual address is determined in setupDisplay()
|
||||
// constructor needs an I2C address. Better solution would be a function to set the address
|
||||
// runtime in the class.
|
||||
LiquidCrystal_I2C lcd(displayAddress);
|
||||
@ -97,14 +96,15 @@ void display()
|
||||
|
||||
void setup()
|
||||
{
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
setupDisplay();
|
||||
|
||||
delay(1000);
|
||||
|
@ -3,7 +3,6 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
//
|
||||
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
@ -22,16 +21,17 @@ uint8_t count = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
Wire.setClock(400000);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
//
|
||||
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
@ -13,6 +12,7 @@
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT(&Wire);
|
||||
@ -20,7 +20,9 @@ DHT20 DHT(&Wire);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Humidity, Temperature");
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
//
|
||||
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
@ -22,16 +21,17 @@ uint8_t count = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
Wire.setClock(400000);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
@ -7,5 +7,5 @@ compile:
|
||||
# - leonardo
|
||||
# - m4
|
||||
- esp32
|
||||
- esp8266
|
||||
# - esp8266
|
||||
# - mega2560
|
@ -13,25 +13,22 @@
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT(&Wire);
|
||||
DHT20 DHT(&Wire1); // 2nd I2C interface
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
DHT.begin(12, 13); // select your pin numbers here
|
||||
#else
|
||||
DHT.begin();
|
||||
#endif
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire1.begin(12, 13); // select your pin numbers here
|
||||
|
||||
delay(2000);
|
||||
|
||||
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
|
||||
|
@ -15,9 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DHT20.git"
|
||||
},
|
||||
"version": "0.2.3",
|
||||
"version": "0.3.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "DHT20.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DHT20
|
||||
version=0.2.3
|
||||
version=0.3.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for I2C DHT20 temperature and humidity sensor.
|
||||
|
@ -61,6 +61,7 @@ unittest(test_constructor)
|
||||
assertEqualFloat(0, DHT.getTempOffset(), 0.001);
|
||||
assertEqualFloat(0, DHT.getHumOffset(), 0.001);
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin();
|
||||
assertEqual(DHT20_ERROR_LASTREAD, DHT.read());
|
||||
|
||||
@ -74,6 +75,8 @@ unittest(test_constructor)
|
||||
unittest(test_offset)
|
||||
{
|
||||
DHT20 DHT(&Wire);
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin();
|
||||
|
||||
assertEqualFloat(0, DHT.getTempOffset(), 0.001);
|
||||
|
Loading…
x
Reference in New Issue
Block a user