mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
add SHT85
This commit is contained in:
parent
105ec63998
commit
a9936bdd9f
7
libraries/SHT85/.arduino-ci.yml
Normal file
7
libraries/SHT85/.arduino-ci.yml
Normal file
@ -0,0 +1,7 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- leonardo
|
||||
- due
|
||||
- zero
|
12
libraries/SHT85/.github/workflows/arduino_test_runner.yml
vendored
Normal file
12
libraries/SHT85/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
arduino_ci:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: Arduino-CI/action@v0.1.0
|
18
libraries/SHT85/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/SHT85/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
21
libraries/SHT85/LICENSE
Normal file
21
libraries/SHT85/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-2021 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
165
libraries/SHT85/README.md
Normal file
165
libraries/SHT85/README.md
Normal file
@ -0,0 +1,165 @@
|
||||
|
||||
[![Arduino CI](https://github.com/robtillaart/SHT85/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/SHT85.svg?maxAge=3600)](https://github.com/RobTillaart/SHT85/releases)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/SHT85/blob/master/LICENSE)
|
||||
|
||||
|
||||
# SHT85
|
||||
|
||||
Arduino library for the SHT85 temperature and humidity sensor
|
||||
|
||||
Based upon the SHT31 library - https://github.com/RobTillaart/SHT31
|
||||
|
||||
**Warning:** to keep self-heating below 0.1°C, the SHT85 sensor should
|
||||
not be used for more than 10% of the time.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
```
|
||||
// TOPVIEW
|
||||
// +-------+
|
||||
// +-----\ | SDA 4 -----
|
||||
// | /-+ ----+ VCC 3 -----
|
||||
// | +-+ ----+ GND 2 -----
|
||||
// +-----/ | SCL 1 -----
|
||||
// +-------+
|
||||
```
|
||||
|
||||
The SHT85 sensors should work up to 1000 KHz, however during tests
|
||||
with an Arduino UNO it stopped at ~500 KHz so to be safe I recommend
|
||||
not to use it above 400 KHz. Also the differences in readtime becomes
|
||||
quite small. (max 15% gain). See output example sketch.
|
||||
|
||||
| I2C speed | read ms | notes |
|
||||
|:---------:|:-------:|:------|
|
||||
| 100 KHz | 5.11 | |
|
||||
| 150 KHz | 4.79 | |
|
||||
| 200 KHz | 4.64 | |
|
||||
| 250 KHz | 4.56 | |
|
||||
| 300 KHz | 4.50 | |
|
||||
| 350 KHz | 4.47 | |
|
||||
| 400 KHz | 4.45 | |
|
||||
| 450 KHz | 4.43 | |
|
||||
| 500 KHz | 4.42 | |
|
||||
| 550 KHz | ---- | fail |
|
||||
|
||||
|
||||
### Compatibility
|
||||
|
||||
This library should also work for SHT30, SHT31 and SHT35 but
|
||||
this is not verified 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 |
|
||||
|
||||
Need to investigate if the interface is identical?
|
||||
If so the libraries might be merged.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
#### Base interface
|
||||
|
||||
- **SHT85()** constructor.
|
||||
- **begin(address, dataPin, clockPin)** begin function for ESP8266 & ESP32; **WARNING: not verified yet**
|
||||
returns false if device address is incorrect or device cannot be reset.
|
||||
- **begin(address, TwoWire \*wire = &Wire)** for platforms with multiple I2C busses.
|
||||
- **read(bool fast = true)** blocks 4 (fast) or 15 (slow) milliseconds + actual read + math.
|
||||
Does read both the temperature and humidity.
|
||||
- **isConnected()** check sensor is reachable over I2C. Returns false if not connected.
|
||||
- **uint16_t readStatus()** details see datasheet and **Status fields** below
|
||||
- **uint32_t lastRead()** in milliSeconds since start of program.
|
||||
- **reset(bool hard = false)** resets the sensor, soft reset by default. Returns false if fails.
|
||||
- **getHumidity()** returns relative humidity in %. Needs a **read()** to update.
|
||||
- **getTemperature()** returns temperature in °C. Needs a **read()** to update.
|
||||
|
||||
|
||||
#### Error interface
|
||||
|
||||
- **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 | 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 statusfield |
|
||||
|
||||
|
||||
|
||||
#### Heater interface
|
||||
|
||||
Use the heater for max **180** seconds, and let it cool down an equal period of time.
|
||||
|
||||
**WARNING:** Do not use heater for long periods.
|
||||
|
||||
**WARNING:** The user is responsible to switch the heater off manually!
|
||||
The class does **NOT** do this automatically.
|
||||
|
||||
- **setHeatTimeout(uint8_t seconds)** Set the time out of the heat cycle.
|
||||
This value is truncated to max 180 seconds.
|
||||
- **heatOn()** switches heat cycle on. Returns false if fails.
|
||||
- **heatOff()** switches heat cycle off. Returns false if fails.
|
||||
- **isHeaterOn()** is the sensor still in heating cycle? replaces **heatUp()**.
|
||||
Will switch heat off if max heating time has passed.
|
||||
- **heatUp()** will be obsolete in the future.
|
||||
|
||||
|
||||
#### Async interface
|
||||
|
||||
See async example for usage
|
||||
|
||||
- **requestData()** requests a new measurement. Returns false if this fails.
|
||||
- **dataReady()** checks if enough time has passed to read the data. (typical 15 millis)
|
||||
- **readData(bool fast = true)** fast skips CRC check. Returns false if reading fails or in case of a CRC fail.
|
||||
|
||||
|
||||
## Status fields
|
||||
|
||||
| BIT | Description | values |
|
||||
|:----:|:----|:----|
|
||||
| 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 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 |
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- verify working with ESP32
|
||||
- merge with other SHT sensors if possible
|
||||
- investigate command ART (auto sampling at 4 Hz)
|
||||
- investigate command BREAK (stop auto sampling)
|
||||
- direct Fahrenheit formula
|
||||
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See examples
|
||||
|
318
libraries/SHT85/SHT85.cpp
Normal file
318
libraries/SHT85/SHT85.cpp
Normal file
@ -0,0 +1,318 @@
|
||||
//
|
||||
// FILE: SHT85.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2021-02-10
|
||||
// PURPOSE: Arduino library for the SHT85 temperature and humidity sensor
|
||||
// https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530
|
||||
// URL: https://github.com/RobTillaart/SHT85
|
||||
//
|
||||
|
||||
// HISTORY:
|
||||
// 0.1.0 2021-02-10 initial version
|
||||
// 0.1.1 2021-03-13 initial release
|
||||
|
||||
|
||||
#include "SHT85.h"
|
||||
|
||||
|
||||
// SUPPORTED COMMANDS - single shot mode only
|
||||
#define SHT_READ_STATUS 0xF32D
|
||||
#define SHT_CLEAR_STATUS 0x3041
|
||||
|
||||
#define SHT_SOFT_RESET 0x30A2
|
||||
#define SHT_HARD_RESET 0x0006
|
||||
|
||||
#define SHT_MEASUREMENT_FAST 0x2416 // page 10 datasheet
|
||||
#define SHT_MEASUREMENT_SLOW 0x2400 // no clock stretching
|
||||
|
||||
#define SHT_HEAT_ON 0x306D
|
||||
#define SHT_HEAT_OFF 0x3066
|
||||
|
||||
|
||||
SHT85::SHT85()
|
||||
{
|
||||
_addr = 0;
|
||||
_lastRead = 0;
|
||||
temperature = 0;
|
||||
humidity = 0;
|
||||
_heaterStart = 0;
|
||||
_error = SHT_OK;
|
||||
}
|
||||
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
bool SHT85::begin(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)
|
||||
{
|
||||
if ((address != 0x44) && (address != 0x45))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_addr = address;
|
||||
|
||||
_wire = &Wire;
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
{
|
||||
_wire->begin(dataPin, clockPin);
|
||||
} else {
|
||||
_wire->begin();
|
||||
}
|
||||
return reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool SHT85::begin(const uint8_t address, TwoWire *wire)
|
||||
{
|
||||
if ((address != 0x44) && (address != 0x45))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_addr = address;
|
||||
_wire = wire;
|
||||
_wire->begin();
|
||||
return reset();
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::read(bool fast)
|
||||
{
|
||||
if (writeCmd(fast ? SHT_MEASUREMENT_FAST : SHT_MEASUREMENT_SLOW) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
delay(fast ? 4 : 15); // table 4 datasheet
|
||||
return readData(fast);
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::isConnected()
|
||||
{
|
||||
_wire->beginTransmission(_addr);
|
||||
int rv = _wire->endTransmission();
|
||||
if (rv != 0) _error = SHT_ERR_NOT_CONNECT;
|
||||
return (rv == 0);
|
||||
}
|
||||
|
||||
#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
|
||||
#endif
|
||||
|
||||
|
||||
uint16_t SHT85::readStatus()
|
||||
{
|
||||
uint8_t status[3] = { 0, 0, 0 };
|
||||
// page 13 datasheet
|
||||
if (writeCmd(SHT_READ_STATUS) == false)
|
||||
{
|
||||
return 0xFFFF;
|
||||
}
|
||||
// 16 bit status + CRC
|
||||
if (readBytes(3, (uint8_t*) &status[0]) == false)
|
||||
{
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
if (status[2] != crc8(status, 2))
|
||||
{
|
||||
_error = SHT_ERR_CRC_STATUS;
|
||||
return 0xFFFF;
|
||||
}
|
||||
|
||||
return (uint16_t) (status[0] << 8) + status[1];
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::reset(bool hard)
|
||||
{
|
||||
bool b = writeCmd(hard ? SHT_HARD_RESET : SHT_SOFT_RESET);
|
||||
if (b == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
delay(1); // table 4 datasheet
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SHT85::setHeatTimeout(uint8_t seconds)
|
||||
{
|
||||
_heatTimeOut = seconds;
|
||||
if (_heatTimeOut > 180) _heatTimeOut = 180;
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::heatOn()
|
||||
{
|
||||
if (writeCmd(SHT_HEAT_ON) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_heaterStart = millis();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::heatOff()
|
||||
{
|
||||
if (writeCmd(SHT_HEAT_OFF) == false)
|
||||
{
|
||||
_error = SHT_ERR_HEATER_OFF; // can be serious!
|
||||
return false;
|
||||
}
|
||||
_heaterStart = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::isHeaterOn()
|
||||
{
|
||||
if (_heaterStart == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// did not exceed time out
|
||||
if (millis() - _heaterStart < (_heatTimeOut * 1000UL))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
heatOff(); // should this be done here?
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::requestData()
|
||||
{
|
||||
if (writeCmd(SHT_MEASUREMENT_SLOW) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_lastRequest = millis();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::dataReady()
|
||||
{
|
||||
return ((millis() - _lastRequest) > 15); // TODO MAGIC NR
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::readData(bool fast)
|
||||
{
|
||||
uint8_t buffer[6];
|
||||
if (readBytes(6, (uint8_t*) &buffer[0]) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!fast)
|
||||
{
|
||||
if (buffer[2] != crc8(buffer, 2))
|
||||
{
|
||||
_error = SHT_ERR_CRC_TEMP;
|
||||
return false;
|
||||
}
|
||||
if (buffer[5] != crc8(buffer + 3, 2))
|
||||
{
|
||||
_error = SHT_ERR_CRC_HUM;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t raw = (buffer[0] << 8) + buffer[1];
|
||||
temperature = raw * (175.0 / 65535) - 45;
|
||||
raw = (buffer[3] << 8) + buffer[4];
|
||||
humidity = raw * (100.0 / 65535);
|
||||
|
||||
_lastRead = millis();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int SHT85::getError()
|
||||
{
|
||||
int rv = _error;
|
||||
_error = SHT_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
uint8_t SHT85::crc8(const uint8_t *data, uint8_t len)
|
||||
{
|
||||
// CRC-8 formula from page 14 of SHT spec pdf
|
||||
const uint8_t POLY(0x31);
|
||||
uint8_t crc(0xFF);
|
||||
|
||||
for (uint8_t j = len; j; --j)
|
||||
{
|
||||
crc ^= *data++;
|
||||
|
||||
for (uint8_t i = 8; i; --i)
|
||||
{
|
||||
crc = (crc & 0x80) ? (crc << 1) ^ POLY : (crc << 1);
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::writeCmd(uint16_t cmd)
|
||||
{
|
||||
_wire->beginTransmission(_addr);
|
||||
_wire->write(cmd >> 8 );
|
||||
_wire->write(cmd & 0xFF);
|
||||
if (_wire->endTransmission() != 0)
|
||||
{
|
||||
_error = SHT_ERR_WRITECMD;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SHT85::readBytes(uint8_t n, uint8_t *val)
|
||||
{
|
||||
int rv = _wire->requestFrom(_addr, (uint8_t) n);
|
||||
if (rv == n)
|
||||
{
|
||||
for (uint8_t i = 0; i < n; i++)
|
||||
{
|
||||
val[i] = _wire->read();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
_error = SHT_ERR_READBYTES;
|
||||
return false;
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
111
libraries/SHT85/SHT85.h
Normal file
111
libraries/SHT85/SHT85.h
Normal file
@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: SHT85.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2021-02-10
|
||||
// PURPOSE: Arduino library for the SHT85 temperature and humidity sensor
|
||||
// https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530
|
||||
// URL: https://github.com/RobTillaart/SHT85
|
||||
//
|
||||
|
||||
// keep lib in sync with https://github.com/RobTillaart/SHT31
|
||||
|
||||
|
||||
// TOPVIEW
|
||||
// +-------+
|
||||
// +-----\ | SDA 4 -----
|
||||
// | +-+ ----+ VCC 3 -----
|
||||
// | +-+ ----+ GND 2 -----
|
||||
// +-----/ | SCL 1 -----
|
||||
// +-------+
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define SHT85_LIB_VERSION "0.1.1"
|
||||
|
||||
|
||||
// fields readStatus
|
||||
#define SHT_STATUS_ALERT_PENDING (1 << 15)
|
||||
#define SHT_STATUS_HEATER_ON (1 << 13)
|
||||
#define SHT_STATUS_HUM_TRACK_ALERT (1 << 11)
|
||||
#define SHT_STATUS_TEMP_TRACK_ALERT (1 << 10)
|
||||
#define SHT_STATUS_SYSTEM_RESET (1 << 4)
|
||||
#define SHT_STATUS_COMMAND_STATUS (1 << 1)
|
||||
#define SHT_STATUS_WRITE_CRC_STATUS (1 << 0)
|
||||
|
||||
// error codes
|
||||
#define SHT_OK 0x00
|
||||
#define SHT_ERR_WRITECMD 0x81
|
||||
#define SHT_ERR_READBYTES 0x82
|
||||
#define SHT_ERR_HEATER_OFF 0x83
|
||||
#define SHT_ERR_NOT_CONNECT 0x84
|
||||
#define SHT_ERR_CRC_TEMP 0x85
|
||||
#define SHT_ERR_CRC_HUM 0x86
|
||||
#define SHT_ERR_CRC_STATUS 0x87
|
||||
|
||||
|
||||
class SHT85
|
||||
{
|
||||
public:
|
||||
SHT85();
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
bool begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin);
|
||||
#endif
|
||||
bool begin(const uint8_t address, TwoWire *wire = &Wire);
|
||||
|
||||
// blocks 15 milliseconds + actual read + math
|
||||
bool read(bool fast = true);
|
||||
|
||||
// check senosr is reachable over I2C
|
||||
bool isConnected();
|
||||
|
||||
// details see datasheet; summary in SHT31.cpp file
|
||||
uint16_t readStatus();
|
||||
|
||||
// lastRead is in milliSeconds since start
|
||||
uint32_t lastRead() { return _lastRead; };
|
||||
|
||||
bool reset(bool hard = false);
|
||||
|
||||
// do not use heater for long periods,
|
||||
// use it for max 3 minutes to heat up
|
||||
// and let it cool down an equal period.
|
||||
void setHeatTimeout(uint8_t seconds);
|
||||
bool heatOn();
|
||||
bool heatOff();
|
||||
bool isHeaterOn(); // is the sensor still heating up?
|
||||
|
||||
float getHumidity() { return humidity; };
|
||||
float getTemperature() { return temperature; };
|
||||
|
||||
// ASYNC INTERFACE
|
||||
bool requestData();
|
||||
bool dataReady();
|
||||
bool readData(bool fast = true);
|
||||
|
||||
int getError(); // clears error flag
|
||||
|
||||
private:
|
||||
uint8_t crc8(const uint8_t *data, uint8_t len);
|
||||
bool writeCmd(uint16_t cmd);
|
||||
bool readBytes(uint8_t n, uint8_t *val);
|
||||
TwoWire* _wire;
|
||||
|
||||
uint8_t _addr;
|
||||
uint8_t _heatTimeOut; // seconds
|
||||
uint32_t _lastRead;
|
||||
uint32_t _lastRequest; // for async interface
|
||||
uint32_t _heaterStart;
|
||||
|
||||
float humidity;
|
||||
float temperature;
|
||||
|
||||
uint8_t _error;
|
||||
};
|
||||
|
||||
// -- END OF FILE --
|
54
libraries/SHT85/examples/SHT85_I2C_speed/SHT85_I2C_speed.ino
Normal file
54
libraries/SHT85/examples/SHT85_I2C_speed/SHT85_I2C_speed.ino
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// FILE: SHT85_I2C_speed.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/SHT85
|
||||
|
||||
|
||||
// TOPVIEW
|
||||
// +-------+
|
||||
// +-----\ | SDA 4 -----
|
||||
// | +-+ ----+ GND 3 -----
|
||||
// | +-+ ----+ +5V 2 -----
|
||||
// +-----/ | SCL 1 -----
|
||||
// +-------+
|
||||
|
||||
|
||||
#include "SHT85.h"
|
||||
|
||||
#define SHT85_ADDRESS 0x44
|
||||
|
||||
uint32_t start;
|
||||
uint32_t stop;
|
||||
|
||||
SHT85 sht;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("SHT85_LIB_VERSION: \t");
|
||||
Serial.println(SHT85_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
sht.begin(SHT85_ADDRESS);
|
||||
for (uint32_t clk = 100000; clk < 550000; clk += 50000)
|
||||
{
|
||||
Wire.setClock(clk);
|
||||
start = micros();
|
||||
sht.read(); // default = true/fast slow = false
|
||||
stop = micros();
|
||||
Serial.print(clk);
|
||||
Serial.print("\t");
|
||||
Serial.println((stop - start) * 0.001);
|
||||
delay(100);
|
||||
}
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
58
libraries/SHT85/examples/SHT85_demo/SHT85_demo.ino
Normal file
58
libraries/SHT85/examples/SHT85_demo/SHT85_demo.ino
Normal file
@ -0,0 +1,58 @@
|
||||
//
|
||||
// FILE: SHT85_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/SHT85
|
||||
|
||||
|
||||
// TOPVIEW
|
||||
// +-------+
|
||||
// +-----\ | SDA 4 -----
|
||||
// | +-+ ----+ GND 3 -----
|
||||
// | +-+ ----+ +5V 2 -----
|
||||
// +-----/ | SCL 1 -----
|
||||
// +-------+
|
||||
|
||||
|
||||
#include "SHT85.h"
|
||||
|
||||
#define SHT85_ADDRESS 0x44
|
||||
|
||||
uint32_t start;
|
||||
uint32_t stop;
|
||||
|
||||
SHT85 sht;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("SHT85_LIB_VERSION: \t");
|
||||
Serial.println(SHT85_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
sht.begin(SHT85_ADDRESS);
|
||||
Wire.setClock(100000);
|
||||
|
||||
uint16_t stat = sht.readStatus();
|
||||
Serial.print(stat, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
start = micros();
|
||||
sht.read(); // default = true/fast slow = false
|
||||
stop = micros();
|
||||
|
||||
Serial.print("\t");
|
||||
Serial.print((stop - start) * 0.001);
|
||||
Serial.print("\t");
|
||||
Serial.print(sht.getTemperature(), 1);
|
||||
Serial.print("\t");
|
||||
Serial.println(sht.getHumidity(), 1);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,67 @@
|
||||
//
|
||||
// FILE: SHT85_demo_plotter.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/SHT85
|
||||
|
||||
|
||||
// TOPVIEW
|
||||
// +-------+
|
||||
// +-----\ | SDA 4 -----
|
||||
// | +-+ ----+ GND 3 -----
|
||||
// | +-+ ----+ +5V 2 -----
|
||||
// +-----/ | SCL 1 -----
|
||||
// +-------+
|
||||
|
||||
#include "SHT85.h"
|
||||
|
||||
#define SHT85_ADDRESS 0x44
|
||||
|
||||
uint32_t start;
|
||||
uint32_t stop;
|
||||
|
||||
uint16_t count = 0;
|
||||
uint32_t last = 0;
|
||||
|
||||
SHT85 sht;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
// Serial.println(__FILE__);
|
||||
// Serial.print("SHT85_LIB_VERSION: \t");
|
||||
// Serial.println(SHT85_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
sht.begin(SHT85_ADDRESS);
|
||||
Wire.setClock(100000);
|
||||
|
||||
// uint16_t stat = sht.readStatus();
|
||||
// Serial.print(stat, HEX);
|
||||
// Serial.println();
|
||||
Serial.println("count\t time\t temp\t hum");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
start = micros();
|
||||
sht.read(); // default = true/fast slow = false
|
||||
stop = micros();
|
||||
|
||||
Serial.print("\t");
|
||||
Serial.print(count++);
|
||||
Serial.print("\t");
|
||||
Serial.print((stop - start) * 0.001, 3);
|
||||
Serial.print("\t");
|
||||
Serial.print(sht.getTemperature(), 2);
|
||||
Serial.print("\t");
|
||||
Serial.println(sht.getHumidity(), 2);
|
||||
if (millis() - last >= 100)
|
||||
{
|
||||
last = millis();
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
33
libraries/SHT85/keywords.txt
Normal file
33
libraries/SHT85/keywords.txt
Normal file
@ -0,0 +1,33 @@
|
||||
# Syntax Coloring Map For SHT85 temperature and humidity sensor
|
||||
|
||||
# Datatypes (KEYWORD1)
|
||||
SHT85 KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
read KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
readStatus KEYWORD2
|
||||
lastRead KEYWORD2
|
||||
reset KEYWORD2
|
||||
setHeatTimeout KEYWORD2
|
||||
heatOn KEYWORD2
|
||||
heatOff KEYWORD2
|
||||
isHeaterOn KEYWORD2
|
||||
getHumidity KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
requestData KEYWORD2
|
||||
dataReady KEYWORD2
|
||||
readData KEYWORD2
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
||||
# Constants (LITERAL1)
|
||||
SHT_LIB_VERSION LITERAL1
|
||||
SHT_STATUS_ALERT_PENDING LITERAL1
|
||||
SHT_STATUS_HEATER_ON LITERAL1
|
||||
SHT_STATUS_HUM_TRACK_ALERT LITERAL1
|
||||
SHT_STATUS_TEMP_TRACK_ALERT LITERAL1
|
||||
SHT_STATUS_SYSTEM_RESET LITERAL1
|
||||
SHT_STATUS_COMMAND_STATUS LITERAL1
|
||||
SHT_STATUS_WRITE_CRC_STATUS LITERAL1
|
21
libraries/SHT85/library.json
Normal file
21
libraries/SHT85/library.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "SHT85",
|
||||
"keywords": "SHT85 Temperature Humidity I2C SHT30, SHT31, SHT35",
|
||||
"description": "Arduino library for the I2C SHT85 temperature and humidity sensor",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/SHT85"
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
11
libraries/SHT85/library.properties
Normal file
11
libraries/SHT85/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=SHT85
|
||||
version=0.1.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for the SHT85 temperature and humidity sensor
|
||||
paragraph=Class for SHT85 Temperature Humidity Adafruit I2C
|
||||
category=Sensor
|
||||
url=https://github.com/RobTillaart/SHT85
|
||||
architectures=*
|
||||
includes=SHT85.h
|
||||
depends=
|
156
libraries/SHT85/test/unit_test_001.cpp
Normal file
156
libraries/SHT85/test/unit_test_001.cpp
Normal file
@ -0,0 +1,156 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// DATE: 2021-02-10
|
||||
// PURPOSE: unit tests for the SHT85 temperature and humidity sensor
|
||||
// https://github.com/RobTillaart/SHT85
|
||||
// https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual)
|
||||
// assertNotEqual(expected, actual)
|
||||
// assertLess(expected, actual)
|
||||
// assertMore(expected, actual)
|
||||
// assertLessOrEqual(expected, actual)
|
||||
// assertMoreOrEqual(expected, actual)
|
||||
// assertTrue(actual)
|
||||
// assertFalse(actual)
|
||||
// assertNull(actual)
|
||||
|
||||
/*
|
||||
most unit tests will test for fail
|
||||
as there is no sensor connected
|
||||
and there is no mockup.
|
||||
|
||||
It appears that Wire.write does not fail without sensor...
|
||||
*/
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SHT85.h"
|
||||
|
||||
int expect; // TODO needed as there seems a problem with 8 bit comparisons (char?)
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
}
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
unittest(test_begin)
|
||||
{
|
||||
SHT85 sht;
|
||||
|
||||
bool b = sht.begin(0x44);
|
||||
assertEqual(b, true);
|
||||
|
||||
assertTrue(sht.reset());
|
||||
expect = SHT_OK;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
Serial.println(sht.getTemperature());
|
||||
Serial.println(sht.getHumidity());
|
||||
|
||||
// default value == 0
|
||||
assertEqual(0, sht.getTemperature());
|
||||
assertEqual(0, sht.getHumidity());
|
||||
}
|
||||
|
||||
unittest(test_read)
|
||||
{
|
||||
SHT85 sht;
|
||||
bool b = sht.begin(0x44);
|
||||
assertEqual(b, true);
|
||||
|
||||
assertTrue(sht.isConnected());
|
||||
expect = SHT_OK;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
assertFalse(sht.read());
|
||||
expect = SHT_ERR_READBYTES;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
start = millis();
|
||||
assertFalse(sht.read(false));
|
||||
stop = millis();
|
||||
Serial.println(stop - start);
|
||||
expect = SHT_ERR_READBYTES;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
start = millis();
|
||||
assertFalse(sht.read(true));
|
||||
stop = millis();
|
||||
Serial.println(stop - start);
|
||||
expect = SHT_ERR_READBYTES;
|
||||
assertEqual(expect, sht.getError());
|
||||
}
|
||||
|
||||
unittest(test_readStatus)
|
||||
{
|
||||
SHT85 sht;
|
||||
bool b = sht.begin(0x44);
|
||||
assertEqual(b, true);
|
||||
|
||||
assertEqual(0xFFFF, sht.readStatus());
|
||||
expect = SHT_ERR_READBYTES;
|
||||
assertEqual(expect, sht.getError());
|
||||
}
|
||||
|
||||
unittest(test_heater)
|
||||
{
|
||||
SHT85 sht;
|
||||
bool b = sht.begin(0x44);
|
||||
assertEqual(b, true);
|
||||
|
||||
assertTrue(sht.heatOn());
|
||||
expect = SHT_OK;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
assertTrue(sht.heatOff());
|
||||
expect = SHT_OK;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
assertFalse(sht.isHeaterOn());
|
||||
expect = SHT_OK;
|
||||
assertEqual(expect, sht.getError());
|
||||
}
|
||||
|
||||
unittest(test_async)
|
||||
{
|
||||
SHT85 sht;
|
||||
bool b = sht.begin(0x44);
|
||||
assertEqual(b, true);
|
||||
|
||||
assertTrue(sht.requestData());
|
||||
expect = SHT_OK;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
assertFalse(sht.dataReady());
|
||||
expect = SHT_OK;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
assertFalse(sht.readData());
|
||||
expect = SHT_ERR_READBYTES;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
assertFalse(sht.readData(true));
|
||||
expect = SHT_ERR_READBYTES;
|
||||
assertEqual(expect, sht.getError());
|
||||
|
||||
assertFalse(sht.readData(false));
|
||||
expect = SHT_ERR_READBYTES;
|
||||
assertEqual(expect, sht.getError());
|
||||
}
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
Loading…
Reference in New Issue
Block a user