Skip to content

Commit 4b93777

Browse files
committed
0.1.3 SHT85
1 parent 19e4633 commit 4b93777

File tree

7 files changed

+67
-59
lines changed

7 files changed

+67
-59
lines changed

libraries/SHT85/README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ not be used for more than 10% of the time.
2727
```
2828

2929
The SHT85 sensors should work up to 1000 KHz, however during tests
30-
with an Arduino UNO it stopped at ~500 KHz so to be safe I recommend
31-
not to use it above 400 KHz. Also the differences in readtime becomes
30+
with an Arduino UNO it stopped between 500 - 550 KHz so to be safe I recommend
31+
not to use it above 400 KHz. Also the differences in read time becomes
3232
quite small. (max 15% gain). See output example sketch.
3333

3434
| I2C speed | read ms | notes |
@@ -51,11 +51,11 @@ This library should also work for SHT30, SHT31 and SHT35 but
5151
this is not verified yet.
5252

5353
| SENSOR | Temperature accuracy | Humidity accuracy |
54-
|:----:|:----:|:----:|
55-
| SHT30 | ~0.3 | 2.0 |
56-
| SHT31 | ~0.3 | 1.5 |
57-
| SHT35 | ~0.2 | 1.5 |
58-
| SHT85 | ~0.2 | 1.5 |
54+
|:------:|:------:|:-----:|
55+
| SHT30 | ~0.3 | 2.0 |
56+
| SHT31 | ~0.3 | 1.5 |
57+
| SHT35 | ~0.2 | 1.5 |
58+
| SHT85 | ~0.2 | 1.5 |
5959

6060
Need to investigate if the interface is identical?
6161
If so the libraries might be merged.
@@ -75,15 +75,18 @@ Does read both the temperature and humidity.
7575
- **uint16_t readStatus()** details see datasheet and **Status fields** below
7676
- **uint32_t lastRead()** in milliSeconds since start of program.
7777
- **reset(bool hard = false)** resets the sensor, soft reset by default. Returns false if fails.
78-
- **getHumidity()** returns relative humidity in %. Needs a **read()** to update.
79-
- **getTemperature()** returns temperature in °C. Needs a **read()** to update.
78+
- **getHumidity()** computes the relative humidity in % based off the latest raw reading, and returns it
79+
- **getTemperature()** computes the temperature in °C based off the latest raw reading, and returns it
80+
- **getRawHumidity()** returns the raw two-byte representation of humidity directly from the sensor
81+
- **getRawTemperature()** returns the raw two-byte representation of temperature directly from the sensor
82+
83+
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.
8084

8185

8286
#### Error interface
8387

8488
- **getError()** returns last set error flag and clear it.
85-
Be sure to clear the error flag by calling **getError()** before calling
86-
any command as the error flag could be from a previous command.
89+
Be sure to clear the error flag by calling **getError()** before calling any command as the error flag could be from a previous command.
8790

8891
| Error | Symbolic | Description |
8992
|:----:|:----|:----|
@@ -97,7 +100,6 @@ any command as the error flag could be from a previous command.
97100
| 0x87 | SHT_ERR_CRC_STATUS | CRC error in statusfield |
98101

99102

100-
101103
#### Heater interface
102104

103105
Use the heater for max **180** seconds, and let it cool down an equal period of time.
@@ -121,16 +123,16 @@ Will switch heat off if max heating time has passed.
121123
See async example for usage
122124

123125
- **requestData()** requests a new measurement. Returns false if this fails.
124-
- **dataReady()** checks if enough time has passed to read the data. (typical 15 millis)
126+
- **dataReady()** checks if enough time has passed to read the data. (15 milliseconds)
125127
- **readData(bool fast = true)** fast skips CRC check. Returns false if reading fails or in case of a CRC fail.
126128

127129

128130
## Status fields
129131

130132
| BIT | Description | values |
131133
|:----:|:----|:----|
132-
| 15 | Alert pending status | '0': no pending alerts|
133-
| | | '1': at least one pending alert - default |
134+
| 15 | Alert pending status | '0' : no pending alerts|
135+
| | | '1' : at least one pending alert - default |
134136
| 14 | Reserved | '0' |
135137
| 13 | Heater status | '0’ : Heater OFF - default |
136138
| | | '1’ : Heater ON |
@@ -140,22 +142,22 @@ See async example for usage
140142
| 10 | Temperature tracking alert | '0’ : no alert - default |
141143
| | | '1’ : alert |
142144
| 9-5 | Reserved | '00000' |
143-
| 4 | System reset detected | '0': no reset since last ‘clear status register’ command |
144-
| | | '1': reset detected (hard or soft reset command or supply fail) - default |
145+
| 4 | System reset detected | '0' : no reset since last ‘clear status register’ command |
146+
| | | '1' : reset detected (hard or soft reset command or supply fail) - default |
145147
| 3-2 | Reserved | '00' |
146-
| 1 | Command status | '0': last cmd executed successfully |
147-
| | | '1': last cmd not processed. Invalid or failed checksum |
148-
| 0 | Write data checksum status | '0': checksum of last write correct |
149-
| | | '1': checksum of last write transfer failed |
148+
| 1 | Command status | '0' : last command executed successfully |
149+
| | | '1' : last command not processed. Invalid or failed checksum |
150+
| 0 | Write data checksum status | '0' : checksum of last write correct |
151+
| | | '1' : checksum of last write transfer failed |
150152

151153

152154
## Future
153155

154156
- verify working with ESP32
155157
- merge with other SHT sensors if possible
158+
- SHT_BASE class ?
156159
- investigate command ART (auto sampling at 4 Hz)
157160
- investigate command BREAK (stop auto sampling)
158-
- direct Fahrenheit formula
159161

160162

161163
## Operation

libraries/SHT85/SHT85.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: SHT85.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.2
4+
// VERSION: 0.1.3
55
// DATE: 2021-02-10
66
// PURPOSE: Arduino library for the SHT85 temperature and humidity sensor
77
// https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530
@@ -11,7 +11,8 @@
1111
// HISTORY:
1212
// 0.1.0 2021-02-10 initial version
1313
// 0.1.1 2021-03-13 initial release
14-
// 0.1.2 2021-05-27 fix arduino-lint
14+
// 0.1.2 2021-05-27 fix Arduino-lint
15+
// 0.1.3 2021-08-06 expose raw data from sensor
1516

1617

1718
#include "SHT85.h"
@@ -33,12 +34,12 @@
3334

3435
SHT85::SHT85()
3536
{
36-
_addr = 0;
37-
_lastRead = 0;
38-
temperature = 0;
39-
humidity = 0;
40-
_heaterStart = 0;
41-
_error = SHT_OK;
37+
_addr = 0;
38+
_lastRead = 0;
39+
_rawTemperature = 0;
40+
_rawHumidity = 0;
41+
_heaterStart = 0;
42+
_error = SHT_OK;
4243
}
4344

4445

@@ -118,8 +119,8 @@ bool SHT85::isConnected()
118119
// '1': reset detected (hard or soft reset command or supply fail) - default
119120
// 3:2 Reserved ‘00’
120121
// 1 Command status
121-
// '0': last cmd executed successfully
122-
// '1': last cmd not processed. Invalid or failed checksum
122+
// '0': last command executed successfully
123+
// '1': last command not processed. Invalid or failed checksum
123124
// 0 Write data checksum status
124125
// '0': checksum of last write correct
125126
// '1': checksum of last write transfer failed
@@ -247,10 +248,8 @@ bool SHT85::readData(bool fast)
247248
}
248249
}
249250

250-
uint16_t raw = (buffer[0] << 8) + buffer[1];
251-
temperature = raw * (175.0 / 65535) - 45;
252-
raw = (buffer[3] << 8) + buffer[4];
253-
humidity = raw * (100.0 / 65535);
251+
_rawTemperature = (buffer[0] << 8) + buffer[1];
252+
_rawHumidity = (buffer[3] << 8) + buffer[4];
254253

255254
_lastRead = millis();
256255

libraries/SHT85/SHT85.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: SHT85.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.2
5+
// VERSION: 0.1.3
66
// DATE: 2021-02-10
77
// PURPOSE: Arduino library for the SHT85 temperature and humidity sensor
88
// https://nl.rs-online.com/web/p/temperature-humidity-sensor-ics/1826530
@@ -12,7 +12,7 @@
1212
// keep lib in sync with https://github.com/RobTillaart/SHT31
1313

1414

15-
// TOPVIEW
15+
// TOPVIEW SHT85
1616
// +-------+
1717
// +-----\ | SDA 4 -----
1818
// | +-+ ----+ VCC 3 -----
@@ -25,7 +25,7 @@
2525
#include "Wire.h"
2626

2727

28-
#define SHT85_LIB_VERSION (F("0.1.2"))
28+
#define SHT85_LIB_VERSION (F("0.1.3"))
2929

3030

3131
// fields readStatus
@@ -61,7 +61,7 @@ class SHT85
6161
// blocks 15 milliseconds + actual read + math
6262
bool read(bool fast = true);
6363

64-
// check senosr is reachable over I2C
64+
// check sensor is reachable over I2C
6565
bool isConnected();
6666

6767
// details see datasheet; summary in SHT31.cpp file
@@ -80,8 +80,11 @@ class SHT85
8080
bool heatOff();
8181
bool isHeaterOn(); // is the sensor still heating up?
8282

83-
float getHumidity() { return humidity; };
84-
float getTemperature() { return temperature; };
83+
float getHumidity() { return _rawHumidity * (100.0 / 65535); };
84+
float getTemperature() { return _rawTemperature * (175.0 / 65535) - 45; };
85+
// float getFahrenheit() { return _rawTemperature * (63.0 /13107.0) - 49; };
86+
uint16_t getRawHumidity() {return _rawHumidity; };
87+
uint16_t getRawTemperature() {return _rawTemperature; };
8588

8689
// ASYNC INTERFACE
8790
bool requestData();
@@ -90,20 +93,21 @@ class SHT85
9093

9194
int getError(); // clears error flag
9295

96+
9397
private:
94-
uint8_t crc8(const uint8_t *data, uint8_t len);
95-
bool writeCmd(uint16_t cmd);
96-
bool readBytes(uint8_t n, uint8_t *val);
98+
uint8_t crc8(const uint8_t *data, uint8_t len);
99+
bool writeCmd(uint16_t cmd);
100+
bool readBytes(uint8_t n, uint8_t *val);
97101
TwoWire* _wire;
98102

99-
uint8_t _addr;
100-
uint8_t _heatTimeOut; // seconds
101-
uint32_t _lastRead;
102-
uint32_t _lastRequest; // for async interface
103-
uint32_t _heaterStart;
103+
uint8_t _addr;
104+
uint8_t _heatTimeOut; // seconds
105+
uint32_t _lastRead;
106+
uint32_t _lastRequest; // for async interface
107+
uint32_t _heaterStart;
104108

105-
float humidity;
106-
float temperature;
109+
uint16_t _rawHumidity;
110+
uint16_t _rawTemperature;
107111

108112
uint8_t _error;
109113
};

libraries/SHT85/keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ requestData KEYWORD2
2424
dataReady KEYWORD2
2525
readData KEYWORD2
2626

27+
getRawHumidity KEYWORD2
28+
getRawTemperature KEYWORD2
2729

2830
# Instances (KEYWORD2)
2931

libraries/SHT85/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/SHT85"
1717
},
18-
"version": "0.1.2",
18+
"version": "0.1.3",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*"

libraries/SHT85/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SHT85
2-
version=0.1.2
2+
version=0.1.3
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for the SHT85 temperature and humidity sensor

libraries/SHT85/test/unit_test_001.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
It appears that Wire.write does not fail without sensor...
3030
*/
3131

32-
3332
#include <ArduinoUnitTests.h>
3433

3534
#include "Arduino.h"
@@ -39,7 +38,6 @@ int expect; // TODO needed as there seems a problem with 8 bit comparisons (cha
3938

4039
uint32_t start, stop;
4140

42-
4341
unittest_setup()
4442
{
4543
}
@@ -63,10 +61,14 @@ unittest(test_begin)
6361

6462
Serial.println(sht.getTemperature());
6563
Serial.println(sht.getHumidity());
64+
Serial.println(sht.getRawTemperature());
65+
Serial.println(sht.getRawHumidity());
6666

6767
// default value == 0
68-
assertEqual(0, sht.getTemperature());
68+
assertEqual(-45, sht.getTemperature());
6969
assertEqual(0, sht.getHumidity());
70+
assertEqual(0, sht.getRawTemperature());
71+
assertEqual(0, sht.getRawHumidity());
7072
}
7173

7274

@@ -162,5 +164,4 @@ unittest(test_async)
162164

163165
unittest_main()
164166

165-
166-
// --------
167+
// --------

0 commit comments

Comments
 (0)