Arduino library for the SHT31 temperature and humidity sensor - using SoftWire.
This experimental library features the class SHT31_SW derived from - https://github.com/RobTillaart/SHT31. It has the same interface as the SHT31 class so please use that documentation as it will be the "leading class".
The main difference is that the SHT31_SW class uses the SoftWire library for communication instead of the TwoWire based Wire class. See SHT31 PR #35.
SoftWire is a software I2C bus library to be able to select other pins than the default (AVR) hardware I2C pins (SDA and SCL). An important reason to use this version is when you want more than two devices on one Arduino.
The SoftWire library is portable, however it could not read (on AVR) the SHT85 sensor which is command compatible with the SHT3x. A fix has been made in 0.3.0 and works on AVR (UNO) with an SHT31. See #12. It still has to be verified with an SHT85. The solution was to add buffers for I2C.
A separate repo is created based upon the AVR specific SoftwareWire see links below.
The SoftwareWire library is an AVR specific and worked for the SHT85. See https://github.com/RobTillaart/SHT31_SW/issues/5
The SHT3x family of sensors should work up to 1 MHz I2C although not tested above 400 MHz.
This library should also work for SHT30/35/85 but these are not tested yet.
Test on UNO
SENSOR | Temperature | Humidity | works | |
---|---|---|---|---|
SHT30 | ~0.3 | 2.0 | (not tested) | |
SHT31 | ~0.3 | 1.5 | yes | |
SHT35 | ~0.2 | 1.5 | (not tested) | |
SHT85 | ~0.2 | 1.5 | no | See SHT31_SWW |
Version 0.2.0 introduced a breaking change in constructor and begin(). Parameters have moved from begin() to the constructor.
These libraries need to be installed to get SHT31_SW working:
Related
#include "SHT31_SW.h"
Note: The interface is mostly inherited from SHT31 but presented here for completeness.
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 reading.
Error | Symbolic | Description |
---|---|---|
0x00 | SHT31_OK | no error |
0x81 | SHT31_ERR_WRITECMD | I2C write failed |
0x82 | SHT31_ERR_READBYTES | I2C read failed |
0x83 | SHT31_ERR_HEATER_OFF | Could not switch off heater |
0x84 | SHT31_ERR_NOT_CONNECT | Could not connect |
0x85 | SHT31_ERR_CRC_TEMP | CRC error in temperature |
0x86 | SHT31_ERR_CRC_HUM | CRC error in humidity |
0x87 | SHT31_ERR_CRC_STATUS | CRC error in status field |
0x88 | SHT31_ERR_HEATER_COOLDOWN | Heater need to cool down |
0x88 | SHT31_ERR_HEATER_ON | Could not switch on heater |
WARNING: Do not use heater for long periods.
Use the heater for max 180 seconds, and let it cool down 180 seconds = 3 minutes. SHT31 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.
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().
See async example for usage
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 | |
4 | System reset detected | 0 | no reset since last clear status register 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 |
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,