Skip to content

Commit 36fbe4b

Browse files
committed
0.5.1 SHT31
1 parent 1300a86 commit 36fbe4b

File tree

9 files changed

+211
-60
lines changed

9 files changed

+211
-60
lines changed

libraries/SHT31/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.5.1] - 2025-04-28
10+
- add **clearStatus()**, kudos to Elbandi
11+
- update readme.md
12+
- removed **heatUp** from documentation, labelled as depreciated.
13+
- add example SHT31_demo_plotter.ino
14+
- update keywords.txt
15+
- minor edits
16+
917
## [0.5.0] - 2023-12-09
1018
- refactor API, constructor and begin()
1119
- add **getAddress()**

libraries/SHT31/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019-2024 Rob Tillaart
3+
Copyright (c) 2019-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/SHT31/README.md

Lines changed: 97 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ Relates to the SHT85 library - https://github.com/RobTillaart/SHT85
1818

1919
## Description
2020

21-
The SHT3x family of sensors should work up to 1 MHz I2C
21+
The SHT3x family of sensors should work up to 1 MHz I2C.
2222

23-
This library should also work for SHT30 and SHT35 but these are
23+
This library should also work for SHT30 and SHT35 but these are
2424
not tested yet.
2525

2626
Accuracy table
2727

28-
| SENSOR | Temperature | Humidity |
29-
|:--------:|:-------------:|:----------:|
30-
| SHT30 | ~0.3 | 2.0 |
31-
| SHT31 | ~0.3 | 1.5 |
32-
| SHT35 | ~0.2 | 1.5 |
33-
| SHT85 | ~0.2 | 1.5 |
28+
| Sensor | Temperature | Humidity | Verified }
29+
|:--------:|:-------------:|:----------:|:----------:|
30+
| SHT30 | ~0.3° | 2.0% | N |
31+
| SHT31 | ~0.3° | 1.5% | Y |
32+
| SHT35 | ~0.2° | 1.5% | N |
33+
| SHT85 | ~0.2° | 1.5% | Y |
3434

3535

3636
An elaborated library for the SHT31 sensor can be found here
@@ -40,7 +40,25 @@ A derived class for using the SHT31 sensor with SoftWire (soft I2C) can be found
4040
- https://github.com/RobTillaart/SHT31_SW
4141

4242

43-
#### 0.5.0 Breaking change
43+
### I2C multiplexing
44+
45+
Sometimes you need to control more devices than possible with the default
46+
address range the device provides.
47+
This is possible with an I2C multiplexer e.g. TCA9548 which creates up
48+
to eight channels (think of it as I2C subnets) which can use the complete
49+
address range of the device.
50+
51+
Drawback of using a multiplexer is that it takes more administration in
52+
your code e.g. which device is on which channel.
53+
This will slow down the access, which must be taken into account when
54+
deciding which devices are on which channel.
55+
Also note that switching between channels will slow down other devices
56+
too if they are behind the multiplexer.
57+
58+
- https://github.com/RobTillaart/TCA9548
59+
60+
61+
### 0.5.0 Breaking change
4462

4563
Version 0.5.0 introduced a breaking change.
4664
You cannot set the pins in **begin()** any more.
@@ -49,12 +67,32 @@ The user has to call **Wire.begin()** and can optionally set the Wire pins
4967
before calling **begin()**.
5068

5169

52-
#### Related
70+
### Related
5371

54-
- https://github.com/RobTillaart/SHT31
55-
- https://github.com/RobTillaart/SHT31_SW
56-
- https://github.com/RobTillaart/SHT31_SWW
57-
- https://github.com/RobTillaart/SHT85
72+
SHT series temperature sensors
73+
74+
- https://github.com/RobTillaart/SHT2x
75+
- https://github.com/RobTillaart/SHT31 Sensirion humidity / temperature sensor
76+
- https://github.com/RobTillaart/SHT31_SW = softWire based I2C.
77+
- https://github.com/RobTillaart/SHT31_SWW = softWire based I2C.
78+
- https://github.com/RobTillaart/SHT85 Sensirion humidity / temperature sensor
79+
- https://github.com/RobTillaart/tinySHT2x
80+
81+
Other temperature sensors
82+
83+
- https://github.com/RobTillaart/DHTNew DHT11/22 etc
84+
- https://github.com/RobTillaart/DHTStable DHT11/22 etc
85+
- https://github.com/RobTillaart/DHT_Simulator
86+
- https://github.com/RobTillaart/DS18B20_INT OneWire temperature sensor
87+
- https://github.com/RobTillaart/DS18B20_RT OneWire temperature sensor
88+
89+
An elaborated library for the SHT31 sensor can be found here
90+
- https://github.com/hawesg/SHT31D_Particle_Photon_ClosedCube
91+
92+
Other, including Dewpoint, heatindex, related functions and conversions.
93+
94+
- https://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html (interesting)
95+
- https://github.com/RobTillaart/Temperature (conversions, dewPoint, heat index etc.)
5896

5997

6098
## Interface
@@ -63,7 +101,7 @@ before calling **begin()**.
63101
#include "SHT31.h"
64102
```
65103

66-
#### Constructor
104+
### Constructor
67105

68106
- **SHT31(uint8_t address = SHT_DEFAULT_ADDRESS, TwoWire \*wire = &Wire)** constructor.
69107
Optional select address and the I2C bus (Wire, Wire1 etc).
@@ -73,16 +111,29 @@ Returns false if device address is incorrect or device cannot be reset.
73111
- **uint8_t getAddress()** returns address set in the constructor.
74112

75113

76-
#### Read
114+
### Read
77115

78116
- **bool read(bool fast = true)** blocks 4 (fast) or 15 (slow) milliseconds + actual read + math.
79117
Does read both the temperature and humidity.
80-
- **uint16_t readStatus()** details see datasheet and **Status fields** below.
118+
119+
Meta information about the sensor.
120+
121+
- **uint16_t readStatus()** returns bit mask, details see **Status fields** below (and datasheet).
122+
- **bool clearStatus()** clear status register, see **Status fields** below.
81123
- **uint32_t lastRead()** in milliSeconds since start of program.
82-
- **bool reset(bool hard = false)** resets the sensor, soft reset by default. Returns false if it fails.
124+
- **bool reset(bool hard = false)** resets the sensor, soft reset by default. Returns false if call fails.
125+
126+
The following functions will return the same value until a new **read()** call (or async) is made.
127+
83128
- **float getHumidity()** computes the relative humidity in % based on the latest raw reading, and returns it.
84129
- **float getTemperature()** computes the temperature in °C based on the latest raw reading, and returns it.
85130
- **float getFahrenheit()** computes the temperature in °F based on the latest raw reading, and returns it..
131+
132+
133+
The **getRawHumidity()** and **getRawTemperature()** can be used to minimize storage or communication as the data type is 50% smaller.
134+
Another application is faster comparison with a previous value or threshold.
135+
However comparisons are quite fast.
136+
86137
- **uint16_t getRawHumidity()** returns the raw two-byte representation of humidity directly from the sensor.
87138
- **uint16_t getRawTemperature()** returns the raw two-byte representation of temperature directly from the sensor.
88139

@@ -91,26 +142,27 @@ If you're worried about the extra cycles, you should make sure to cache these va
91142
you've performed a new reading.
92143

93144

94-
#### Error interface
145+
### Error interface
95146

96147
- **int getError()** returns last set error flag and clear it.
97-
Be sure to clear the error flag by calling **getError()** before calling any command as the error flag could be from a previous command.
148+
Be sure to clear the error flag by calling **getError()** before calling
149+
any command as the error flag could be from a previous command.
98150

99-
| Error | Symbolic | Description |
100-
|:-------:|:----------------------------|:------------------------------|
101-
| 0x00 | SHT31_OK | no error |
102-
| 0x81 | SHT31_ERR_WRITECMD | I2C write failed |
103-
| 0x82 | SHT31_ERR_READBYTES | I2C read failed |
104-
| 0x83 | SHT31_ERR_HEATER_OFF | Could not switch off heater |
105-
| 0x84 | SHT31_ERR_NOT_CONNECT | Could not connect |
106-
| 0x85 | SHT31_ERR_CRC_TEMP | CRC error in temperature |
107-
| 0x86 | SHT31_ERR_CRC_HUM | CRC error in humidity |
108-
| 0x87 | SHT31_ERR_CRC_STATUS | CRC error in status field |
109-
| 0x88 | SHT31_ERR_HEATER_COOLDOWN | Heater need to cool down |
110-
| 0x88 | SHT31_ERR_HEATER_ON | Could not switch on heater |
151+
| Error | Symbolic | Description |
152+
|:-------:|:----------------------------|:-------------------------------|
153+
| 0x00 | SHT31_OK | no error |
154+
| 0x81 | SHT31_ERR_WRITECMD | I2C write failed |
155+
| 0x82 | SHT31_ERR_READBYTES | I2C read failed |
156+
| 0x83 | SHT31_ERR_HEATER_OFF | Could not switch off heater |
157+
| 0x84 | SHT31_ERR_NOT_CONNECT | Could not connect |
158+
| 0x85 | SHT31_ERR_CRC_TEMP | CRC error in temperature |
159+
| 0x86 | SHT31_ERR_CRC_HUM | CRC error in humidity |
160+
| 0x87 | SHT31_ERR_CRC_STATUS | CRC error in status field |
161+
| 0x88 | SHT31_ERR_HEATER_COOLDOWN | Heater need to cool down |
162+
| 0x89 | SHT31_ERR_HEATER_ON | Could not switch on heater |
111163

112164

113-
#### Heater interface
165+
### Heater interface
114166

115167
**WARNING:** Do not use heater for long periods.
116168

@@ -121,22 +173,21 @@ within **180** seconds of the last switch off. Note: this guarding is not reboot
121173
**WARNING:** The user is responsible to switch the heater off manually!
122174

123175
The class does **NOT** do this automatically.
124-
Switch off the heater by directly calling **heatOff()** or indirectly by calling **isHeaterOn()**.
176+
Switch off the heater by explicitly calling **heatOff()** or indirectly by calling **isHeaterOn()**.
125177

126178
- **void setHeatTimeout(uint8_t seconds)** Set the time out of the heat cycle.
127179
This value is truncated to max 180 seconds.
128-
- **uint8_t getHeatTimeout
129-
- **bool heatOn()** switches heat cycle on if not already on.
130-
Returns false if fails, setting error to **SHT31_ERR_HEATER_COOLDOWN**
180+
- **uint8_t getHeatTimeout()** returns the value set.
181+
- **bool heatOn()** switches the heat cycle on if not already on.
182+
Returns false if the call fails, setting error to **SHT31_ERR_HEATER_COOLDOWN**
131183
or to **SHT31_ERR_HEATER_ON**.
132-
- **bool heatOff()** switches heat cycle off.
184+
- **bool heatOff()** switches the heat cycle off.
133185
Returns false if fails, setting error to **SHT31_ERR_HEATER_OFF**.
134-
- **bool isHeaterOn()** is the sensor still in heating cycle? replaces **heatUp()**.
135-
Will switch the heater off if max heating time has passed.
136-
- **bool heatUp()** will be obsolete in the future. replaced by **isHeaterOn()**
186+
- **bool isHeaterOn()** is the sensor still in a heating cycle? Replaces **heatUp()**.
187+
Will switch the heater off if maximum heating time has passed.
137188

138189

139-
#### Async interface
190+
### Async interface
140191

141192
See async example for usage
142193

@@ -160,7 +211,7 @@ Returns false if reading fails or in case of a CRC failure.
160211
| | | 1 | alert
161212
| 10 | Temperature tracking alert | 0 | no alert - default
162213
| | | 1 | alert
163-
| 9-5 | Reserved | 00000 |
214+
| 9-5 | Reserved | 00000 | reserved
164215
| 4 | System reset detected | 0 | no reset since last ‘clear status register’ command
165216
| | | 1 | reset detected (hard or soft reset command or supply fail) - default
166217
| 3-2 | Reserved | 00 |
@@ -169,17 +220,15 @@ Returns false if reading fails or in case of a CRC failure.
169220
| 0 | Write data checksum status | 0 | checksum of last write correct
170221
| | | 1 | checksum of last write transfer failed
171222

172-
173-
174-
## Operation
175-
176-
See examples.
223+
**bool clearStatus()** clears 15, 11, 10 and 4.
177224

178225

179226
## Future
180227

181228
#### Must
182229

230+
- improve documentation.
231+
- reorder interface
183232
- keep in sync with SHT85 library.
184233
- keep derived SHT31_SW builds green
185234

libraries/SHT31/SHT31.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: SHT31.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.5.0
4+
// VERSION: 0.5.1
55
// DATE: 2019-02-08
66
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
77
// https://www.adafruit.com/product/2857
@@ -77,10 +77,14 @@ bool SHT31::read(bool fast)
7777
}
7878

7979

80+
/////////////////////////////////////////////////////////////////
81+
//
82+
// STATUS
83+
//
8084
#ifdef doc
8185
// bit - description
8286
// ==================
83-
// 15 Alert pending status
87+
// 15 Alert pending status
8488
// '0': no pending alerts
8589
// '1': at least one pending alert - default
8690
// 14 Reserved ‘0’
@@ -132,6 +136,20 @@ uint16_t SHT31::readStatus()
132136
}
133137

134138

139+
// resets the following bits
140+
// 15 Alert pending status
141+
// 11 Humidity tracking alert
142+
// 10 Temp tracking alert
143+
// 4 System reset detected
144+
bool SHT31::clearStatus()
145+
{
146+
if (writeCmd(SHT31_CLEAR_STATUS) == false)
147+
{
148+
return false;
149+
}
150+
return true;
151+
}
152+
135153
bool SHT31::reset(bool hard)
136154
{
137155
bool b = writeCmd(hard ? SHT31_HARD_RESET : SHT31_SOFT_RESET);
@@ -151,6 +169,10 @@ void SHT31::setHeatTimeout(uint8_t seconds)
151169
}
152170

153171

172+
/////////////////////////////////////////////////////////////////
173+
//
174+
// HEATER
175+
//
154176
bool SHT31::heatOn()
155177
{
156178
if (isHeaterOn()) return true;
@@ -200,6 +222,10 @@ bool SHT31::isHeaterOn()
200222
}
201223

202224

225+
/////////////////////////////////////////////////////////////////
226+
//
227+
// ASYNC
228+
//
203229
bool SHT31::requestData()
204230
{
205231
if (writeCmd(SHT31_MEASUREMENT_SLOW) == false)
@@ -256,8 +282,10 @@ int SHT31::getError()
256282
}
257283

258284

259-
//////////////////////////////////////////////////////////
260-
285+
/////////////////////////////////////////////////////////////////
286+
//
287+
// PROTECTED
288+
//
261289
uint8_t SHT31::crc8(const uint8_t *data, uint8_t len)
262290
{
263291
// CRC-8 formula from page 14 of SHT spec pdf

libraries/SHT31/SHT31.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: SHT31.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.5.0
5+
// VERSION: 0.5.1
66
// DATE: 2019-02-08
77
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
88
// https://www.adafruit.com/product/2857
@@ -13,7 +13,7 @@
1313
#include "Wire.h"
1414

1515

16-
#define SHT31_LIB_VERSION (F("0.5.0"))
16+
#define SHT31_LIB_VERSION (F("0.5.1"))
1717

1818
#ifndef SHT_DEFAULT_ADDRESS
1919
#define SHT_DEFAULT_ADDRESS 0x44
@@ -57,6 +57,7 @@ class SHT31
5757

5858
// details see datasheet; summary in SHT31.cpp file
5959
uint16_t readStatus();
60+
bool clearStatus();
6061

6162
// lastRead is in milliSeconds since start
6263
uint32_t lastRead() { return _lastRead; };
@@ -71,16 +72,20 @@ class SHT31
7172
bool heatOn();
7273
bool heatOff();
7374
bool isHeaterOn(); // is the sensor still heating up?
74-
bool heatUp() { return isHeaterOn(); }; // will be obsolete in future
75+
// [[deprecated("Use isHeaterOn() instead")]]
76+
bool heatUp() { return isHeaterOn(); }; // will be obsolete
7577

78+
// 0..100%
7679
float getHumidity() { return _rawHumidity * (100.0 / 65535); };
80+
// getTemperature returns Celsius
7781
float getTemperature() { return _rawTemperature * (175.0 / 65535) - 45; };
7882
float getFahrenheit() { return _rawTemperature * (63.0 /13107.0) - 49; };
83+
// raw data e.g. debugging or efficient logging / transmit.
7984
uint16_t getRawHumidity() { return _rawHumidity; };
8085
uint16_t getRawTemperature() { return _rawTemperature; };
8186

8287

83-
// ASYNC INTERFACE
88+
// ASYNC INTERFACE
8489
bool requestData();
8590
bool dataReady();
8691
bool readData(bool fast = true);

0 commit comments

Comments
 (0)