Skip to content

Commit

Permalink
fix reset: clear state of resolution, heater and error (#26)
Browse files Browse the repository at this point in the history
- fix **reset()**: clear state of resolution, heater and error
- update readme.md
- minor edits
  • Loading branch information
jnsbyr committed Nov 27, 2023
1 parent df4d8fa commit 8706f69
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
36 changes: 21 additions & 15 deletions SHT2x.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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


//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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;
}


Expand Down
10 changes: 5 additions & 5 deletions SHT2x.h
Original file line number Diff line number Diff line change
@@ -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
//
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
},
{
"name": "Viktor Balint"
},
{
"name": "JensB"
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/SHT2x.git"
},
"version": "0.4.0",
"version": "0.4.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SHT2x
version=0.4.0
version=0.4.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the I2C SHT20 SHT21 SHT25 series temperature and humidity sensor.
Expand Down

0 comments on commit 8706f69

Please sign in to comment.