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

350 lines
14 KiB
Markdown
Raw Permalink Normal View History

2021-05-26 06:06:51 -04:00
2023-09-06 05:42:30 -04:00
[![Arduino CI](https://github.com/RobTillaart/SHT85/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-08-24 12:45:23 -04:00
[![Arduino-lint](https://github.com/RobTillaart/SHT85/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/SHT85/actions/workflows/arduino-lint.yml)
2021-10-20 02:32:56 -04:00
[![JSON check](https://github.com/RobTillaart/SHT85/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SHT85/actions/workflows/jsoncheck.yml)
2023-09-06 05:42:30 -04:00
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/SHT85.svg)](https://github.com/RobTillaart/SHT85/issues)
2021-05-26 06:06:51 -04:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SHT85/blob/master/LICENSE)
2021-08-24 12:45:23 -04:00
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SHT85.svg?maxAge=3600)](https://github.com/RobTillaart/SHT85/releases)
2023-09-06 05:42:30 -04:00
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/SHT85.svg)](https://registry.platformio.org/libraries/robtillaart/SHT85)
2021-05-26 06:06:51 -04:00
# SHT85
2021-12-28 08:21:26 -05:00
Arduino library for the SHT85 temperature and humidity sensor.
2021-05-26 06:06:51 -04:00
Based upon the SHT31 library - https://github.com/RobTillaart/SHT31
2023-04-06 10:54:56 -04:00
however this library will be leading in the future as it implements derived classes
2023-05-09 06:44:18 -04:00
for the following sensors: **SHT30, SHT31, SHT35 and SHT85**.
2022-11-24 08:11:40 -05:00
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
**WARNING** to keep self-heating below 0.1<EFBFBD>C, the SHT85 sensor should
2021-05-26 06:06:51 -04:00
not be used for more than 10% of the time.
## Description
2023-04-06 10:54:56 -04:00
Always check datasheet before connecting!
2021-05-26 06:06:51 -04:00
```
2023-04-06 10:54:56 -04:00
// TOPVIEW SHT85
// +-------+
// +-----\ | SDA 4 -----
// | /-+ ----+ GND 3 -----
// | +-+ ----+ +5V 2 -----
// +-----/ | SCL 1 -----
// +-------+
2021-05-26 06:06:51 -04:00
```
2021-10-20 02:32:56 -04:00
2023-09-06 05:42:30 -04:00
The SHT85 sensors should work (I2C) up to 1000 KHz.
2023-04-06 10:54:56 -04:00
During tests with an Arduino UNO it stopped between 500 - 550 KHz.
So to be safe I recommend not to use the sensor above 400 KHz.
Also the differences in read time becomes quite small. (max 15% gain).
See indicative output example sketch.
SPS (= samples per second) are added later.
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
| I2C speed | read ms | SPS | notes |
|:---------:|:-------:|:-----:|:--------|
| 50 KHz | 6.60 | 123 |
| 100 KHz | 5.11 | 140 | default
2021-05-26 06:06:51 -04:00
| 150 KHz | 4.79 | |
2023-04-06 10:54:56 -04:00
| 200 KHz | 4.64 | 140 |
2021-05-26 06:06:51 -04:00
| 250 KHz | 4.56 | |
2023-04-06 10:54:56 -04:00
| 300 KHz | 4.50 | 164 |
2021-05-26 06:06:51 -04:00
| 350 KHz | 4.47 | |
2023-04-06 10:54:56 -04:00
| 400 KHz | 4.45 | 164 |
2021-05-26 06:06:51 -04:00
| 450 KHz | 4.43 | |
2023-04-06 10:54:56 -04:00
| 500 KHz | 4.42 | 163 |
| 550 KHz | ---- | | fail
2023-09-06 05:42:30 -04:00
At 10% load the SHT85 can be used to make about 10 - 15 SPS.
2023-04-06 10:54:56 -04:00
#### Compatibility
2021-05-26 06:06:51 -04:00
2023-05-09 06:44:18 -04:00
The SHT85 is protocol compatible with the SHT3x series.
2023-09-06 05:42:30 -04:00
Main difference is the accuracy and the SHT85 only has address 0x44.
2023-05-09 06:44:18 -04:00
Compare the data sheets to see all differences.
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
Accuracy table:
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
| Sensor | Temperature | Humidity | Verified }
|:--------:|:-------------:|:----------:|:----------:|
| SHT30 | ~0.3<EFBFBD> | 2.0% | N |
| SHT31 | ~0.3<EFBFBD> | 1.5% | Y |
| SHT35 | ~0.2<EFBFBD> | 1.5% | N |
| SHT85 | ~0.2<EFBFBD> | 1.5% | Y |
2021-05-26 06:06:51 -04:00
2021-12-28 08:21:26 -05:00
2023-04-06 10:54:56 -04:00
Note: The SHT40, SHT41 and SHT45 are not protocol compatible with SHT3x and SHT85.
The SHT4x series is slightly faster than the SHT3x series.
2021-12-28 08:21:26 -05:00
2021-05-26 06:06:51 -04:00
2023-09-06 05:42:30 -04:00
#### Multiple SHT85
The SHT3x comes with two I2C address options, 0x44 and 0x45.
The SHT85 only has 0x44 as I2C address, so it is not possible to have more than
one on a single I2C bus.
This means you need to use multiple I2C buses (if your board support this),
a software I2C (below) or an I2C multiplexer e.g. https://github.com/RobTillaart/TCA9548
2023-12-10 04:07:39 -05:00
#### 0.6.0 Breaking change
2023-09-06 05:42:30 -04:00
2023-12-10 04:07:39 -05:00
Version 0.6.0 introduced a breaking change.
The parameters from begin() moved to the constructor.
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()**.
#### Related
2023-04-06 10:54:56 -04:00
- https://github.com/RobTillaart/SHT2x
- https://github.com/RobTillaart/SHT31
- https://github.com/RobTillaart/SHT31_SW = softWire based I2C.
- https://github.com/RobTillaart/tinySHT2x
2021-05-26 06:06:51 -04:00
2021-08-24 12:45:23 -04:00
An elaborated library for the SHT31 sensor can be found here
2023-04-06 10:54:56 -04:00
- https://github.com/hawesg/SHT31D_Particle_Photon_ClosedCube
2023-05-09 06:44:18 -04:00
Dewpoint, heatindex, related functions and conversions.
2023-04-06 10:54:56 -04:00
- https://github.com/RobTillaart/Temperature
2021-08-24 12:45:23 -04:00
2023-09-06 05:42:30 -04:00
I2C multiplexer
- https://github.com/RobTillaart/TCA9548
2021-05-26 06:06:51 -04:00
## Interface
2023-04-06 10:54:56 -04:00
```cpp
#include "SHT85.h"
```
2023-12-10 04:07:39 -05:00
#### Constructor
2021-05-26 06:06:51 -04:00
2023-12-10 04:07:39 -05:00
- **SHT(uint8_t address, TwoWire \*wire = &Wire)** constructor of the base class.
Note that **getType()** will return 0.
- **SHT30(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
- **SHT31(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
- **SHT35(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
- **SHT85(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
2021-08-24 13:59:51 -04:00
- **uint8_t getType()** returns numeric part of sensor type.
2023-04-06 10:54:56 -04:00
Returns 0 for the base class.
2023-12-10 04:07:39 -05:00
- **bool begin()** Returns false if device address is incorrect or device cannot be reset.
- **uint8_t getAddress()** returns address set in constructor.
2023-04-06 10:54:56 -04:00
#### Status
2023-05-09 06:44:18 -04:00
- **bool isConnected()** checks if address of the sensor is reachable over I2C. Returns false if not connected.
2021-08-24 12:45:23 -04:00
- **uint16_t readStatus()** details see datasheet and **Status fields** below.
2021-05-26 06:06:51 -04:00
- **uint32_t lastRead()** in milliSeconds since start of program.
2021-08-24 12:45:23 -04:00
- **bool reset(bool hard = false)** resets the sensor, soft reset by default. Returns false if fails.
2023-04-06 10:54:56 -04:00
#### Synchronous read
- **bool read(bool fast = true)** blocks 4 (fast) or 15 (slow) milliseconds + actual read + math.
2023-05-09 06:44:18 -04:00
Reads both the temperature and humidity from the device.
2023-04-06 10:54:56 -04:00
Note: the medium level is not supported (yet).
#### Asynchronous read
See async example for usage.
- **bool requestData(bool fast = true)** requests a new measurement.
Returns false if the request fails.
2023-05-09 06:44:18 -04:00
Records the timestamp of the request if successful.
2023-04-06 10:54:56 -04:00
- **bool dataReady(bool fast = true)** Checks if appropriate time (4 / 15 ms)
has past since request to read the data.
2023-05-09 06:44:18 -04:00
The parameter **fast** should be the same as in requestData().
2023-04-06 10:54:56 -04:00
- **bool readData(bool fast = true)** fast = true skips the CRC check.
Returns false if reading the data fails or if CRC check failed.
2023-05-09 06:44:18 -04:00
- **uint32_t getLastRequest()** returns timestamp of last successful call to requestData.
This function is used to check if the request is too long ago.
2023-04-06 10:54:56 -04:00
#### Temperature and humidity
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
2023-05-09 06:44:18 -04:00
you've performed a new **read()**.
2023-04-06 10:54:56 -04:00
2023-05-09 06:44:18 -04:00
- **float getHumidity()** computes the relative humidity in % based on the latest raw reading. This includes the optional offset.
- **float getTemperature()** computes the temperature in <20>C based on the latest raw reading. This includes the optional offset.
2021-08-24 13:59:51 -04:00
- **float getFahrenheit()** computes the temperature in <20>F based on the latest raw reading, and returns it.
2023-04-06 10:54:56 -04:00
Note that the optional offset is set in <20>Celsius.
2023-05-09 06:44:18 -04:00
The **getRawHumidity()** and **getRawTemperature()** can be used to minimize storage or communication as the data type is 50% smaller.
2023-04-06 10:54:56 -04:00
Another application is faster comparison with a previous value or threshold.
2023-05-09 06:44:18 -04:00
However comparisons are quite fast.
2023-04-06 10:54:56 -04:00
2021-08-24 12:45:23 -04:00
- **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.
2021-08-07 06:34:52 -04:00
2023-04-06 10:54:56 -04:00
The library has no **CelsiusToRaw()** function although this is relative easy.
2023-05-09 06:44:18 -04:00
```cpp
2023-04-06 10:54:56 -04:00
rawTemperatureC = (tempC + 45) * (65535 / 175.0);
rawTemperatureF = (tempF + 49) * (65535 / 315.0);
rawHumidity = humidity * 655.35;
```
#### Temperature and humidity offset
Default the offset is zero for both temperature and humidity.
2023-05-09 06:44:18 -04:00
These functions allows one to adjust them a little. Note there is no limit to the offset so one can use huge values. This allows to use an offset of 273.15 effectively creating **<EFBFBD>Kelvin** instead of Celsius.
2023-04-06 10:54:56 -04:00
2023-05-09 06:44:18 -04:00
Note: the offset is defined in degrees Celsius.
To set an offset in degrees Fahrenheit, multiply the Fahrenheit offset with 0.55555556 to get Celsius steps (divide by 1.8 is slower).
So an offset of 4 <20>F becomes 2.2222 <20>C.
2023-04-06 10:54:56 -04:00
2023-05-09 06:44:18 -04:00
- **void setTemperatureOffset(float offset = 0)** set the offset in <20>C, default is zero removing the offset. The library converts this internally
- **float getTemperatureOffset()** returns the set offset in <20>C.
2023-04-06 10:54:56 -04:00
- **void setHumidityOffset(float offset = 0)** set the offset, default is zero removing the offset.
- **float getHumidityOffset()** returns the set offset.
2021-05-26 06:06:51 -04:00
#### Error interface
2021-08-24 13:59:51 -04:00
- **int getError()** returns last set error flag and clear it.
2023-04-06 10:54:56 -04:00
Be sure to clear the error flag by calling **getError()** before calling
any command as the error flag could be from a previous command.
2023-05-09 06:44:18 -04:00
| Error | Symbolic | Description |
|:-------:|:--------------------------|:-------------------------------|
| 0x00 | SHT_OK | no error |
| 0x81 | SHT_ERR_WRITECMD | I2C write failed |
| 0x82 | SHT_ERR_READBYTES | I2C read failed |
| 0x83 | SHT_ERR_HEATER_OFF | Could not switch off heater |
| 0x84 | SHT_ERR_NOT_CONNECT | Could not connect |
| 0x85 | SHT_ERR_CRC_TEMP | CRC error in temperature |
| 0x86 | SHT_ERR_CRC_HUM | CRC error in humidity |
| 0x87 | SHT_ERR_CRC_STATUS | CRC error in status field |
| 0x88 | SHT_ERR_HEATER_COOLDOWN | Heater need to cool down |
| 0x89 | SHT_ERR_HEATER_ON | Could not switch on heater |
| 0x8A | SHT_ERR_SERIAL | Could not read serial number |
2021-05-26 06:06:51 -04:00
#### Heater interface
2021-08-24 12:45:23 -04:00
**WARNING:** Do not use heater for long periods.
Use the heater for max **180** seconds, and let it cool down **180** seconds = 3 minutes.
Version 0.3.3 and up 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.
2021-05-26 06:06:51 -04:00
2021-08-24 12:45:23 -04:00
**WARNING:** The user is responsible to switch the heater off manually!
2021-05-26 06:06:51 -04:00
The class does **NOT** do this automatically.
2023-04-06 10:54:56 -04:00
Switch off the heater by explicitly calling **heatOff()** or indirectly by calling **isHeaterOn()**.
2021-05-26 06:06:51 -04:00
2021-08-24 12:45:23 -04:00
- **void setHeatTimeout(uint8_t seconds)** Set the time out of the heat cycle.
2021-05-26 06:06:51 -04:00
This value is truncated to max 180 seconds.
2023-04-06 10:54:56 -04:00
- **uint8_t getHeatTimeout()** returns the value set.
- **bool heatOn()** switches the heat cycle on if not already on.
Returns false if this fails, setting error to **SHT_ERR_HEATER_COOLDOWN**
2021-08-24 12:45:23 -04:00
or to **SHT_ERR_HEATER_ON**.
2023-04-06 10:54:56 -04:00
- **bool heatOff()** switches the heat cycle off.
2021-08-24 12:45:23 -04:00
Returns false if fails, setting error to **SHT_ERR_HEATER_OFF**.
2023-04-06 10:54:56 -04:00
- **bool isHeaterOn()** is the sensor still in a heating cycle? Replaces **heatUp()**.
Will switch the heater off if maximum heating time has passed.
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
## Status fields
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
| BIT | Description | value | notes |
|:------|:---------------------------|:--------|:--------|
| 15 | Alert pending status | 0 | no pending alerts
| | | 1 | at least one pending alert - default
| 14 | Reserved | 0 |
| 13 | Heater status | 0 | Heater OFF - default
| | | 1 | Heater ON
| 12 | Reserved | 0 |
| 11 | Humidity tracking alert | 0 | no alert - default
| | | 1 | alert
| 10 | Temperature tracking alert | 0 | no alert - default
| | | 1 | alert
| 9-5 | Reserved | 00000 | reserved
| 4 | System reset detected | 0 | no reset since last <20>clear status register<65> command
| | | 1 | reset detected (hard or soft reset command or supply fail) - default
| 3-2 | Reserved | 00 |
| 1 | Command status | 0 | last command executed successfully
| | | 1 | last command not processed. Invalid or failed checksum
| 0 | Write data checksum status | 0 | checksum of last write correct
| | | 1 | checksum of last write transfer failed
2021-05-26 06:06:51 -04:00
2023-05-09 06:44:18 -04:00
#### SHT85 specific
- **uint32_t GetSerialNumber()** Returns a 32 bit unique serial number.
This command seems to be timing sensitive, it uses a delay of 500us
which may need "tuning". So function is bit experimental.
2023-04-06 10:54:56 -04:00
## Future
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
#### Must
2021-12-28 08:21:26 -05:00
2023-04-06 10:54:56 -04:00
- improve documentation.
2023-12-10 04:07:39 -05:00
- reorder interface
2021-12-28 08:21:26 -05:00
2021-05-26 06:06:51 -04:00
2023-04-06 10:54:56 -04:00
#### Should
2022-01-17 15:15:55 -05:00
2023-04-06 10:54:56 -04:00
- more testing (including heater)
- verify working with ESP32
- support for medium level read.
2023-12-10 04:07:39 -05:00
- 3 levels instead of 2.
2022-11-24 08:11:40 -05:00
2022-01-17 15:15:55 -05:00
2023-04-06 10:54:56 -04:00
#### Could
2022-01-17 15:15:55 -05:00
2023-05-09 06:44:18 -04:00
- remember the fast parameter of **requestData()** so it
can become obsolete for **radaReady()**.
2021-05-26 06:06:51 -04:00
- investigate command ART (auto sampling at 4 Hz)
- investigate command BREAK (stop auto sampling)
2023-04-06 10:54:56 -04:00
- test SHT30/35
2022-11-24 08:11:40 -05:00
2022-01-17 15:15:55 -05:00
2023-05-09 06:44:18 -04:00
#### Won't
2022-01-17 15:15:55 -05:00
2022-11-24 08:11:40 -05:00
- rename the library? to SHT ? or sensirion.h ?
- not on short term
2022-01-17 15:15:55 -05:00
- create a SHT85 simulator
- I2C slave sketch with e.g. a DHT22 sensor/
- not within this library.
2023-04-06 10:54:56 -04:00
- software I2C experiments
- see https://github.com/RobTillaart/SHT31_SW
- merge with other SHT sensors if possible?
- derived classes fixes this enough.
- **getKelvin()** wrapper? (no => check temperature class)
2023-05-09 06:44:18 -04:00
==> set Offset to 273.15 !
2021-05-26 06:06:51 -04:00
2023-09-06 05:42:30 -04:00
## Support
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,