0.3.0 DHT20

This commit is contained in:
Rob Tillaart 2023-10-25 17:19:14 +02:00
parent c3af1c2dda
commit f0f20a91e1
16 changed files with 83 additions and 79 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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();

View File

@ -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,

View File

@ -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);
}
@ -38,7 +39,7 @@ void loop()
{
if (millis() - DHT.lastRead() >= 1000)
{
// READ DATA
// READ DATA
uint32_t start = micros();
int status = DHT.read();
uint32_t stop = micros();
@ -52,7 +53,7 @@ void loop()
count++;
Serial.print("DHT20 \t");
// DISPLAY DATA, sensor has only one decimal.
// DISPLAY DATA, sensor has only one decimal.
Serial.print(DHT.getHumidity(), 1);
Serial.print("\t\t");
Serial.print(DHT.getTemperature(), 1);
@ -91,4 +92,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -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);
@ -98,4 +98,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -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());
}
@ -65,4 +64,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -3,7 +3,6 @@
// AUTHOR: Rob Tillaart
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
//
// Always check datasheet - front view
//
// +--------------+
@ -57,16 +56,16 @@ uint32_t stop, start;
int displayAddress = 0x27;
// 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.
// 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);
void setupDisplay()
{
lcd = LiquidCrystal_I2C(displayAddress, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
lcd.begin(20, 4);
// lcd.setBacklightPin(BACKLIGHT_PIN, NEGATIVE);
// lcd.setBacklightPin(BACKLIGHT_PIN, NEGATIVE);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(BL_ON);
}
@ -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);
@ -115,7 +115,7 @@ void loop()
{
if (millis() - DHT.lastRead() >= 1000)
{
// READ DATA
// READ DATA
start = micros();
int status = DHT.read();
stop = micros();
@ -131,7 +131,7 @@ void loop()
count++;
Serial.print("DHT20 \t");
// DISPLAY DATA, sensor has only one decimal.
// DISPLAY DATA, sensor has only one decimal.
Serial.print(DHT.getHumidity(), 1);
Serial.print("\t\t");
Serial.print(DHT.getTemperature(), 1);
@ -170,4 +170,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -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);
}
@ -48,7 +48,7 @@ void loop()
// make a measurement every 2 seconds
if (millis() - DHT.lastRead() >= 2000)
{
// READ DATA
// READ DATA
uint32_t start = micros();
int status = DHT.read();
uint32_t stop = micros();
@ -62,7 +62,7 @@ void loop()
count++;
Serial.print("DHT20 \t");
// DISPLAY DATA, sensor has only one decimal.
// DISPLAY DATA, sensor has only one decimal.
Serial.print(DHT.getHumidity(), 1);
Serial.print("\t\t");
Serial.print(DHT.getTemperature(), 1);
@ -105,4 +105,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -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");
}
@ -30,7 +32,7 @@ void loop()
{
if (millis() - DHT.lastRead() >= 1000)
{
// note no error checking
// note no error checking
DHT.read();
Serial.print(DHT.getHumidity(), 1);
Serial.print(", ");
@ -39,4 +41,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -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);
}
@ -44,4 +44,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -7,5 +7,5 @@ compile:
# - leonardo
# - m4
- esp32
- esp8266
# - esp8266
# - mega2560

View File

@ -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)");

View File

@ -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"
}

View File

@ -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.

View File

@ -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);