0.1.3 SHT85

This commit is contained in:
rob tillaart 2021-08-07 12:34:52 +02:00
parent 19e4633309
commit 4b93777421
7 changed files with 67 additions and 59 deletions

View File

@ -27,8 +27,8 @@ not be used for more than 10% of the time.
``` ```
The SHT85 sensors should work up to 1000 KHz, however during tests 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 with an Arduino UNO it stopped between 500 - 550 KHz so to be safe I recommend
not to use it above 400 KHz. Also the differences in readtime becomes not to use it above 400 KHz. Also the differences in read time becomes
quite small. (max 15% gain). See output example sketch. quite small. (max 15% gain). See output example sketch.
| I2C speed | read ms | notes | | I2C speed | read ms | notes |
@ -51,11 +51,11 @@ This library should also work for SHT30, SHT31 and SHT35 but
this is not verified yet. this is not verified yet.
| SENSOR | Temperature accuracy | Humidity accuracy | | SENSOR | Temperature accuracy | Humidity accuracy |
|:----:|:----:|:----:| |:------:|:------:|:-----:|
| SHT30 | ~0.3 | 2.0 | | SHT30 | ~0.3 | 2.0 |
| SHT31 | ~0.3 | 1.5 | | SHT31 | ~0.3 | 1.5 |
| SHT35 | ~0.2 | 1.5 | | SHT35 | ~0.2 | 1.5 |
| SHT85 | ~0.2 | 1.5 | | SHT85 | ~0.2 | 1.5 |
Need to investigate if the interface is identical? Need to investigate if the interface is identical?
If so the libraries might be merged. If so the libraries might be merged.
@ -75,15 +75,18 @@ Does read both the temperature and humidity.
- **uint16_t readStatus()** details see datasheet and **Status fields** below - **uint16_t readStatus()** details see datasheet and **Status fields** below
- **uint32_t lastRead()** in milliSeconds since start of program. - **uint32_t lastRead()** in milliSeconds since start of program.
- **reset(bool hard = false)** resets the sensor, soft reset by default. Returns false if fails. - **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. - **getHumidity()** computes the relative humidity in % based off the latest raw reading, and returns it
- **getTemperature()** returns temperature in °C. Needs a **read()** to update. - **getTemperature()** computes the temperature in °C based off the latest raw reading, and returns it
- **getRawHumidity()** returns the raw two-byte representation of humidity directly from the sensor
- **getRawTemperature()** returns the raw two-byte representation of temperature directly from the sensor
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 interface #### Error interface
- **getError()** returns last set error flag and clear it. - **getError()** returns last set error flag and clear it.
Be sure to clear the error flag by calling **getError()** before calling Be sure to clear the error flag by calling **getError()** before calling any command as the error flag could be from a previous command.
any command as the error flag could be from a previous command.
| Error | Symbolic | Description | | Error | Symbolic | Description |
|:----:|:----|:----| |:----:|:----|:----|
@ -97,7 +100,6 @@ any command as the error flag could be from a previous command.
| 0x87 | SHT_ERR_CRC_STATUS | CRC error in statusfield | | 0x87 | SHT_ERR_CRC_STATUS | CRC error in statusfield |
#### Heater interface #### Heater interface
Use the heater for max **180** seconds, and let it cool down an equal period of time. Use the heater for max **180** seconds, and let it cool down an equal period of time.
@ -121,7 +123,7 @@ Will switch heat off if max heating time has passed.
See async example for usage See async example for usage
- **requestData()** requests a new measurement. Returns false if this fails. - **requestData()** requests a new measurement. Returns false if this fails.
- **dataReady()** checks if enough time has passed to read the data. (typical 15 millis) - **dataReady()** checks if enough time has passed to read the data. (15 milliseconds)
- **readData(bool fast = true)** fast skips CRC check. Returns false if reading fails or in case of a CRC fail. - **readData(bool fast = true)** fast skips CRC check. Returns false if reading fails or in case of a CRC fail.
@ -129,8 +131,8 @@ See async example for usage
| BIT | Description | values | | BIT | Description | values |
|:----:|:----|:----| |:----:|:----|:----|
| 15 | Alert pending status | '0': no pending alerts| | 15 | Alert pending status | '0' : no pending alerts|
| | | '1': at least one pending alert - default | | | | '1' : at least one pending alert - default |
| 14 | Reserved | '0' | | 14 | Reserved | '0' |
| 13 | Heater status | '0 : Heater OFF - default | | 13 | Heater status | '0 : Heater OFF - default |
| | | '1 : Heater ON | | | | '1 : Heater ON |
@ -140,22 +142,22 @@ See async example for usage
| 10 | Temperature tracking alert | '0 : no alert - default | | 10 | Temperature tracking alert | '0 : no alert - default |
| | | '1 : alert | | | | '1 : alert |
| 9-5 | Reserved | '00000' | | 9-5 | Reserved | '00000' |
| 4 | System reset detected | '0': no reset since last clear status register command | | 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 | | | | '1' : reset detected (hard or soft reset command or supply fail) - default |
| 3-2 | Reserved | '00' | | 3-2 | Reserved | '00' |
| 1 | Command status | '0': last cmd executed successfully | | 1 | Command status | '0' : last command executed successfully |
| | | '1': last cmd not processed. Invalid or failed checksum | | | | '1' : last command not processed. Invalid or failed checksum |
| 0 | Write data checksum status | '0': checksum of last write correct | | 0 | Write data checksum status | '0' : checksum of last write correct |
| | | '1': checksum of last write transfer failed | | | | '1' : checksum of last write transfer failed |
## Future ## Future
- verify working with ESP32 - verify working with ESP32
- merge with other SHT sensors if possible - merge with other SHT sensors if possible
- SHT_BASE class ?
- investigate command ART (auto sampling at 4 Hz) - investigate command ART (auto sampling at 4 Hz)
- investigate command BREAK (stop auto sampling) - investigate command BREAK (stop auto sampling)
- direct Fahrenheit formula
## Operation ## Operation

View File

@ -1,7 +1,7 @@
// //
// FILE: SHT85.cpp // FILE: SHT85.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.2 // VERSION: 0.1.3
// DATE: 2021-02-10 // DATE: 2021-02-10
// PURPOSE: Arduino library for the SHT85 temperature and humidity sensor // PURPOSE: Arduino library for the SHT85 temperature and humidity sensor
// https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530 // https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530
@ -11,7 +11,8 @@
// HISTORY: // HISTORY:
// 0.1.0 2021-02-10 initial version // 0.1.0 2021-02-10 initial version
// 0.1.1 2021-03-13 initial release // 0.1.1 2021-03-13 initial release
// 0.1.2 2021-05-27 fix arduino-lint // 0.1.2 2021-05-27 fix Arduino-lint
// 0.1.3 2021-08-06 expose raw data from sensor
#include "SHT85.h" #include "SHT85.h"
@ -33,12 +34,12 @@
SHT85::SHT85() SHT85::SHT85()
{ {
_addr = 0; _addr = 0;
_lastRead = 0; _lastRead = 0;
temperature = 0; _rawTemperature = 0;
humidity = 0; _rawHumidity = 0;
_heaterStart = 0; _heaterStart = 0;
_error = SHT_OK; _error = SHT_OK;
} }
@ -118,8 +119,8 @@ bool SHT85::isConnected()
// '1': reset detected (hard or soft reset command or supply fail) - default // '1': reset detected (hard or soft reset command or supply fail) - default
// 3:2 Reserved 00 // 3:2 Reserved 00
// 1 Command status // 1 Command status
// '0': last cmd executed successfully // '0': last command executed successfully
// '1': last cmd not processed. Invalid or failed checksum // '1': last command not processed. Invalid or failed checksum
// 0 Write data checksum status // 0 Write data checksum status
// '0': checksum of last write correct // '0': checksum of last write correct
// '1': checksum of last write transfer failed // '1': checksum of last write transfer failed
@ -247,10 +248,8 @@ bool SHT85::readData(bool fast)
} }
} }
uint16_t raw = (buffer[0] << 8) + buffer[1]; _rawTemperature = (buffer[0] << 8) + buffer[1];
temperature = raw * (175.0 / 65535) - 45; _rawHumidity = (buffer[3] << 8) + buffer[4];
raw = (buffer[3] << 8) + buffer[4];
humidity = raw * (100.0 / 65535);
_lastRead = millis(); _lastRead = millis();

View File

@ -2,7 +2,7 @@
// //
// FILE: SHT85.h // FILE: SHT85.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.2 // VERSION: 0.1.3
// DATE: 2021-02-10 // DATE: 2021-02-10
// PURPOSE: Arduino library for the SHT85 temperature and humidity sensor // PURPOSE: Arduino library for the SHT85 temperature and humidity sensor
// https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530 // https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530
@ -12,7 +12,7 @@
// keep lib in sync with https://github.com/RobTillaart/SHT31 // keep lib in sync with https://github.com/RobTillaart/SHT31
// TOPVIEW // TOPVIEW SHT85
// +-------+ // +-------+
// +-----\ | SDA 4 ----- // +-----\ | SDA 4 -----
// | +-+ ----+ VCC 3 ----- // | +-+ ----+ VCC 3 -----
@ -25,7 +25,7 @@
#include "Wire.h" #include "Wire.h"
#define SHT85_LIB_VERSION (F("0.1.2")) #define SHT85_LIB_VERSION (F("0.1.3"))
// fields readStatus // fields readStatus
@ -61,7 +61,7 @@ public:
// blocks 15 milliseconds + actual read + math // blocks 15 milliseconds + actual read + math
bool read(bool fast = true); bool read(bool fast = true);
// check senosr is reachable over I2C // check sensor is reachable over I2C
bool isConnected(); bool isConnected();
// details see datasheet; summary in SHT31.cpp file // details see datasheet; summary in SHT31.cpp file
@ -80,8 +80,11 @@ public:
bool heatOff(); bool heatOff();
bool isHeaterOn(); // is the sensor still heating up? bool isHeaterOn(); // is the sensor still heating up?
float getHumidity() { return humidity; }; float getHumidity() { return _rawHumidity * (100.0 / 65535); };
float getTemperature() { return temperature; }; float getTemperature() { return _rawTemperature * (175.0 / 65535) - 45; };
// float getFahrenheit() { return _rawTemperature * (63.0 /13107.0) - 49; };
uint16_t getRawHumidity() {return _rawHumidity; };
uint16_t getRawTemperature() {return _rawTemperature; };
// ASYNC INTERFACE // ASYNC INTERFACE
bool requestData(); bool requestData();
@ -90,20 +93,21 @@ public:
int getError(); // clears error flag int getError(); // clears error flag
private: private:
uint8_t crc8(const uint8_t *data, uint8_t len); uint8_t crc8(const uint8_t *data, uint8_t len);
bool writeCmd(uint16_t cmd); bool writeCmd(uint16_t cmd);
bool readBytes(uint8_t n, uint8_t *val); bool readBytes(uint8_t n, uint8_t *val);
TwoWire* _wire; TwoWire* _wire;
uint8_t _addr; uint8_t _addr;
uint8_t _heatTimeOut; // seconds uint8_t _heatTimeOut; // seconds
uint32_t _lastRead; uint32_t _lastRead;
uint32_t _lastRequest; // for async interface uint32_t _lastRequest; // for async interface
uint32_t _heaterStart; uint32_t _heaterStart;
float humidity; uint16_t _rawHumidity;
float temperature; uint16_t _rawTemperature;
uint8_t _error; uint8_t _error;
}; };

View File

@ -24,6 +24,8 @@ requestData KEYWORD2
dataReady KEYWORD2 dataReady KEYWORD2
readData KEYWORD2 readData KEYWORD2
getRawHumidity KEYWORD2
getRawTemperature KEYWORD2
# Instances (KEYWORD2) # Instances (KEYWORD2)

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/SHT85" "url": "https://github.com/RobTillaart/SHT85"
}, },
"version": "0.1.2", "version": "0.1.3",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*"

View File

@ -1,5 +1,5 @@
name=SHT85 name=SHT85
version=0.1.2 version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the SHT85 temperature and humidity sensor sentence=Arduino library for the SHT85 temperature and humidity sensor

View File

@ -29,7 +29,6 @@
It appears that Wire.write does not fail without sensor... It appears that Wire.write does not fail without sensor...
*/ */
#include <ArduinoUnitTests.h> #include <ArduinoUnitTests.h>
#include "Arduino.h" #include "Arduino.h"
@ -39,7 +38,6 @@ int expect; // TODO needed as there seems a problem with 8 bit comparisons (cha
uint32_t start, stop; uint32_t start, stop;
unittest_setup() unittest_setup()
{ {
} }
@ -63,10 +61,14 @@ unittest(test_begin)
Serial.println(sht.getTemperature()); Serial.println(sht.getTemperature());
Serial.println(sht.getHumidity()); Serial.println(sht.getHumidity());
Serial.println(sht.getRawTemperature());
Serial.println(sht.getRawHumidity());
// default value == 0 // default value == 0
assertEqual(0, sht.getTemperature()); assertEqual(-45, sht.getTemperature());
assertEqual(0, sht.getHumidity()); assertEqual(0, sht.getHumidity());
assertEqual(0, sht.getRawTemperature());
assertEqual(0, sht.getRawHumidity());
} }
@ -162,5 +164,4 @@ unittest(test_async)
unittest_main() unittest_main()
// --------
// --------