Arduino library for CHT8305 temperature and humidity sensor.
EXPERIMENTAL minimal tested.
If you are able to test this library, please let me know your experiences.
The CHT8305 is a temperature and humidity sensor.
sensor | range | accuracy* | resolution |
---|---|---|---|
temperature | -40°..125° | max 2°C | 0.1° C |
humidity | 0%..100% RH | max 5% RH | 0.1% RH |
* Accuracy for full range. More exact details for smaller ranges, see datasheet (page 8).
One of the interesting functions is the support of an ALERT function. This prevents the need for continuous polling of the sensor.
Version 0.2.0 introduced a breaking change. You cannot set the pins in begin() any more. This reduces the dependency of processor dependent Wire implementations. The user has to call Wire.begin() and can optionally set the Wire pins before calling begin().
Moved the address parameter from begin() to constructor.
The ALERT functions are not tested. The reason is that the sensor I have does not expose the ALERT pin.
If you are able to test the ALERT functions, please let me know your experiences.
Always check datasheet for connections.
//
// +---------------+
// VCC ----| VCC |
// SDA ----| SDA CHT8305 |
// GND ----| GND |
// SCL ----| SCL |
// ? ----| AD0 | ? depends on address see table below.
// | |
// IRQ ----| ALERT | only if enabled.
// +---------------+
//
// check datasheet
// VCC RED
// GND BLACK
// SDA YELLOW
// SCL WHITE
Pull ups are needed on SDA, SCL and optional to ALERT.
The CHT8305 has an ALERT logic output pin with an open drain structure. This output is active low. (if the breakout supports this.)
I2C bus speeds is supported up to 400 KHz.
AD0 | Address | Notes |
---|---|---|
GND | 0x40 | CHT8305_DEFAULT_ADDRESS |
VCC | 0x41 | |
SDA | 0x42 | |
SCL | 0x43 |
Pull ups are needed on SDA, SCL and optional to ALERT.
Sometimes you need to control more devices than possible with the default address range the device provides. This is possible with an I2C multiplexer e.g. TCA9548 which creates up to eight channels (think of it as I2C subnets) which can use the complete address range of the device.
Drawback of using a multiplexer is that it takes more administration in your code e.g. which device is on which channel. This will slow down the access, which must be taken into account when deciding which devices are on which channel. Also note that switching between channels will slow down other devices too if they are behind the multiplexer.
#include "CHT8305.h"
Note: read(), readTemperature() and readHumidity() blocks each other, so you can call only one of them every second.
Adding offsets works well in the "normal range" but might introduce under- or overflow at the ends of the sensor range. These are not handled for temperature by the library (humidity since 0.1.7).
If the offset is not the same over the operational range, consider a mapping function for temperature and humidity. e.g. https://github.com/RobTillaart/MultiMap
Check the datasheet for details of the register bits.
bit | mask | name | description |
---|---|---|---|
15 | 0x8000 | soft reset | 1 = reboot the sensor to default |
14 | 0x4000 | clock stretch | 1 = ON, 0 = OFF (default) |
13 | 0x2000 | heater | 1 = ON, 0 = OFF (default) |
12 | 0x1000 | mode | 1 = read both (default), 0 = read T or RH |
11 | 0x0800 | vccs | 1 = >2.8V, 0 = <2.8V |
10 | 0x0400 | T-RES | 1 = 11 bit, 0 = 14 bit (default) |
9-8 | 0x0300 | H-RES | 10 = 8 bit, 01 = 11 bit, 00 = 14 bit (default) |
7-6 | 0x00C0 | ALTM | Alert Mode (datasheet) |
5 | 0x0020 | APS | Alert pending status |
4 | 0x0010 | H-ALT | Humidity Alert status |
3 | 0x0008 | T-ALT | Temperature Alert status |
2 | 0x0004 | VCC enable | 1 = enable VCC measurement (default), 0 = disable |
1-0 | 0x0003 | reserved. | do not change. |
Note: setting setConfigRegister(bitmask) can be faster.
Wrapper functions for easy configuration.
See register 3 datasheet page 12 for details.
mode | trigger | notes |
---|---|---|
0 | T or H | default |
1 | T | |
2 | H | |
3 | T and H |
The ALERT pin triggers with a falling edge (from HIGH to LOW).
VCC measurement should be enabled by means of void setVCCenable(true) or by setConfigRegister(0x0004).
Best guess for now: 16 bit data implies voltage = 5.0V * value / 32768.0;
Varied slightly 5.000 - 4.999 also for 3V3 power supply.
Conclusion: it is unclear how to interpret this register.
See datasheet page 10 for details
Address | Register name |
---|---|
0x00 | CHT8305_REG_TEMPERATURE |
0x01 | CHT8305_REG_HUMIDITY |
0x02 | CHT8305_REG_CONFIG |
0x03 | CHT8305_REG_ALERT |
0x04 | CHT8305_REG_VOLTAGE |
0xFE | CHT8305_REG_MANUFACTURER |
0xFF | CHT8305_REG_VERSION |
If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.
Thank you,