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
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
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 read time becomes
quite small. (max 15% gain). See output example sketch.
| 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.
| 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 |
|:------:|:------:|:-----:|
| 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.
@ -75,15 +75,18 @@ Does read both the temperature and humidity.
- **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.
- **getHumidity()** computes the relative humidity in % based off the latest raw reading, and returns it
- **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
- **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.
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 |
|:----:|:----|:----|
@ -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 |
#### Heater interface
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
- **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.
@ -129,8 +131,8 @@ See async example for usage
| BIT | Description | values |
|:----:|:----|:----|
| 15 | Alert pending status | '0': no pending alerts|
| | | '1': at least one pending alert - default |
| 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 |
@ -140,22 +142,22 @@ See async example for usage
| 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 |
| 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 |
| 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 |
## Future
- verify working with ESP32
- merge with other SHT sensors if possible
- SHT_BASE class ?
- investigate command ART (auto sampling at 4 Hz)
- investigate command BREAK (stop auto sampling)
- direct Fahrenheit formula
## Operation

View File

@ -1,7 +1,7 @@
//
// FILE: SHT85.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// 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
@ -11,7 +11,8 @@
// HISTORY:
// 0.1.0 2021-02-10 initial version
// 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"
@ -33,12 +34,12 @@
SHT85::SHT85()
{
_addr = 0;
_lastRead = 0;
temperature = 0;
humidity = 0;
_heaterStart = 0;
_error = SHT_OK;
_addr = 0;
_lastRead = 0;
_rawTemperature = 0;
_rawHumidity = 0;
_heaterStart = 0;
_error = SHT_OK;
}
@ -118,8 +119,8 @@ bool SHT85::isConnected()
// '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': 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
@ -247,10 +248,8 @@ bool SHT85::readData(bool fast)
}
}
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);
_rawTemperature = (buffer[0] << 8) + buffer[1];
_rawHumidity = (buffer[3] << 8) + buffer[4];
_lastRead = millis();

View File

@ -2,7 +2,7 @@
//
// FILE: SHT85.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// 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
@ -12,7 +12,7 @@
// keep lib in sync with https://github.com/RobTillaart/SHT31
// TOPVIEW
// TOPVIEW SHT85
// +-------+
// +-----\ | SDA 4 -----
// | +-+ ----+ VCC 3 -----
@ -25,7 +25,7 @@
#include "Wire.h"
#define SHT85_LIB_VERSION (F("0.1.2"))
#define SHT85_LIB_VERSION (F("0.1.3"))
// fields readStatus
@ -61,7 +61,7 @@ public:
// blocks 15 milliseconds + actual read + math
bool read(bool fast = true);
// check senosr is reachable over I2C
// check sensor is reachable over I2C
bool isConnected();
// details see datasheet; summary in SHT31.cpp file
@ -80,8 +80,11 @@ public:
bool heatOff();
bool isHeaterOn(); // is the sensor still heating up?
float getHumidity() { return humidity; };
float getTemperature() { return temperature; };
float getHumidity() { return _rawHumidity * (100.0 / 65535); };
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
bool requestData();
@ -90,20 +93,21 @@ public:
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);
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;
uint8_t _addr;
uint8_t _heatTimeOut; // seconds
uint32_t _lastRead;
uint32_t _lastRequest; // for async interface
uint32_t _heaterStart;
float humidity;
float temperature;
uint16_t _rawHumidity;
uint16_t _rawTemperature;
uint8_t _error;
};

View File

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

View File

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

View File

@ -1,5 +1,5 @@
name=SHT85
version=0.1.2
version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
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...
*/
#include <ArduinoUnitTests.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;
unittest_setup()
{
}
@ -63,10 +61,14 @@ unittest(test_begin)
Serial.println(sht.getTemperature());
Serial.println(sht.getHumidity());
Serial.println(sht.getRawTemperature());
Serial.println(sht.getRawHumidity());
// default value == 0
assertEqual(0, sht.getTemperature());
assertEqual(-45, sht.getTemperature());
assertEqual(0, sht.getHumidity());
assertEqual(0, sht.getRawTemperature());
assertEqual(0, sht.getRawHumidity());
}
@ -162,5 +164,4 @@ unittest(test_async)
unittest_main()
// --------