Skip to content

Commit 87bbbfd

Browse files
committed
0.3.1 SHT2x
1 parent 710c148 commit 87bbbfd

File tree

8 files changed

+196
-63
lines changed

8 files changed

+196
-63
lines changed

libraries/SHT2x/CHANGELOG.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ 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.3.1] - 2023-09-10
10+
- fix #21 example for elaborated async.
11+
- improve async interface
12+
- add **getRequestType()** to async interface
13+
- add three request constants to .h file
14+
- add **bool requestReady()** checks both.
15+
- update readme.md
16+
- minor edits
17+
18+
919
## [0.3.0] - 2023-03-26
1020
- fix setResolution #13, #18
1121
- fix heater settings
@@ -41,16 +51,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4151
- Fix getEIDB() bug.
4252

4353
## [0.1.3] - 2021-12-28
44-
- update library.json
54+
- update library.json
4555
- update license
4656
- minor edits
4757

48-
## [0.1.2] - 2021-09-29
58+
## [0.1.2] - 2021-09-29
4959
- Add Si70xx derived classes
5060
- add getEIDA(), getEIDB(), getFirmwareVersion()
5161
- update build-CI, readme.md badges
5262

53-
## [0.1.1] - 2021-09-28
63+
## [0.1.1] - 2021-09-28
5464
- Add HTU2x derived classes,
5565
- update readme.md + add some status info
5666

libraries/SHT2x/README.md

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

2-
[![Arduino CI](https://github.com/robtillaart/SHT2x/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3-
[![JSON check](https://github.com/RobTillaart/SHT2x/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SHT2x/actions/workflows/jsoncheck.yml)
2+
[![Arduino CI](https://github.com/RobTillaart/SHT2x/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
43
[![Arduino-lint](https://github.com/RobTillaart/SHT2x/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/SHT2x/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/SHT2x/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SHT2x/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/SHT2x.svg)](https://github.com/RobTillaart/SHT2x/issues)
6+
57
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SHT2x/blob/master/LICENSE)
68
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SHT2x.svg?maxAge=3600)](https://github.com/RobTillaart/SHT2x/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/SHT2x.svg)](https://registry.platformio.org/libraries/robtillaart/SHT2x)
710

811

912
# SHT2x
@@ -39,6 +42,13 @@ If you want to use more on one I2C bus one needs either an I2C multiplexer
3942
or one should switch sensors on/off like the select in SPI communication.
4043

4144

45+
#### Related
46+
47+
- https://github.com/RobTillaart/SHT31
48+
- https://github.com/RobTillaart/SHT85
49+
- https://github.com/RobTillaart/tinySHT2x
50+
51+
4252
## Interface
4353

4454
```cpp
@@ -89,13 +99,24 @@ Note: The raw temperature and raw humidity are ideal to minimize storage or to m
8999
Experimental since 0.2.2 this interface can change in the future
90100
Discussion see https://github.com/RobTillaart/SHT2x/issues/16
91101

92-
- **bool requestTemperature()**
93-
- **bool requestHumidity()**
94-
- **bool reqTempReady()**
95-
- **bool reqHumReady()**
96-
- **bool readTemperature()**
97-
- **bool readHumidity()**
98-
- **uint32_t lastRequest()**
102+
- **bool requestTemperature()** starts new temperature request.
103+
Overrules optional existing / running request.
104+
- **bool requestHumidity()** starts new humidity request.
105+
Overrules optional existing / running request.
106+
- **bool reqTempReady()** returns true if temperature request is ready.
107+
- **bool reqHumReady()** returns true if humidity request is ready.
108+
- **bool requestReady()** checks if either temperature or humidity is ready.
109+
- **bool readTemperature()** calculates the temperature from raw measurement.
110+
- **bool readHumidity()** calculates the humidity from raw measurement.
111+
- **uint32_t lastRequest()** timestamp of last request.
112+
- **uint8_t getRequestType()** get current request type.
113+
114+
115+
| Value | Symbolic | Description | Notes |
116+
|:-------:|:----------------------------|:------------------------------|:-----------|
117+
| 0x00 | SHT2x_REQ_NONE | no request pending | |
118+
| 0x01 | SHT2x_REQ_TEMPERATURE | temperature request pending | |
119+
| 0x02 | SHT2x_REQ_HUMIDITY | humidity request pending | |
99120

100121
TODO elaborate documentation.
101122

@@ -157,28 +178,28 @@ To be tested.
157178

158179
#### Status fields
159180

160-
From HTU20 datasheet
181+
From HTU20 datasheet (read for details).
161182

162-
| bits | value | meaning |
163-
|:------:|:------:|:--------------------|
164-
| 00 | 0 | open circuit |
165-
| 01 | 1 | temperature reading |
166-
| 10 | 2 | humidity reading |
167-
| 11 | 3 | closed circuit |
183+
| bits | value | Symbolic | Description |
184+
|:------:|:-------:|:------------------------------|:----------------------|
185+
| 00 | 0 | SHT2x_STATUS_OPEN_CIRCUIT | open circuit |
186+
| 01 | 1 | SHT2x_STATUS_TEMPERATURE | temperature reading |
187+
| 10 | 2 | SHT2x_STATUS_HUMIDITY | humidity reading |
188+
| 11 | 3 | SHT2x_STATUS_CLOSED_CIRCUIT | closed circuit |
168189

169190

170191
#### Resolution
171192

172193
**Warning experimental**
173-
- needs more testing as results are not in line with the datasheet.
194+
- needs more testing as the results are not in line with the datasheet.
174195
- only tested on a HTUxx sensor.
175196
- tested with **SHT2X_resolution.ino**
176197

177198
- **void setResolution(uint8_t res)** res = 0..3, other values return false.
178199
- **uint8_t getResolution()** returns resolution set 0..3.
179200

180201

181-
Datasheet SHT20 Table 8: (resolution)
202+
Datasheet SHT20 Table 8: resolution
182203

183204
| RES | Humidity | Temperature |
184205
|:-----:|:----------:|:-------------:|
@@ -187,7 +208,8 @@ Datasheet SHT20 Table 8: (resolution)
187208
| 2 | 10 bit | 13 bit |
188209
| 3 | 11 bit | 11 bit |
189210

190-
Datasheet SHT20 Table 7: (timing) and results of real measurements.
211+
212+
Datasheet SHT20 Table 7: timing versus results of real measurements.
191213
( https://github.com/RobTillaart/SHT2x/pull/11 )
192214

193215
| RES | HUM | TEMP | TOTAL | REAL |
@@ -209,44 +231,45 @@ Timing in milliseconds.
209231
## Future
210232

211233
#### Must
234+
212235
- improve documentation
213236
- reorganize interface
237+
- async documentation
214238
- clean up code.
215239

216-
217240
#### 0.4.0
241+
218242
- add crc8 check (need sensor to test)
219243
- improve error handling (all code paths)
220244
- investigate blocking delay() in read
221245
- add offset for temperature and humidity
222246

223-
224-
#### ASYNC 0.4.0
225-
improvements for interface.
226-
227-
- **bool requestReady()** checks both.
228-
- **bool requestPending()** checks.
229-
- **uint8_t getRequestType()** returns 0, 1, 2.
230-
- async documentation
231-
232-
233247
#### Should
248+
234249
- test test test
235250
- get hardware
236251
- add examples
237252
- test resolutions
238253
- performance different resolutions
239254
- test battery
240255

241-
242256
#### Could
257+
243258
- fix TODO in code (.cpp and .h) and documentation
244259
- update unit tests
245260
- add type info in derived classes?
246261

247-
248262
#### Wont
249263

250264
- add **getSerialNumber()**
251265
**getEIDA()** and **getEIDB()** covers this
252266

267+
268+
## Support
269+
270+
If you appreciate my libraries, you can support the development and maintenance.
271+
Improve the quality of the libraries by providing issues and Pull Requests, or
272+
donate through PayPal or GitHub sponsors.
273+
274+
Thank you,
275+

libraries/SHT2x/SHT2x.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: SHT2x.cpp
33
// AUTHOR: Rob Tillaart, Viktor Balint
4-
// VERSION: 0.3.0
4+
// VERSION: 0.3.1
55
// DATE: 2021-09-25
66
// PURPOSE: Arduino library for the SHT2x temperature and humidity sensor
77
// URL: https://github.com/RobTillaart/SHT2x
@@ -26,10 +26,6 @@
2626
#define SHT2x_USRREG_BATTERY 0x20
2727
#define SHT2x_USRREG_HEATER 0x04
2828

29-
#define SHT2x_REQ_NONE 0x00
30-
#define SHT2x_REQ_TEMPERATURE 0x01
31-
#define SHT2x_REQ_HUMIDITY 0x02
32-
3329

3430
//////////////////////////////////////////////////////////////
3531
//
@@ -39,7 +35,7 @@ SHT2x::SHT2x()
3935
{
4036
_lastRead = 0;
4137
_lastRequest = 0;
42-
_requestType = 0;
38+
_requestType = SHT2x_REQ_NONE;
4339
_rawTemperature = 0;
4440
_rawHumidity = 0;
4541
_heatTimeout = 0;
@@ -165,6 +161,11 @@ bool SHT2x::reqHumReady()
165161
}
166162

167163

164+
bool SHT2x::requestReady()
165+
{
166+
return (reqTempReady() || reqHumReady());
167+
}
168+
168169
bool SHT2x::readTemperature()
169170
{
170171
uint8_t buffer[3];
@@ -177,7 +178,7 @@ bool SHT2x::readTemperature()
177178
if (crc8(buffer, 2) != buffer[2])
178179
{
179180
_error = SHT2x_ERR_CRC_TEMP;
180-
// return false; // do not fail yet
181+
// return false; // do not fail yet
181182
}
182183
_rawTemperature = buffer[0] << 8;
183184
_rawTemperature += buffer[1];
@@ -187,7 +188,7 @@ bool SHT2x::readTemperature()
187188
_requestType = SHT2x_REQ_NONE;
188189

189190
_status = buffer[1] & 0x0003;
190-
if (_status == 0xFF) // TODO != 0x01 (need HW to test)
191+
if (_status == 0xFF) // TODO != 0x01 (need HW to test)
191192
{
192193
_error = SHT2x_ERR_READBYTES;
193194
return false;
@@ -207,7 +208,7 @@ bool SHT2x::readHumidity()
207208
if (crc8(buffer, 2) != buffer[2])
208209
{
209210
_error = SHT2x_ERR_CRC_HUM;
210-
// return false; // do not fail yet
211+
// return false; // do not fail yet
211212
}
212213
_rawHumidity = buffer[0] << 8;
213214
_rawHumidity += buffer[1];
@@ -235,20 +236,26 @@ uint32_t SHT2x::lastRequest()
235236
}
236237

237238

239+
uint8_t SHT2x::getRequestType()
240+
{
241+
return _requestType;
242+
}
243+
244+
238245
/////////////////////////////////////////////////////////
239246
//
240247
// TEMPERATURE AND HUMIDTY
241248
//
242249
float SHT2x::getTemperature()
243250
{
244-
// par 6.2
251+
// par 6.2
245252
return -46.85 + (175.72 / 65536.0) * _rawTemperature;
246253
}
247254

248255

249256
float SHT2x::getHumidity()
250257
{
251-
// par 6.1
258+
// par 6.1
252259
return -6.0 + (125.0 / 65536.0) * _rawHumidity;
253260
}
254261

@@ -347,7 +354,7 @@ bool SHT2x::heatOff()
347354

348355
if (writeCmd(SHT2x_WRITE_USER_REGISTER, userReg) == false)
349356
{
350-
_error = SHT2x_ERR_HEATER_OFF; // can be serious!
357+
_error = SHT2x_ERR_HEATER_OFF; // can be serious!
351358
return false;
352359
}
353360
_heaterStop = millis();
@@ -362,7 +369,7 @@ bool SHT2x::isHeaterOn()
362369
{
363370
return false;
364371
}
365-
// did not exceed time out
372+
// did not exceed time out
366373
if (millis() - _heaterStart < (_heatTimeout * 1000UL))
367374
{
368375
return true;
@@ -380,7 +387,7 @@ bool SHT2x::setHeaterLevel(uint8_t level)
380387
}
381388

382389
uint8_t heaterReg = 0;
383-
writeCmd(0x11); // Read Heater Control Register
390+
writeCmd(0x11); // Read Heater Control Register
384391
if (readBytes(1, (uint8_t *) &heaterReg, 5) == false)
385392
{
386393
_error = SHT2x_ERR_READBYTES;
@@ -400,7 +407,7 @@ bool SHT2x::setHeaterLevel(uint8_t level)
400407
bool SHT2x::getHeaterLevel(uint8_t & level)
401408
{
402409
uint8_t heaterReg = 0;
403-
writeCmd(0x11); // Read Heater Control Register
410+
writeCmd(0x11); // Read Heater Control Register
404411
if (readBytes(1, (uint8_t *) &heaterReg, 5) == false)
405412
{
406413
_error = SHT2x_ERR_READBYTES;
@@ -541,8 +548,8 @@ bool SHT2x::batteryOK()
541548
//
542549
uint8_t SHT2x::crc8(const uint8_t *data, uint8_t len)
543550
{
544-
// CRC-8 formula from page 14 of SHT spec pdf
545-
// Sensirion_Humidity_Sensors_SHT2x_CRC_Calculation.pdf
551+
// CRC-8 formula from page 14 of SHT spec pdf
552+
// Sensirion_Humidity_Sensors_SHT2x_CRC_Calculation.pdf
546553
const uint8_t POLY = 0x31;
547554
uint8_t crc = 0x00;
548555

0 commit comments

Comments
 (0)