GY-63_MS5611/libraries/SHT2x/README.md

249 lines
8.7 KiB
Markdown
Raw Normal View History

2021-09-27 14:51:23 -04:00
[![Arduino CI](https://github.com/robtillaart/SHT2x/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![JSON check](https://github.com/RobTillaart/SHT2x/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SHT2x/actions/workflows/jsoncheck.yml)
[![Arduino-lint](https://github.com/RobTillaart/SHT2x/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/SHT2x/actions/workflows/arduino-lint.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SHT2x/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SHT2x.svg?maxAge=3600)](https://github.com/RobTillaart/SHT2x/releases)
# SHT2x
2021-11-17 12:59:50 -05:00
Arduino library for the SHT2x, HTU2x and Si70xx temperature and humidity sensors.
2021-09-27 14:51:23 -04:00
## Description
2021-11-17 12:59:50 -05:00
This library is not tested extensively yet.
It should work for SHT20, SHT21 and SHT25 but these are not tested yet.
2021-09-27 14:51:23 -04:00
The SHT2x family of sensors should work up to 400 KHz I2C.
2021-11-17 12:59:50 -05:00
Furthermore there are a number of compatible sensors, these are not tested either.
2021-12-28 06:13:24 -05:00
Accuracy table
| Sensor | Temperature | Humidity | Notes |
|:-------:|:-----------:|:--------:|:-------|
| SHT20 | ~0.3 | <20>3.0 | |
| SHT21 | ~0.3 | <20>3.0 | |
| SHT25 | ~0.3 | <20>1.8 | |
| HTU20 | | | to-do |
| HTU21 | | | to-do |
| Si7013 | | | to-do |
| Si7020 | | | to-do |
| Si7021 | | | to-do |
2021-09-27 14:51:23 -04:00
All sensors in this family of sensors have address 0x40 (64 decimal).
2021-11-17 12:59:50 -05:00
If you want to use more on one I2C bus one needs either an I2C multiplexer
or one should switch sensors on/off like the select in SPI communication.
2021-09-27 14:51:23 -04:00
## Interface
2022-12-18 04:41:37 -05:00
#### Constructors
2021-09-29 07:21:17 -04:00
All classes below are derived from SHT2x class.
2021-09-27 14:51:23 -04:00
2021-09-29 07:21:17 -04:00
- **SHT2x()** constructor base class.
2021-09-27 14:51:23 -04:00
- **SHT20()** constructor.
- **SHT21()** constructor.
- **SHT25()** constructor.
2021-09-29 07:21:17 -04:00
- **HTU20()** constructor.
- **HTU21()** constructor.
2021-11-17 12:59:50 -05:00
- **Si7013()** constructor.
- **Si7020()** constructor.
- **Si7021()** constructor.
2021-09-29 07:21:17 -04:00
2022-12-18 04:41:37 -05:00
#### Base interface
2021-09-29 07:21:17 -04:00
2022-06-23 09:15:32 -04:00
- **bool begin(int dataPin, int clockPin)** begin function for ESP8266 & ESP32;
2021-09-27 14:51:23 -04:00
returns false if device address is incorrect or device cannot be reset.
2021-11-17 12:59:50 -05:00
- **bool begin(TwoWire \*wire = &Wire)** optional set the wire interface
for platforms with multiple I2C buses. **begin()** calls **reset()** which can take up to 15 ms.
2021-09-27 14:51:23 -04:00
- **bool read()** Reads both the temperature and humidity.
Initial release has a blocking delay.
- **bool isConnected()** check if sensor is reachable over I2C. Returns false if not connected.
2022-07-13 09:46:33 -04:00
- **uint16_t getStatus()** returns a 2 bit status. See Status fields below.
2021-09-27 14:51:23 -04:00
- **uint32_t lastRead()** in milliSeconds since start of program.
- **bool reset()** resets the sensor, soft reset, no hard reset supported.
- **float getHumidity()** computes the relative humidity in % based off the latest raw reading, and returns it.
- **float getTemperature()** computes the temperature in <20>C based off the latest raw reading, and returns it.
- **uint16_t getRawHumidity()** returns the raw two-byte representation of humidity directly from the sensor.
- **uint16_t getRawTemperature()** returns the raw two-byte representation of temperature directly from the sensor.
Note that the temperature and humidity values are recalculated on every call to getHumidity() and getTemperature().
If you're worried about the extra cycles, you should make sure to cache these values or only request them
after you've performed a new **read()**.
2022-07-13 09:46:33 -04:00
Note: The raw temperature and raw humidity are ideal to minimize storage or to minimize communication.
2021-09-27 14:51:23 -04:00
2022-12-18 04:41:37 -05:00
#### Asynchronous interface
Experimental since 0.2.2 this interface can change in the future
Discussion see https://github.com/RobTillaart/SHT2x/issues/16
- **bool requestTemperature()**
- **bool requestHumidity()**
- **bool reqTempReady()**
- **bool reqHumReady()**
- **bool readTemperature()**
- **bool readHumidity()**
- **uint32_t lastRequest()**
TODO elaborate documentation.
#### Error interface
2021-09-27 14:51:23 -04:00
- **int getError()** returns last set error flag and clear it.
Be sure to clear the error flag by calling **getError()** before calling any command as the error flag could be from a previous command.
2021-09-29 07:21:17 -04:00
| Value | Symbolic | Description | Notes |
|:------:|:--------------------------|:----------------------------|:---------|
| 0x00 | SHT2x_OK | no error | |
| 0x81 | SHT2x_ERR_WRITECMD | I2C write failed | |
| 0x82 | SHT2x_ERR_READBYTES | I2C read failed | |
| 0x83 | SHT2x_ERR_HEATER_OFF | Could not switch off heater | |
| 0x84 | SHT2x_ERR_NOT_CONNECT | Could not connect | |
| 0x85 | SHT2x_ERR_CRC_TEMP | CRC error in temperature | |
| 0x86 | SHT2x_ERR_CRC_HUM | CRC error in humidity | |
| 0x87 | SHT2x_ERR_CRC_STATUS | CRC error in status field | not used |
| 0x88 | SHT2x_ERR_HEATER_COOLDOWN | Heater need to cool down | |
| 0x88 | SHT2x_ERR_HEATER_ON | Could not switch on heater | |
Note: the HTU20 / HTU21 classes share the same error codes.
2021-09-27 14:51:23 -04:00
2022-12-18 04:41:37 -05:00
#### Heater interface
2021-09-27 14:51:23 -04:00
**WARNING:** Do not use heater for long periods.
Datasheet SHT2x does not mention max time so the maximum time of the SHT3x series is assumed here.
Use the heater for max **180** seconds, and let it cool down **180** seconds = 3 minutes.
THe library guards the cool down time by preventing switching the heater on
within **180** seconds of the last switch off. Note: this guarding is not reboot persistent.
**WARNING:** The user is responsible to switch the heater off manually!
The class does **NOT** do this automatically.
Switch off the heater by directly calling **heatOff()** or indirectly by calling **isHeaterOn()**.
- **void setHeatTimeout(uint8_t seconds)** Set the time out of the heat cycle.
This value is truncated to max 180 seconds.
- **uint8_t getHeatTimeout()** returns the value set.
- **bool heatOn()** switches heat cycle on if not already on.
Returns false if fails, setting error to **SHT2x_ERR_HEATER_COOLDOWN**
or to **SHT2x_ERR_HEATER_ON**.
- **bool heatOff()** switches heat cycle off.
Returns false if fails, setting error to **SHT2x_ERR_HEATER_OFF**.
- **bool isHeaterOn()** is the sensor still in heating cycle?
2022-12-18 04:41:37 -05:00
#### Electronic ID
2021-11-17 12:59:50 -05:00
2022-07-13 09:46:33 -04:00
To be tested.
- **uint32_t getEIDA()** returns unique ID part A.
- **uint32_t getEIDB()** returns unique ID part B.
- **uint8_t getFirmwareVersion()** returns firmware version.
2021-11-17 12:59:50 -05:00
2022-12-18 04:41:37 -05:00
#### Status fields
2021-09-27 14:51:23 -04:00
2021-09-29 07:21:17 -04:00
From HTU20 datasheet
| bits | value | meaning |
|:------:|:------:|:--------------------|
| 00 | 0 | open circuit |
| 01 | 1 | temperature reading |
| 10 | 2 | humidity reading |
| 11 | 3 | closed circuit |
2021-09-27 14:51:23 -04:00
2022-12-18 04:41:37 -05:00
#### Resolution
2022-07-13 09:46:33 -04:00
**Warning experimental**
- needs more testing as results are not in line with the datasheet.
- only tested on a HTUxx sensor.
- tested with **SHT2X_resolution.ino**
- **void setResolution(uint8_t res)** res = 0..3, other values return false.
- **uint8_t getResolution()** returns resolution set 0..3.
Datasheet SHT20 Table 8: (resolution)
| RES | Humidity | Temperature |
|:-----:|:---------:|:-----------:|
| 0 | 12 bit | 14 bit |
| 1 | 08 bit | 12 bit |
| 2 | 10 bit | 13 bit |
| 3 | 11 bit | 11 bit |
Datasheet SHT20 Table 7: (timing) and results of real measurements.
( https://github.com/RobTillaart/SHT2x/pull/11 )
| RES | HUM | TEMP | TOTAL | REAL |
|:-----:|:-----:|:------:|:-------:|:------:|
| 0 | 29 | 85 | 114 | 116 |
| 1 | 4 | 22 | 26 | 113 |
| 2 | 9 | 43 | 52 | 084 |
| 3 | 15 | 11 | 26 | 102 |
Timing in milliseconds.
2021-11-17 12:59:50 -05:00
2022-07-13 09:46:33 -04:00
2022-12-18 04:41:37 -05:00
#### Battery
2022-07-13 09:46:33 -04:00
- **bool batteryOK()** returns true if VCC > 2.5 Volts.
2021-11-17 12:59:50 -05:00
2021-09-27 14:51:23 -04:00
## Future
2022-12-18 04:41:37 -05:00
#### Must
2021-11-17 12:59:50 -05:00
- improve documentation
2022-12-18 04:41:37 -05:00
- clean up code.
2022-07-13 09:46:33 -04:00
#### 0.3.0
- add crc8 check (need sensor)
2021-09-29 07:21:17 -04:00
- improve error handling (all code paths)
2022-05-19 06:33:49 -04:00
- investigate blocking delay() in read
2022-12-18 04:41:37 -05:00
- add offset for temperature and humidity
- move code from .h to .cpp
- add GY21 as derived class name
#### ASYNC 0.3.0
improvements for interface.
- **bool requestReady()** checks both.
- **bool requestPending()** checks .
- **uint8_t getRequestType()** returns 0, 1, 2
- documentation
2022-06-23 09:15:32 -04:00
2022-11-24 08:09:52 -05:00
2022-12-18 04:41:37 -05:00
#### Should
2022-11-24 08:09:52 -05:00
- test test test
- get hardware
- add examples
- test resolutions
- performance different resolutions
- test battery
2022-12-18 04:41:37 -05:00
#### Could
2022-11-24 08:09:52 -05:00
- investigate resolution anomalies
2022-12-18 04:41:37 -05:00
- fix TODO in code (.cpp and .h) and documentation
2022-11-24 08:09:52 -05:00
- update unit tests
2022-12-18 04:41:37 -05:00
#### Wont
2022-06-23 09:15:32 -04:00
2022-07-13 09:46:33 -04:00
- add **getSerialNumber()**
**getEIDA()** and **getEIDB()** covers this
2022-06-23 09:15:32 -04:00