From 8706f6925a2ce4833e96628bb5a92b0d8b9504a4 Mon Sep 17 00:00:00 2001 From: Jens B Date: Mon, 27 Nov 2023 09:43:02 +0100 Subject: [PATCH] fix reset: clear state of resolution, heater and error (#26) - fix **reset()**: clear state of resolution, heater and error - update readme.md - minor edits --- CHANGELOG.md | 5 +++++ README.md | 11 +++++++---- SHT2x.cpp | 36 +++++++++++++++++++++--------------- SHT2x.h | 10 +++++----- library.json | 5 ++++- library.properties | 2 +- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d4396..643a81e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.4.1] - 2023-11-25 +- fix **reset()**: clear state of resolution, heater and error +- update readme.md +- minor edits + ## [0.4.0] - 2023-09-21 - moved TwoWire param from begin() to Constructor - FIx #23 support for Wire1 for ESP32 diff --git a/README.md b/README.md index cca9278..5d91214 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,9 @@ Accuracy table | Sensor | Temperature | Humidity | Notes | |:---------:|:-----------:|:--------:|:--------| -| SHT20 | ~0.3 | ±3.0 | | -| SHT21 | ~0.3 | ±3.0 | | -| SHT25 | ~0.3 | ±1.8 | | +| SHT20 | ~0.3 | ±3.0 | | +| SHT21 | ~0.3 | ±3.0 | | +| SHT25 | ~0.3 | ±1.8 | | | HTU20 | | | to-do | | HTU21 | | | to-do | | Si7013 | | | to-do | @@ -83,7 +83,7 @@ Initial release has a blocking delay. - **uint32_t lastRead()** in milliSeconds since start of program. - **bool reset()** resets the sensor, soft reset, no hard reset supported. - **float getHumidity()** computes the relative humidity in % based off the latest raw reading, and returns it. -- **float getTemperature()** computes the temperature in °C based off the latest raw reading, and returns it. +- **float getTemperature()** computes the temperature in °C based off the latest raw reading, and returns it. - **uint16_t getRawHumidity()** returns the raw two-byte representation of humidity directly from the sensor. - **uint16_t getRawTemperature()** returns the raw two-byte representation of temperature directly from the sensor. @@ -244,6 +244,9 @@ Timing in milliseconds. - investigate blocking delay() in read - add offset for temperature and humidity +#### 0.4.1 +- fix reset(): clear state of resolution, heater and error + #### Should - test test test diff --git a/SHT2x.cpp b/SHT2x.cpp index ce857ba..5b31771 100644 --- a/SHT2x.cpp +++ b/SHT2x.cpp @@ -1,8 +1,8 @@ // // FILE: SHT2x.cpp -// AUTHOR: Rob Tillaart, Viktor Balint -// VERSION: 0.4.0 -// DATE: 2021-09-25 +// AUTHOR: Rob Tillaart, Viktor Balint, JensB +// VERSION: 0.4.1 +// DATE: 2023-11-25 // PURPOSE: Arduino library for the SHT2x temperature and humidity sensor // URL: https://github.com/RobTillaart/SHT2x @@ -11,20 +11,20 @@ // SUPPORTED COMMANDS -#define SHT2x_GET_TEMPERATURE_NO_HOLD 0xF3 -#define SHT2x_GET_HUMIDITY_NO_HOLD 0xF5 -#define SHT2x_SOFT_RESET 0xFE -#define SHT2x_WRITE_USER_REGISTER 0xE6 -#define SHT2x_READ_USER_REGISTER 0xE7 +#define SHT2x_GET_TEMPERATURE_NO_HOLD 0xF3 +#define SHT2x_GET_HUMIDITY_NO_HOLD 0xF5 +#define SHT2x_SOFT_RESET 0xFE +#define SHT2x_WRITE_USER_REGISTER 0xE6 +#define SHT2x_READ_USER_REGISTER 0xE7 -#define SHT2x_HEATER_TIMEOUT 180000UL // milliseconds +#define SHT2x_HEATER_TIMEOUT 180000UL // milliseconds -#define SHT2x_ADDRESS 0x40 +#define SHT2x_ADDRESS 0x40 -#define SHT2x_USRREG_RESOLUTION 0x81 -#define SHT2x_USRREG_BATTERY 0x20 -#define SHT2x_USRREG_HEATER 0x04 +#define SHT2x_USRREG_RESOLUTION 0x81 +#define SHT2x_USRREG_BATTERY 0x20 +#define SHT2x_USRREG_HEATER 0x04 ////////////////////////////////////////////////////////////// @@ -273,8 +273,14 @@ uint16_t SHT2x::getRawHumidity() bool SHT2x::reset() { - bool b = writeCmd(SHT2x_SOFT_RESET); - return b; + bool success = writeCmd(SHT2x_SOFT_RESET); + if (success) + { + _resolution = 0; + _heaterOn = false; + _error = SHT2x_OK; + } + return success; } diff --git a/SHT2x.h b/SHT2x.h index 94265d7..6215530 100644 --- a/SHT2x.h +++ b/SHT2x.h @@ -1,9 +1,9 @@ #pragma once // // FILE: SHT2x.h -// AUTHOR: Rob Tillaart, Viktor Balint -// VERSION: 0.4.0 -// DATE: 2021-09-25 +// AUTHOR: Rob Tillaart, Viktor Balint, JensB +// VERSION: 0.4.1 +// DATE: 2023-11-25 // PURPOSE: Arduino library for the SHT2x temperature and humidity sensor // URL: https://github.com/RobTillaart/SHT2x // @@ -13,7 +13,7 @@ #include "Wire.h" -#define SHT2x_LIB_VERSION (F("0.4.0")) +#define SHT2x_LIB_VERSION (F("0.4.1")) // fields getStatus @@ -63,7 +63,7 @@ class SHT2x // // TEMPERATURE AND HUMIDTY // - // read must be called get getTemperature / getHumidity + // read must be called before calling getTemperature / getHumidity bool read(); float getTemperature(); diff --git a/library.json b/library.json index 535d3d8..9843e70 100644 --- a/library.json +++ b/library.json @@ -11,6 +11,9 @@ }, { "name": "Viktor Balint" + }, + { + "name": "JensB" } ], "repository": @@ -18,7 +21,7 @@ "type": "git", "url": "https://github.com/RobTillaart/SHT2x.git" }, - "version": "0.4.0", + "version": "0.4.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index ec2f29c..246da4a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SHT2x -version=0.4.0 +version=0.4.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for the I2C SHT20 SHT21 SHT25 series temperature and humidity sensor.