Skip to content

Commit 302b12e

Browse files
committed
0.3.0 SHT2x
1 parent cdd3ab2 commit 302b12e

File tree

11 files changed

+196
-91
lines changed

11 files changed

+196
-91
lines changed

libraries/SHT2x/.github/workflows/arduino-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010
- uses: arduino/arduino-lint-action@v1
1111
with:
1212
library-manager: update

libraries/SHT2x/.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

libraries/SHT2x/.github/workflows/jsoncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
- name: json-syntax-check
1515
uses: limitusus/json-syntax-check@v1
1616
with:

libraries/SHT2x/CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ 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.0] - 2023-03-26
10+
- fix setResolution #13, #18
11+
- fix heater settings
12+
- add GY21 as derived class
13+
- fix derived constructors
14+
- move code from .h to .cpp
15+
- update readme.md
16+
- update GitHub actions
17+
- update license 2023
18+
- minor edits
19+
20+
----
21+
922
## [0.2.2] - 2022-12-14
1023
- add experimental asynchronous interface
1124
- add async example
1225

13-
1426
## [0.2.1] - 2022-11-24
1527
- Add RP2040 support to build-CI.
1628
- Add CHANGELOG.md

libraries/SHT2x/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) 2021-2022 Rob Tillaart
3+
Copyright (c) 2021-2023 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/SHT2x/README.md

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ Furthermore there are a number of compatible sensors, these are not tested eithe
2121

2222
Accuracy table
2323

24-
| Sensor | Temperature | Humidity | Notes |
25-
|:-------:|:-----------:|:--------:|:-------|
26-
| SHT20 | ~0.3 | ±3.0 | |
27-
| SHT21 | ~0.3 | ±3.0 | |
28-
| SHT25 | ~0.3 | ±1.8 | |
29-
| HTU20 | | | to-do |
30-
| HTU21 | | | to-do |
31-
| Si7013 | | | to-do |
32-
| Si7020 | | | to-do |
33-
| Si7021 | | | to-do |
24+
| Sensor | Temperature | Humidity | Notes |
25+
|:---------:|:-----------:|:--------:|:--------|
26+
| SHT20 | ~0.3 | ±3.0 | |
27+
| SHT21 | ~0.3 | ±3.0 | |
28+
| SHT25 | ~0.3 | ±1.8 | |
29+
| HTU20 | | | to-do |
30+
| HTU21 | | | to-do |
31+
| Si7013 | | | to-do |
32+
| Si7020 | | | to-do |
33+
| Si7021 | | | to-do |
34+
| GY21 | | | to-do |
3435

3536

3637
All sensors in this family of sensors have address 0x40 (64 decimal).
@@ -40,6 +41,10 @@ or one should switch sensors on/off like the select in SPI communication.
4041

4142
## Interface
4243

44+
```cpp
45+
#include "SHT2x.h"
46+
```
47+
4348
#### Constructors
4449

4550
All classes below are derived from SHT2x class.
@@ -100,18 +105,18 @@ TODO elaborate documentation.
100105
- **int getError()** returns last set error flag and clear it.
101106
Be sure to clear the error flag by calling **getError()** before calling any command as the error flag could be from a previous command.
102107

103-
| Value | Symbolic | Description | Notes |
104-
|:------:|:--------------------------|:----------------------------|:---------|
105-
| 0x00 | SHT2x_OK | no error | |
106-
| 0x81 | SHT2x_ERR_WRITECMD | I2C write failed | |
107-
| 0x82 | SHT2x_ERR_READBYTES | I2C read failed | |
108-
| 0x83 | SHT2x_ERR_HEATER_OFF | Could not switch off heater | |
109-
| 0x84 | SHT2x_ERR_NOT_CONNECT | Could not connect | |
110-
| 0x85 | SHT2x_ERR_CRC_TEMP | CRC error in temperature | |
111-
| 0x86 | SHT2x_ERR_CRC_HUM | CRC error in humidity | |
112-
| 0x87 | SHT2x_ERR_CRC_STATUS | CRC error in status field | not used |
113-
| 0x88 | SHT2x_ERR_HEATER_COOLDOWN | Heater need to cool down | |
114-
| 0x88 | SHT2x_ERR_HEATER_ON | Could not switch on heater | |
108+
| Value | Symbolic | Description | Notes |
109+
|:-------:|:----------------------------|:------------------------------|:-----------|
110+
| 0x00 | SHT2x_OK | no error | |
111+
| 0x81 | SHT2x_ERR_WRITECMD | I2C write failed | |
112+
| 0x82 | SHT2x_ERR_READBYTES | I2C read failed | |
113+
| 0x83 | SHT2x_ERR_HEATER_OFF | Could not switch off heater | |
114+
| 0x84 | SHT2x_ERR_NOT_CONNECT | Could not connect | |
115+
| 0x85 | SHT2x_ERR_CRC_TEMP | CRC error in temperature | |
116+
| 0x86 | SHT2x_ERR_CRC_HUM | CRC error in humidity | |
117+
| 0x87 | SHT2x_ERR_CRC_STATUS | CRC error in status field | not used |
118+
| 0x88 | SHT2x_ERR_HEATER_COOLDOWN | Heater need to cool down | |
119+
| 0x88 | SHT2x_ERR_HEATER_ON | Could not switch on heater | |
115120

116121
Note: the HTU20 / HTU21 classes share the same error codes.
117122

@@ -175,12 +180,12 @@ From HTU20 datasheet
175180

176181
Datasheet SHT20 Table 8: (resolution)
177182

178-
| RES | Humidity | Temperature |
179-
|:-----:|:---------:|:-----------:|
180-
| 0 | 12 bit | 14 bit |
181-
| 1 | 08 bit | 12 bit |
182-
| 2 | 10 bit | 13 bit |
183-
| 3 | 11 bit | 11 bit |
183+
| RES | Humidity | Temperature |
184+
|:-----:|:----------:|:-------------:|
185+
| 0 | 12 bit | 14 bit |
186+
| 1 | 08 bit | 12 bit |
187+
| 2 | 10 bit | 13 bit |
188+
| 3 | 11 bit | 11 bit |
184189

185190
Datasheet SHT20 Table 7: (timing) and results of real measurements.
186191
( https://github.com/RobTillaart/SHT2x/pull/11 )
@@ -205,25 +210,24 @@ Timing in milliseconds.
205210

206211
#### Must
207212
- improve documentation
213+
- reorganize interface
208214
- clean up code.
209215

210216

211-
#### 0.3.0
212-
- add crc8 check (need sensor)
217+
#### 0.4.0
218+
- add crc8 check (need sensor to test)
213219
- improve error handling (all code paths)
214220
- investigate blocking delay() in read
215221
- add offset for temperature and humidity
216-
- move code from .h to .cpp
217-
- add GY21 as derived class name
218222

219223

220-
#### ASYNC 0.3.0
224+
#### ASYNC 0.4.0
221225
improvements for interface.
222226

223-
- **bool requestReady()** checks both.
224-
- **bool requestPending()** checks .
225-
- **uint8_t getRequestType()** returns 0, 1, 2
226-
- documentation
227+
- **bool requestReady()** checks both.
228+
- **bool requestPending()** checks.
229+
- **uint8_t getRequestType()** returns 0, 1, 2.
230+
- async documentation
227231

228232

229233
#### Should
@@ -236,9 +240,9 @@ improvements for interface.
236240

237241

238242
#### Could
239-
- investigate resolution anomalies
240243
- fix TODO in code (.cpp and .h) and documentation
241244
- update unit tests
245+
- add type info in derived classes?
242246

243247

244248
#### Wont

libraries/SHT2x/SHT2x.cpp

Lines changed: 55 additions & 23 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.2.2
4+
// VERSION: 0.3.0
55
// DATE: 2021-09-25
66
// PURPOSE: Arduino library for the SHT2x temperature and humidity sensor
77
// URL: https://github.com/RobTillaart/SHT2x
@@ -253,6 +253,18 @@ float SHT2x::getHumidity()
253253
}
254254

255255

256+
uint16_t SHT2x::getRawTemperature()
257+
{
258+
return _rawTemperature;
259+
}
260+
261+
262+
uint16_t SHT2x::getRawHumidity()
263+
{
264+
return _rawHumidity;
265+
}
266+
267+
256268
bool SHT2x::reset()
257269
{
258270
bool b = writeCmd(SHT2x_SOFT_RESET);
@@ -265,6 +277,13 @@ uint8_t SHT2x::getStatus()
265277
return _status;
266278
}
267279

280+
281+
uint32_t SHT2x::lastRead()
282+
{
283+
return _lastRead;
284+
}
285+
286+
268287
/////////////////////////////////////////////////////////
269288
//
270289
// HEATER
@@ -276,6 +295,12 @@ void SHT2x::setHeatTimeout(uint8_t seconds)
276295
}
277296

278297

298+
uint8_t SHT2x::getHeatTimeout()
299+
{
300+
return _heatTimeout;
301+
}
302+
303+
279304
bool SHT2x::heatOn()
280305
{
281306
if (isHeaterOn()) return true;
@@ -296,7 +321,7 @@ bool SHT2x::heatOn()
296321
// HEAT BIT ON
297322
userReg |= SHT2x_USRREG_HEATER;
298323

299-
if (writeCmd(SHT2x_READ_USER_REGISTER, userReg) == false)
324+
if (writeCmd(SHT2x_WRITE_USER_REGISTER, userReg) == false)
300325
{
301326
_error = SHT2x_ERR_HEATER_ON;
302327
return false;
@@ -320,7 +345,7 @@ bool SHT2x::heatOff()
320345
// HEAT BIT OFF
321346
userReg &= ~SHT2x_USRREG_HEATER;
322347

323-
if (writeCmd(SHT2x_READ_USER_REGISTER, userReg) == false)
348+
if (writeCmd(SHT2x_WRITE_USER_REGISTER, userReg) == false)
324349
{
325350
_error = SHT2x_ERR_HEATER_OFF; // can be serious!
326351
return false;
@@ -477,7 +502,7 @@ bool SHT2x::setResolution(uint8_t res)
477502
userReg |= ((res & 0x02) << 6);
478503
userReg |= (res & 0x01);
479504

480-
if (writeCmd(SHT2x_READ_USER_REGISTER, userReg) == false)
505+
if (writeCmd(SHT2x_WRITE_USER_REGISTER, userReg) == false)
481506
{
482507
_error = SHT2x_ERR_RESOLUTION;
483508
return false;
@@ -510,8 +535,6 @@ bool SHT2x::batteryOK()
510535
}
511536

512537

513-
514-
515538
//////////////////////////////////////////////////////////
516539
//
517540
// PROTECTED
@@ -590,53 +613,62 @@ bool SHT2x::readBytes(uint8_t n, uint8_t *val, uint8_t maxDuration)
590613
//
591614
// DERIVED SHT
592615
//
593-
SHT20::SHT20()
616+
SHT20::SHT20() : SHT2x()
594617
{
595-
};
618+
}
596619

597620

598-
SHT21::SHT21()
621+
SHT21::SHT21() : SHT2x()
599622
{
600-
};
623+
}
601624

602625

603-
SHT25::SHT25()
626+
SHT25::SHT25() : SHT2x()
604627
{
605-
};
628+
}
606629

607630

608631
////////////////////////////////////////////////////////
609632
//
610633
// DERIVED HTU
611634
//
612-
HTU20::HTU20()
635+
HTU20::HTU20() : SHT2x()
613636
{
614-
};
637+
}
615638

616639

617-
HTU21::HTU21()
640+
HTU21::HTU21() : SHT2x()
618641
{
619-
};
642+
}
620643

621644

622645
////////////////////////////////////////////////////////
623646
//
624647
// DERIVED Si70xx
625648
//
626-
Si7013::Si7013()
649+
Si7013::Si7013() : SHT2x()
627650
{
628-
};
651+
}
629652

630653

631-
Si7020::Si7020()
654+
Si7020::Si7020() : SHT2x()
632655
{
633-
};
656+
}
634657

635658

636-
Si7021::Si7021()
659+
Si7021::Si7021() : SHT2x()
637660
{
638-
};
661+
}
662+
663+
664+
////////////////////////////////////////////////////////
665+
//
666+
// DERIVED Si70xx
667+
//
668+
GY21::GY21() : SHT2x()
669+
{
670+
}
639671

640672

673+
// -- END OF FILE --
641674

642-
// -- END OF FILE --

0 commit comments

Comments
 (0)