Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reset: clear state of resolution, heater and error #26

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading