Skip to content

Commit f7b35ea

Browse files
committed
0.4.0 CHT832X
1 parent 4a7508b commit f7b35ea

11 files changed

Lines changed: 86 additions & 50 deletions

File tree

libraries/CHT832X/.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
runs-on: ubuntu-latest
77
timeout-minutes: 5
88
steps:
9-
- uses: actions/checkout@v5
9+
- uses: actions/checkout@v6
1010
- uses: arduino/arduino-lint-action@v2
1111
with:
1212
library-manager: update

libraries/CHT832X/.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ jobs:
66
runTest:
77
runs-on: ubuntu-latest
88
timeout-minutes: 20
9-
109
steps:
11-
- uses: actions/checkout@v5
10+
- uses: actions/checkout@v6
1211
- uses: ruby/setup-ruby@v1
1312
with:
1413
ruby-version: 2.6

libraries/CHT832X/.github/workflows/jsoncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
timeout-minutes: 5
1515
steps:
16-
- uses: actions/checkout@v5
16+
- uses: actions/checkout@v6
1717
- name: json-syntax-check
1818
uses: limitusus/json-syntax-check@v2
1919
with:

libraries/CHT832X/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.4.0] - 2026-12-31
10+
- fix #9, CRC check humidity
11+
- make readDelay configurable (default 60).
12+
- update GitHub actions
13+
- minor edits
14+
15+
----
16+
917
## [0.3.1] - 2025-11-21
1018
- fix #7, update readme.md about **getNIST()**
1119
- add **CHT8320** and **CHT8325** as derived classes (convenience).

libraries/CHT832X/CHT832X.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: CHT832X.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.1
4+
// VERSION: 0.4.0
55
// DATE: 2024-12-29
66
// PURPOSE: Arduino library for CHT832X temperature and humidity sensor
77
// URL: https://github.com/RobTillaart/CHT832X
@@ -84,7 +84,7 @@ int CHT832X::requestData()
8484

8585
bool CHT832X::dataReady()
8686
{
87-
return ((millis() - _lastRequest) > CHT832X_READ_DELAY);
87+
return ((millis() - _lastRequest) > _readDelay);
8888
}
8989

9090

@@ -102,24 +102,24 @@ int CHT832X::readData()
102102
// TEMPERATURE PART
103103
_error = CHT832X_OK;
104104
const float Tfactor = 175.0f / 65535.0f;
105-
uint16_t tmp = (data[0] << 8 | data[1]);
106-
_temperature = -45 + Tfactor * tmp;
105+
uint16_t rawtmp = (data[0] << 8 | data[1]);
106+
_temperature = -45 + Tfactor * rawtmp;
107107
// Handle temperature offset.
108108
if (_tempOffset != 0.0f)
109109
{
110110
_temperature += _tempOffset;
111111
}
112112
// CHECK CRC TEMPERATURE
113-
if (_crc8(tmp) != data[2])
113+
if (_crc8(rawtmp) != data[2])
114114
{
115115
_error = CHT832X_ERROR_CRC;
116116
// fall through as value might be correct.
117117
}
118118

119119
// HUMIDITY PART
120120
const float Hfactor = 100.0f / 65535.0f;
121-
uint16_t tmp2 = (data[3] << 8 | data[4]);
122-
_humidity = Hfactor * tmp2;
121+
uint16_t rawhum = (data[3] << 8 | data[4]);
122+
_humidity = Hfactor * rawhum;
123123
if (_humOffset != 0.0f)
124124
{
125125
_humidity += _humOffset;
@@ -128,7 +128,7 @@ int CHT832X::readData()
128128
if (_humidity > 100.0f) _humidity = 100.0f;
129129
}
130130
// CHECK CRC HUMIDITY
131-
if (_crc8(tmp) != data[5])
131+
if (_crc8(rawhum) != data[5])
132132
{
133133
_error = CHT832X_ERROR_CRC;
134134
// fall through as value might be correct.
@@ -334,6 +334,16 @@ int CHT832X::getError()
334334
return e;
335335
}
336336

337+
void CHT832X::setReadDelay(uint8_t rdel)
338+
{
339+
_readDelay = rdel;
340+
}
341+
342+
uint8_t CHT832X::getReadDelay()
343+
{
344+
return _readDelay;
345+
}
346+
337347

338348
////////////////////////////////////////////////
339349
//

libraries/CHT832X/CHT832X.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: CHT832X.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.1
5+
// VERSION: 0.4.0
66
// DATE: 2024-12-29
77
// PURPOSE: Arduino library for CHT832X temperature and humidity sensor
88
// URL: https://github.com/RobTillaart/CHT832X
@@ -12,11 +12,7 @@
1212
#include "Wire.h"
1313

1414

15-
#define CHT832X_LIB_VERSION (F("0.3.1"))
16-
17-
// CONVERSION TIMING
18-
// To configure compile time, datasheet states 60 ms for conversion.
19-
const uint8_t CHT832X_READ_DELAY = 60;
15+
#define CHT832X_LIB_VERSION (F("0.4.0"))
2016

2117

2218
// DEFAULT ADDRESS
@@ -96,6 +92,13 @@ class CHT832X
9692
// ERROR
9793
int getError();
9894

95+
// READ DELAY CONVERSION TIME
96+
// datasheet states 60 ms for conversion. use with care.
97+
// allows to gain a few ms.
98+
void setReadDelay(uint8_t rdel = 60);
99+
uint8_t getReadDelay();
100+
101+
99102
protected:
100103
float _humOffset = 0.0f;
101104
float _tempOffset = 0.0f;
@@ -105,6 +108,7 @@ class CHT832X
105108
uint32_t _lastRequest = 0;
106109
uint32_t _heatStart = 0;
107110
int _error = CHT832X_OK;
111+
uint8_t _readDelay = 60;
108112

109113
TwoWire* _wire;
110114
uint8_t _address = CHT832X_DEFAULT_ADDRESS;

libraries/CHT832X/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) 2024-2025 Rob Tillaart
3+
Copyright (c) 2024-2026 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/CHT832X/README.md

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Arduino library for CHT832X temperature and humidity sensor.
1818

1919
**Experimental**
2020

21-
The CHT8320 and CHT8325 are temperature and relative humidity sensors.
21+
The CHT8320 and CHT8325 are temperature and relative humidity sensors.
2222
They both have the same interface, the CHT8325 is slightly more accurate.
23-
The CHT832X are factory calibrated and have an unique NIST number
23+
The CHT832X are factory calibrated and have an unique NIST number
2424
(48 bit) to be globally trackable.
2525

2626
This library implements the most important functionality of the sensor.
@@ -35,6 +35,11 @@ The library is tested to work with hardware, see issue 3.
3535
Feedback as always is welcome, please share your experiences.
3636

3737

38+
### Breaking change 0.4.0
39+
40+
Fixed CRC for humidity - see #9
41+
42+
3843
### Breaking change 0.3.0
3944

4045
Fixed temperature above 40 degrees Celsius - see #5
@@ -76,7 +81,7 @@ Always check datasheet for connections.
7681
Pull ups are needed on SDA, SCL.
7782

7883

79-
## I2C
84+
## I2C
8085

8186
### Performance
8287

@@ -90,18 +95,18 @@ TODO: fill table
9095

9196
| Version | Speed | Read | getManufacturer |
9297
|:---------:|:--------:|:--------:|:----------------:|
93-
| 0.3.0 | 50000 | | |
94-
| 0.3.0 | 100000 | | |
95-
| 0.3.0 | 200000 | | |
96-
| 0.3.0 | 300000 | | |
97-
| 0.3.0 | 400000 | | |
98-
| 0.3.0 | 600000 | | |
99-
| 0.3.0 | 800000 | | |
98+
| 0.4.0 | 50000 | | |
99+
| 0.4.0 | 100000 | | |
100+
| 0.4.0 | 200000 | | |
101+
| 0.4.0 | 300000 | | |
102+
| 0.4.0 | 400000 | | |
103+
| 0.4.0 | 600000 | | |
104+
| 0.4.0 | 800000 | | |
100105

101106

102107
### Addresses
103108

104-
The CHT8320 supports one fixed address, however one can order different
109+
The CHT8320 supports one fixed address, however one can order different
105110
versions with different addresses. Max 4 sensors per bus.
106111

107112
CHT8320-A-DNR .. CHT8320-D-DNR == 0x44 ..0x47
@@ -114,15 +119,15 @@ Pull ups are needed on SDA and SCL.
114119

115120
Sometimes you need to control more devices than possible with the default
116121
address range the device provides.
117-
This is possible with an I2C multiplexer e.g. TCA9548 which creates up
118-
to eight channels (think of it as I2C subnets) which can use the complete
119-
address range of the device.
122+
This is possible with an I2C multiplexer e.g. TCA9548 which creates up
123+
to eight channels (think of it as I2C subnets) which can use the complete
124+
address range of the device.
120125

121-
Drawback of using a multiplexer is that it takes more administration in
122-
your code e.g. which device is on which channel.
126+
Drawback of using a multiplexer is that it takes more administration in
127+
your code e.g. which device is on which channel.
123128
This will slow down the access, which must be taken into account when
124129
deciding which devices are on which channel.
125-
Also note that switching between channels will slow down other devices
130+
Also note that switching between channels will slow down other devices
126131
too if they are behind the multiplexer.
127132

128133
- https://github.com/RobTillaart/TCA9548
@@ -136,7 +141,7 @@ too if they are behind the multiplexer.
136141

137142
### Constructor
138143

139-
- **CHT832X(const uint8_t address = CHT832X_DEFAULT_ADDRESS, TwoWire \*wire = &Wire)** Constructor
144+
- **CHT832X(const uint8_t address = CHT832X_DEFAULT_ADDRESS, TwoWire \*wire = &Wire)** Constructor
140145
with default address (0x44) and I2C bus.
141146
- **int begin()** initializes internals.
142147
Returns error status.
@@ -179,17 +184,17 @@ Will return the same value until **read()** is called again.
179184

180185
### Offset
181186

182-
Adding offsets works well in the "normal range" but might introduce
187+
Adding offsets works well in the "normal range" but might introduce
183188
under- or overflow at the ends of the sensor range.
184189
These are not handled for temperature by the library, humidity is constrained.
185-
190+
186191
- **void setHumidityOffset(float offset)** idem.
187192
- **void setTemperatureOffset(float offset)** idem.
188193
This function can be used to set return temperature in Kelvin, with offset = 273.15
189194
- **float getHumidityOffset()** idem.
190195
- **float getTemperatureOffset()** idem.
191196

192-
If the offset is not the same over the operational range,
197+
If the offset is not the same over the operational range,
193198
consider a mapping function for temperature and/or humidity.
194199
e.g. https://github.com/RobTillaart/MultiMap
195200

@@ -201,8 +206,8 @@ Check datasheet for details.
201206
The heater can be used to remove condense from the sensor - think humidity.
202207
It is unclear how long the sensor may be heated. (feedback welcome).
203208

204-
The heater must be disabled when making measurements as the heating
205-
affects both the temperature and humidity.
209+
The heater must be disabled when making measurements as the heating
210+
affects both the temperature and humidity.
206211
Note it might take some time to stabilize to "environment temperature" again.
207212

208213
- **void enableHeater()** switch on.
@@ -226,7 +231,7 @@ Check datasheet for details.
226231
|:-----:|:----------------:|:--------------|
227232
| 13 | heater status | 0 = Heater disabled, 1 = heater enabled
228233
| 4 | reset detected | 0 = no reset, 1 reset since last clearStatus
229-
| 1 | command status | 0 = executed, 1 = not executed
234+
| 1 | command status | 0 = executed, 1 = not executed
230235
| 0 | checksum | 0 = pass, 1 = fail
231236
| other | reserved |
232237

@@ -240,14 +245,14 @@ Check datasheet for details.
240245

241246
### Meta data
242247

243-
In issue https://github.com/RobTillaart/CHT832X/issues/7 it is reported that
248+
In issue https://github.com/RobTillaart/CHT832X/issues/7 it is reported that
244249
the CHT8320 does not have an unique NIST identifier (any more).
245250
At the moment it is unknown if this is for one manufacturer or for all.
246251
Feedback on this topic is welcome.
247252

248253
In short, the getNIST() function is probably not usable to identify your product.
249254

250-
- **uint16_t getNIST(uint8_t id)** id = 0, 1, 2; returns 2 x 3 = 6 bytes of
255+
- **uint16_t getNIST(uint8_t id)** id = 0, 1, 2; returns 2 x 3 = 6 bytes of
251256
the device ID. As said above, not guaranteed unique.
252257
- **uint16_t getManufacturer()** Returns 0x5959 according to the datasheet.
253258
Other manufacturers may return different number.
@@ -269,16 +274,26 @@ Resets internal error to CHT832X_OK.
269274
| -21 | CHT832X_ERROR_CRC |
270275

271276

277+
## ReadDelay
278+
279+
The datasheet states 60 milliseonds is needed for conversion,
280+
but some devices might be just slightly faster.
281+
So this function allows to gain a few milliseconds.
282+
Use with care!
283+
284+
- **void setReadDelay(uint8_t rdel = 60)** set conversion delay.
285+
- **uint8_t getReadDelay()** returns set value.
286+
287+
272288
## Future
273289

274290
#### Must
275291

276292
- elaborate documentation.
277-
- test with hardware if all works.
293+
- buy and test with hardware if all works.
278294

279295
#### Should
280296

281-
- make read-delay of 60 ms configurable uint8_t (0.4.0 ?)
282297
- test heater functions.
283298
- test softwareReset().
284299
- operational modi

libraries/CHT832X/examples/CHT832X_verbose/CHT832X_verbose.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void setup()
3838
Serial.println("CHT832X initialization failed!");
3939
}
4040

41-
// Test isConnected() and print the result
41+
// Test isConnected() and print the result
4242
if (CHT.isConnected())
4343
{
4444
Serial.println("CHT832X is connected.");

libraries/CHT832X/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/CHT832X.git"
1717
},
18-
"version": "0.3.1",
18+
"version": "0.4.0",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

0 commit comments

Comments
 (0)