mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.3.7 SHT31
This commit is contained in:
parent
49ddc35547
commit
dd00c5b611
@ -1,11 +1,27 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- due
|
||||
- zero
|
||||
- leonardo
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
- mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
79
libraries/SHT31/CHANGELOG.md
Normal file
79
libraries/SHT31/CHANGELOG.md
Normal file
@ -0,0 +1,79 @@
|
||||
# Change Log SHT31
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.7] - 2022-11-24
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.3.6] - 2022-01-18
|
||||
- sync with SHT85 lib
|
||||
|
||||
## [0.3.5] - 2021-12-28
|
||||
- update library.json
|
||||
- update readme
|
||||
- update license
|
||||
- minor edits
|
||||
|
||||
## [0.3.4] - 2021-09-19
|
||||
- update build-CI
|
||||
|
||||
## [0.3.3] - 2021-08-24
|
||||
- fix #22 prevent heater to switch on too fast.
|
||||
- update readme
|
||||
|
||||
## [0.3.2] - 2021-08-05
|
||||
- expose raw data from sensor
|
||||
|
||||
## [0.3.1] - 2021-05-27
|
||||
- arduino-lint fixes
|
||||
|
||||
## [0.3.0] - 2021-01-04
|
||||
- arduino-ci
|
||||
|
||||
----
|
||||
|
||||
## [0.2.6] - 2021-01-01
|
||||
- patch version 0.2.6
|
||||
|
||||
## [0.2.5] - 2020-12-02
|
||||
- add isHeaterOn()
|
||||
- add unittest
|
||||
- arduino-ci
|
||||
|
||||
## [0.2.4] - 2020-11-29
|
||||
- added isConnected()
|
||||
|
||||
## [0.2.3] - 2020-07-19
|
||||
- added CRC by PetrDa (thanks)
|
||||
- cleanup
|
||||
|
||||
## [0.2.2] - 2020-07-05
|
||||
- fix compiling for ESP
|
||||
|
||||
## [0.2.1] - 2020-06-19
|
||||
- fix library.json
|
||||
|
||||
## [0.2.0] - 2020-05-12
|
||||
- made humidity & temperature private;
|
||||
- support ESP32 I2C
|
||||
|
||||
----
|
||||
|
||||
## [0.1.2] - 2019-03-05
|
||||
- fix issue #123 - error in humidity
|
||||
- stable version
|
||||
|
||||
## [0.1.1] - 2019-02-18
|
||||
- add description readStatus(),
|
||||
- async interface
|
||||
|
||||
## [0.1.0] - 2019-02-08
|
||||
- initial version
|
||||
|
@ -20,12 +20,14 @@ The SHT3x family of sensors should work up to 1 MHz I2C
|
||||
This library should also work for SHT30 and SHT35 but these are
|
||||
not tested yet.
|
||||
|
||||
| SENSOR | Temperature accuracy | Humidity accuracy |
|
||||
|:------:|:------:|:-----:|
|
||||
| SHT30 | ~0.3 | 2.0 |
|
||||
| SHT31 | ~0.3 | 1.5 |
|
||||
| SHT35 | ~0.2 | 1.5 |
|
||||
| SHT85 | ~0.2 | 1.5 |
|
||||
Accuracy table
|
||||
|
||||
| SENSOR | Temperature | Humidity |
|
||||
|:--------:|:-------------:|:----------:|
|
||||
| SHT30 | ~0.3 | 2.0 |
|
||||
| SHT31 | ~0.3 | 1.5 |
|
||||
| SHT35 | ~0.2 | 1.5 |
|
||||
| SHT85 | ~0.2 | 1.5 |
|
||||
|
||||
|
||||
An elaborated library for the SHT31 sensor can be found here
|
||||
@ -65,18 +67,18 @@ you've performed a new reading.
|
||||
- **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.
|
||||
|
||||
| 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 |
|
||||
| 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 |
|
||||
|
||||
|
||||
#### Heater interface
|
||||
@ -117,26 +119,26 @@ Returns false if reading fails or in case of a CRC failure.
|
||||
|
||||
## Status fields
|
||||
|
||||
| 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
|
||||
| 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
|
||||
|
||||
|
||||
|
||||
@ -148,5 +150,6 @@ See examples.
|
||||
## Future
|
||||
|
||||
- keep in sync with SHT85 library
|
||||
- check TODO in code
|
||||
|
||||
|
||||
|
@ -1,54 +1,29 @@
|
||||
//
|
||||
// FILE: SHT31.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.6
|
||||
// VERSION: 0.3.7
|
||||
// DATE: 2019-02-08
|
||||
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
|
||||
// https://www.adafruit.com/product/2857
|
||||
// URL: https://github.com/RobTillaart/SHT31
|
||||
//
|
||||
|
||||
// HISTORY:
|
||||
// 0.1.0 2019-02-08 initial version
|
||||
// 0.1.1 2019-02-18 add description readStatus(),
|
||||
// async interface
|
||||
// 0.1.2 2019-03-05 fix issue #123 - error in humidity
|
||||
// stable version
|
||||
// 0.2.0 2020-05-12 made humidity & temperature private;
|
||||
// support ESP32 I2C
|
||||
// 0.2.1 2020-06-19 fix library.json
|
||||
// 0.2.2 2020-07-05 fix compiling for ESP
|
||||
// 0.2.3 2020-07-19 added CRC by PetrDa (thanks); cleanup
|
||||
// 0.2.4 2020-11-29 added isConnected()
|
||||
// 0.2.5 2020-12-02 added isHeaterOn() + unittest + arduino-ci
|
||||
// 0.2.6 2021-01-01 patch version 0.2.6
|
||||
//
|
||||
// 0.3.0 2021-01-04 arduino-ci
|
||||
// 0.3.1 2021-05-27 arduino-lint fixes
|
||||
// 0.3.2 2021-08-05 expose raw data from sensor
|
||||
// 0.3.3 2021-08-24 fix #22 prevent heater to switch on too fast.
|
||||
// update readme
|
||||
// 0.3.4 2021-09-19 update build-CI
|
||||
// 0.3.5 2021-12-28 update library.json, readme, license, minor edits
|
||||
// 0.3.6 2022-01-18 sync with SHT85 lib
|
||||
|
||||
|
||||
#include "SHT31.h"
|
||||
|
||||
|
||||
// SUPPORTED COMMANDS - single shot mode only
|
||||
// SUPPORTED COMMANDS - single shot mode only
|
||||
#define SHT31_READ_STATUS 0xF32D
|
||||
#define SHT31_CLEAR_STATUS 0x3041
|
||||
|
||||
#define SHT31_SOFT_RESET 0x30A2
|
||||
#define SHT31_HARD_RESET 0x0006
|
||||
|
||||
#define SHT31_MEASUREMENT_FAST 0x2416 // page 10 datasheet
|
||||
#define SHT31_MEASUREMENT_SLOW 0x2400 // no clock stretching
|
||||
#define SHT31_MEASUREMENT_FAST 0x2416 // page 10 datasheet
|
||||
#define SHT31_MEASUREMENT_SLOW 0x2400 // no clock stretching
|
||||
|
||||
#define SHT31_HEAT_ON 0x306D
|
||||
#define SHT31_HEAT_OFF 0x3066
|
||||
#define SHT31_HEATER_TIMEOUT 180000UL // milliseconds
|
||||
#define SHT31_HEATER_TIMEOUT 180000UL // milliseconds
|
||||
|
||||
|
||||
SHT31::SHT31()
|
||||
@ -117,7 +92,7 @@ bool SHT31::read(bool fast)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
delay(fast ? 4 : 15); // table 4 datasheet
|
||||
delay(fast ? 4 : 15); // table 4 datasheet
|
||||
return readData(fast);
|
||||
}
|
||||
|
||||
@ -131,45 +106,45 @@ bool SHT31::isConnected()
|
||||
}
|
||||
|
||||
#ifdef doc
|
||||
// bit - description
|
||||
// ==================
|
||||
// 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 Temp 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 cmd executed successfully
|
||||
// '1': last cmd not processed. Invalid or failed checksum
|
||||
// 0 Write data checksum status
|
||||
// '0': checksum of last write correct
|
||||
// '1': checksum of last write transfer failed
|
||||
// bit - description
|
||||
// ==================
|
||||
// 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 Temp 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
|
||||
#endif
|
||||
|
||||
|
||||
uint16_t SHT31::readStatus()
|
||||
{
|
||||
uint8_t status[3] = { 0, 0, 0 };
|
||||
// page 13 datasheet
|
||||
// page 13 datasheet
|
||||
if (writeCmd(SHT31_READ_STATUS) == false)
|
||||
{
|
||||
return 0xFFFF;
|
||||
}
|
||||
// 16 bit status + CRC
|
||||
// 16 bit status + CRC
|
||||
if (readBytes(3, (uint8_t*) &status[0]) == false)
|
||||
{
|
||||
return 0xFFFF;
|
||||
@ -192,7 +167,7 @@ bool SHT31::reset(bool hard)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
delay(1); // table 4 datasheet
|
||||
delay(1); // table 4 datasheet
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -225,7 +200,7 @@ bool SHT31::heatOn()
|
||||
|
||||
bool SHT31::heatOff()
|
||||
{
|
||||
// always switch off the heater - ignore _heaterOn flag.
|
||||
// always switch off the heater - ignore _heaterOn flag.
|
||||
if (writeCmd(SHT31_HEAT_OFF) == false)
|
||||
{
|
||||
_error = SHT31_ERR_HEATER_OFF; // can be serious!
|
||||
@ -243,7 +218,7 @@ bool SHT31::isHeaterOn()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// did not exceed time out
|
||||
// did not exceed time out
|
||||
if (millis() - _heaterStart < (_heatTimeout * 1000UL))
|
||||
{
|
||||
return true;
|
||||
@ -266,7 +241,7 @@ bool SHT31::requestData()
|
||||
|
||||
bool SHT31::dataReady()
|
||||
{
|
||||
return ((millis() - _lastRequest) > 15); // TODO MAGIC NR
|
||||
return ((millis() - _lastRequest) > 15); // TODO MAGIC NR
|
||||
}
|
||||
|
||||
|
||||
@ -313,7 +288,7 @@ int SHT31::getError()
|
||||
|
||||
uint8_t SHT31::crc8(const uint8_t *data, uint8_t len)
|
||||
{
|
||||
// CRC-8 formula from page 14 of SHT spec pdf
|
||||
// CRC-8 formula from page 14 of SHT spec pdf
|
||||
const uint8_t POLY(0x31);
|
||||
uint8_t crc(0xFF);
|
||||
|
||||
@ -359,4 +334,6 @@ bool SHT31::readBytes(uint8_t n, uint8_t *val)
|
||||
return false;
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,19 +2,18 @@
|
||||
//
|
||||
// FILE: SHT31.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.6
|
||||
// VERSION: 0.3.7
|
||||
// DATE: 2019-02-08
|
||||
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
|
||||
// https://www.adafruit.com/product/2857
|
||||
// URL: https://github.com/RobTillaart/SHT31
|
||||
//
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define SHT31_LIB_VERSION (F("0.3.6"))
|
||||
#define SHT31_LIB_VERSION (F("0.3.7"))
|
||||
|
||||
#ifndef SHT_DEFAULT_ADDRESS
|
||||
#define SHT_DEFAULT_ADDRESS 0x44
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/SHT31"
|
||||
},
|
||||
"version": "0.3.6",
|
||||
"version": "0.3.7",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=SHT31
|
||||
version=0.3.6
|
||||
version=0.3.7
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for the SHT31 temperature and humidity sensor
|
||||
|
@ -31,9 +31,11 @@
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SHT31.h"
|
||||
|
||||
|
||||
int expect; // TODO needed as there seems a problem with 8 bit comparisons (char?)
|
||||
|
||||
uint32_t start, stop;
|
||||
|
Loading…
Reference in New Issue
Block a user