Skip to content

Commit 7132bb7

Browse files
committed
0.1.0 SHT31_SW
1 parent 0d8cf41 commit 7132bb7

File tree

23 files changed

+1599
-0
lines changed

23 files changed

+1599
-0
lines changed

libraries/SHT31_SW/.arduino-ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
unittest:
17+
libraries:
18+
- "SoftWire"
19+
- "AsyncDelay"
20+
- "SHT31"
21+
22+
compile:
23+
# Choosing to run compilation tests on 2 different Arduino platforms
24+
platforms:
25+
- uno
26+
# - due
27+
# - zero
28+
# - leonardo
29+
- m4
30+
- esp32
31+
- esp8266
32+
# - mega2560
33+
- rpipico
34+
libraries:
35+
- "SoftWire"
36+
- "AsyncDelay"
37+
- "SHT31"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+

libraries/SHT31_SW/.github/scripts/patch_arduino_ci.sh

Lines changed: 325 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name: Arduino-lint
3+
4+
on: [push, pull_request]
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: Arduino CI
3+
4+
on: [push, pull_request]
5+
6+
jobs:
7+
runTest:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
./.github/scripts/patch_arduino_ci.sh
18+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: json-syntax-check
15+
uses: limitusus/json-syntax-check@v1
16+
with:
17+
pattern: "\\.json$"
18+

libraries/SHT31_SW/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log SHT31_SW
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2023-03-23
10+
- initial version, derives from SHT31 0.3.8
11+

libraries/SHT31_SW/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019-2023 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/SHT31_SW/README.md

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
2+
[![Arduino CI](https://github.com/robtillaart/SHT31_SW/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![JSON check](https://github.com/RobTillaart/SHT31_SW/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/SHT31_SW/actions/workflows/jsoncheck.yml)
4+
[![Arduino-lint](https://github.com/RobTillaart/SHT31_SW/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/SHT31_SW/actions/workflows/arduino-lint.yml)
5+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SHT31_SW/blob/master/LICENSE)
6+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SHT31_SW.svg?maxAge=3600)](https://github.com/RobTillaart/SHT31_SW/releases)
7+
8+
9+
# SHT31_SW
10+
11+
Arduino library for the SHT31 temperature and humidity sensor - using **SoftWire**.
12+
13+
14+
## Description
15+
16+
This library features the class SHT31_SW derived from - https://github.com/RobTillaart/SHT31
17+
It has the same interface as the SHT31 class so please use that documentation
18+
as it will be the "leading class".
19+
20+
The main difference is that this SHT31_SW class uses the **SoftWire**
21+
library for communication instead of the **TwoWire** based **Wire** class.
22+
23+
**SoftWire** is a software I2C bus library to be able to select other pins
24+
than the default (AVR) hardware I2C pins (SDA and SCL).
25+
An important reason to use this version is when you want more than two
26+
devices on one Arduino.
27+
28+
29+
#### Status
30+
31+
- experimental
32+
- created as alternative for SHT31 PR #35.
33+
34+
35+
#### SHT sensors
36+
37+
The SHT3x family of sensors should work up to 1 MHz I2C (although
38+
39+
This library should also work for SHT30/35/85 but these are not tested yet.
40+
41+
Accuracy table
42+
43+
| SENSOR | Temperature | Humidity |
44+
|:--------:|:-------------:|:----------:|
45+
| SHT30 | ~0.3 | 2.0 |
46+
| SHT31 | ~0.3 | 1.5 |
47+
| SHT35 | ~0.2 | 1.5 |
48+
| SHT85 | ~0.2 | 1.5 |
49+
50+
51+
#### Links
52+
53+
These libraries need to be installed to get SHT31_SW working:
54+
55+
- https://github.com/stevemarple/SoftWire
56+
- https://github.com/stevemarple/AsyncDelay
57+
- https://github.com/RobTillaart/SHT31
58+
59+
60+
## Interface
61+
62+
```cpp
63+
#include "SHT31_SW.h"
64+
```
65+
66+
Note: The interface is mostly inherited from SHT31 but presented here for completeness.
67+
68+
69+
#### Base interface
70+
71+
- **SHT31_SW()** constructor.
72+
- **bool begin(uint8_t address, SoftWire \*wire = &Wire)** for platforms with multiple I2C buses.
73+
- **bool begin(SoftWire \*wire = &Wire)** same as above. With default SHT_DEFAULT_ADDRESS.
74+
- **bool read(bool fast = true)** blocks 4 (fast) or 15 (slow) milliseconds + actual read + math.
75+
Does read both the temperature and humidity.
76+
- **bool isConnected()** check sensor is reachable over I2C. Returns false if not connected.
77+
- **uint16_t readStatus()** details see datasheet and **Status fields** below.
78+
- **uint32_t lastRead()** in milliSeconds since start of program.
79+
- **bool reset(bool hard = false)** resets the sensor, soft reset by default. Returns false if it fails.
80+
- **float getHumidity()** computes the relative humidity in % based on the latest raw reading, and returns it.
81+
- **float getTemperature()** computes the temperature in °C based on the latest raw reading, and returns it.
82+
- **float getFahrenheit()** computes the temperature in °F based on the latest raw reading, and returns it.
83+
- **uint16_t getRawHumidity()** returns the raw two-byte representation of humidity directly from the sensor.
84+
- **uint16_t getRawTemperature()** returns the raw two-byte representation of temperature directly from the sensor.
85+
86+
Note that the temperature and humidity values are recalculated on every call to **getHumidity()** and **getTemperature()**.
87+
If you're worried about the extra cycles, you should make sure to cache these values or only request them after
88+
you've performed a new reading.
89+
90+
91+
#### Error interface
92+
93+
- **int getError()** returns last set error flag and clear it.
94+
Be sure to clear the error flag by calling **getError()** before calling any command as the error flag could be from a previous command.
95+
96+
| Error | Symbolic | Description |
97+
|:-------:|:----------------------------|:------------------------------|
98+
| 0x00 | SHT31_OK | no error |
99+
| 0x81 | SHT31_ERR_WRITECMD | I2C write failed |
100+
| 0x82 | SHT31_ERR_READBYTES | I2C read failed |
101+
| 0x83 | SHT31_ERR_HEATER_OFF | Could not switch off heater |
102+
| 0x84 | SHT31_ERR_NOT_CONNECT | Could not connect |
103+
| 0x85 | SHT31_ERR_CRC_TEMP | CRC error in temperature |
104+
| 0x86 | SHT31_ERR_CRC_HUM | CRC error in humidity |
105+
| 0x87 | SHT31_ERR_CRC_STATUS | CRC error in status field |
106+
| 0x88 | SHT31_ERR_HEATER_COOLDOWN | Heater need to cool down |
107+
| 0x88 | SHT31_ERR_HEATER_ON | Could not switch on heater |
108+
109+
110+
#### Heater interface
111+
112+
**WARNING:** Do not use heater for long periods.
113+
114+
Use the heater for max **180** seconds, and let it cool down **180** seconds = 3 minutes.
115+
SHT31 version 0.3.3 and up guards the cool down time by preventing switching the heater on
116+
within **180** seconds of the last switch off. Note: this guarding is not reboot persistent.
117+
118+
**WARNING:** The user is responsible to switch the heater off manually!
119+
120+
The class does **NOT** do this automatically.
121+
Switch off the heater by directly calling **heatOff()** or indirectly by calling **isHeaterOn()**.
122+
123+
- **void setHeatTimeout(uint8_t seconds)** Set the time out of the heat cycle.
124+
This value is truncated to max 180 seconds.
125+
- **uint8_t getHeatTimeout
126+
- **bool heatOn()** switches heat cycle on if not already on.
127+
Returns false if fails, setting error to **SHT31_ERR_HEATER_COOLDOWN**
128+
or to **SHT31_ERR_HEATER_ON**.
129+
- **bool heatOff()** switches heat cycle off.
130+
Returns false if fails, setting error to **SHT31_ERR_HEATER_OFF**.
131+
- **bool isHeaterOn()** is the sensor still in heating cycle? replaces **heatUp()**.
132+
Will switch the heater off if max heating time has passed.
133+
- **bool heatUp()** will be obsolete in the future. replaced by **isHeaterOn()**
134+
135+
136+
#### Async interface
137+
138+
See async example for usage
139+
140+
- **bool requestData()** requests a new measurement. Returns false if this fails.
141+
- **bool dataReady()** checks if enough time has passed to read the data. (15 milliseconds)
142+
- **bool readData(bool fast = true)** fast = true skips the CRC check.
143+
Returns false if reading fails or in case of a CRC failure.
144+
145+
146+
## Status fields
147+
148+
| BIT | Description | value | notes |
149+
|:------|:-----------------------------|:--------|:--------|
150+
| 15 | Alert pending status | 0 | no pending alerts
151+
| | | 1 | at least one pending alert - default
152+
| 14 | Reserved | 0 |
153+
| 13 | Heater status | 0 | Heater OFF - default
154+
| | | 1 | Heater ON
155+
| 12 | Reserved | 0 |
156+
| 11 | Humidity tracking alert | 0 | no alert - default
157+
| | | 1 | alert
158+
| 10 | Temperature tracking alert | 0 | no alert - default
159+
| | | 1 | alert
160+
| 9-5 | Reserved | 00000 |
161+
| 4 | System reset detected | 0 | no reset since last ‘clear status register’ command
162+
| | | 1 | reset detected (hard or soft reset command or supply fail) - default
163+
| 3-2 | Reserved | 00 |
164+
| 1 | Command status | 0 | last command executed successfully
165+
| | | 1 | last command not processed. Invalid or failed checksum
166+
| 0 | Write data checksum status | 0 | checksum of last write correct
167+
| | | 1 | checksum of last write transfer failed
168+
169+
170+
## Future
171+
172+
- keep in sync with (leading) SHT31 library
173+
174+

0 commit comments

Comments
 (0)