0.6.0 SHT85

This commit is contained in:
Rob Tillaart 2023-12-10 10:07:39 +01:00
parent e813875d60
commit 070fe385a2
13 changed files with 112 additions and 118 deletions

View File

@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.6.0] - 2023-12-09
- refactor API, move parameters from begin() to constructor
- update readme.md
- update examples
- minor edits
----
## [0.5.1] - 2023-09-21
- fix #21, again ...

View File

@ -93,8 +93,17 @@ This means you need to use multiple I2C buses (if your board support this),
a software I2C (below) or an I2C multiplexer e.g. https://github.com/RobTillaart/TCA9548
#### 0.6.0 Breaking change
#### Related libraries
Version 0.6.0 introduced a breaking change.
The parameters from begin() moved to the constructor.
You cannot set the pins in **begin()** any more.
This reduces the dependency of processor dependent Wire implementations.
The user has to call **Wire.begin()** and can optionally set the Wire pins
before calling **begin()**.
#### Related
- https://github.com/RobTillaart/SHT2x
- https://github.com/RobTillaart/SHT31
@ -118,22 +127,22 @@ I2C multiplexer
```
#### Base interface
#### Constructor
- **SHT(TwoWire \*wire = &Wire)** constructor of the base class. **getType()** will return 0.
- **SHT30(TwoWire \*wire = &Wire)** constructor. Optional select the I2C bus (Wire, Wire1 etc).
- **SHT31(TwoWire \*wire = &Wire)** constructor. Optional select the I2C bus (Wire, Wire1 etc).
- **SHT35(TwoWire \*wire = &Wire)** constructor. Optional select the I2C bus (Wire, Wire1 etc).
- **SHT85(TwoWire \*wire = &Wire)** constructor. Optional select the I2C bus (Wire, Wire1 etc).
- **SHT(uint8_t address, TwoWire \*wire = &Wire)** constructor of the base class.
Note that **getType()** will return 0.
- **SHT30(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
- **SHT31(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
- **SHT35(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
- **SHT85(uint8_t address, TwoWire \*wire = &Wire)** constructor.
Optional select the address and the I2C bus (Wire, Wire1 etc).
- **uint8_t getType()** returns numeric part of sensor type.
Returns 0 for the base class.
- **bool begin(uint8_t address, uint8_t dataPin, uint8_t clockPin)** begin function for ESP8266, ESP32 and similar.
**WARNING: not verified yet**.
Returns false if device address is incorrect or device cannot be reset.
- **bool begin(uint8_t dataPin, uint8_t clockPin)** same as above.
Uses SHT_DEFAULT_ADDRESS (0x44) as address.
- **bool begin(uint8_t address = SHT_DEFAULT_ADDRESS)**
Returns false if device address is incorrect or device cannot be reset.
- **bool begin()** Returns false if device address is incorrect or device cannot be reset.
- **uint8_t getAddress()** returns address set in constructor.
#### Status
@ -295,6 +304,7 @@ Will switch the heater off if maximum heating time has passed.
#### Must
- improve documentation.
- reorder interface
#### Should
@ -302,7 +312,7 @@ Will switch the heater off if maximum heating time has passed.
- more testing (including heater)
- verify working with ESP32
- support for medium level read.
- 3 levels iso 2.
- 3 levels instead of 2.
#### Could

View File

@ -1,7 +1,7 @@
//
// FILE: SHT85.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.5.1
// VERSION: 0.6.0
// 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
@ -29,9 +29,9 @@
#define SHT_GET_SERIAL 0x3682
SHT::SHT(TwoWire *wire)
SHT::SHT(uint8_t address, TwoWire *wire)
{
_address = 0;
_address = address;
_wire = wire;
_lastRead = 0;
_rawTemperature = 0;
@ -47,42 +47,20 @@ SHT::SHT(TwoWire *wire)
}
#if defined(ESP8266) || defined(ESP32)
bool SHT::begin(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)
bool SHT::begin()
{
if ((address != 0x44) && (address != 0x45))
if ((_address != 0x44) && (_address != 0x45))
{
return false;
}
_address = address;
if ((dataPin < 255) && (clockPin < 255))
{
_wire->begin(dataPin, clockPin);
} else {
_wire->begin();
}
return reset();
}
bool SHT::begin(const uint8_t dataPin, const uint8_t clockPin)
uint8_t SHT::getAddress()
{
return begin(SHT_DEFAULT_ADDRESS, dataPin, clockPin);
}
#endif
bool SHT::begin(const uint8_t address)
{
if ((address != 0x44) && (address != 0x45))
{
return false;
}
_address = address;
_wire->begin();
return reset();
}
return _address;
};
uint8_t SHT::getType()
@ -453,42 +431,34 @@ bool SHT::readBytes(uint8_t n, uint8_t *val)
//
// DERIVED CLASSES
//
SHT30::SHT30(TwoWire *wire) : SHT(wire)
SHT30::SHT30(uint8_t address, TwoWire *wire) : SHT(address, wire)
{
_type = 30;
}
SHT31::SHT31(TwoWire *wire) : SHT(wire)
SHT31::SHT31(uint8_t address, TwoWire *wire) : SHT(address, wire)
{
_type = 31;
}
SHT35::SHT35(TwoWire *wire) : SHT(wire)
SHT35::SHT35(uint8_t address, TwoWire *wire) : SHT(address, wire)
{
_type = 35;
}
SHT85::SHT85(TwoWire *wire) : SHT(wire)
SHT85::SHT85(uint8_t address, TwoWire *wire) : SHT(address, wire)
{
_type = 85;
}
#if defined(ESP8266) || defined(ESP32)
bool SHT85::begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin)
{
if (address != 0x44) return false;
return SHT::begin(SHT_DEFAULT_ADDRESS, dataPin, clockPin);
}
#endif
bool SHT85::begin(const uint8_t address)
bool SHT85::begin()
{
if (address != 0x44) return false;
return SHT::begin(address);
if (_address != 0x44) return false;
return SHT::begin();
}

View File

@ -2,7 +2,7 @@
//
// FILE: SHT85.h
// AUTHOR: Rob Tillaart
// VERSION: 0.5.1
// VERSION: 0.6.0
// 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
@ -25,7 +25,7 @@
#include "Wire.h"
#define SHT_LIB_VERSION (F("0.5.1"))
#define SHT_LIB_VERSION (F("0.6.0"))
#define SHT85_LIB_VERSION SHT_LIB_VERSION
#ifndef SHT_DEFAULT_ADDRESS
@ -58,16 +58,10 @@
class SHT
{
public:
SHT(TwoWire *wire = &Wire);
#if defined(ESP8266) || defined(ESP32)
bool begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin);
// use SHT_DEFAULT_ADDRESS
bool begin(const uint8_t dataPin, const uint8_t clockPin);
#endif
bool begin(const uint8_t address = SHT_DEFAULT_ADDRESS);
SHT(uint8_t address, TwoWire *wire = &Wire);
bool begin();
uint8_t getAddress();
uint8_t getType();
@ -160,36 +154,33 @@ protected:
class SHT30 : public SHT
{
public:
SHT30(TwoWire *wire = &Wire);
SHT30(uint8_t address, TwoWire *wire = &Wire);
};
class SHT31 : public SHT
{
public:
SHT31(TwoWire *wire = &Wire);
SHT31(uint8_t address, TwoWire *wire = &Wire);
};
class SHT35 : public SHT
{
public:
SHT35(TwoWire *wire = &Wire);
SHT35(uint8_t address, TwoWire *wire = &Wire);
};
class SHT85 : public SHT
{
public:
SHT85(TwoWire *wire = &Wire);
SHT85(uint8_t address, TwoWire *wire = &Wire);
// catch incorrect calls with an address, only 0x44 allowed, see #19
#if defined(ESP8266) || defined(ESP32)
bool begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin);
#endif
bool begin(const uint8_t address = SHT_DEFAULT_ADDRESS);
// catch incorrect calls with an address, only 0x44 allowed, see #19
bool begin();
// EXPERIMENTAL for 0.4.1
// EXPERIMENTAL for 0.4.1
uint32_t GetSerialNumber();
};

View File

@ -20,7 +20,7 @@
uint32_t start;
uint32_t stop;
SHT85 sht;
SHT85 sht(SHT85_ADDRESS);
void setup()
@ -31,12 +31,13 @@ void setup()
Serial.println(SHT_LIB_VERSION);
Wire.begin();
sht.begin(SHT85_ADDRESS);
Wire.setClock(100000);
sht.begin();
for (uint32_t clk = 50000; clk < 550000; clk += 50000)
{
Wire.setClock(clk);
start = micros();
sht.read(); // default = true/fast slow = false
sht.read(); // default = true/fast slow = false
stop = micros();
Serial.print(clk);
Serial.print("\t");

View File

@ -20,7 +20,7 @@
uint32_t start;
uint32_t stop;
SHT85 sht;
SHT85 sht(SHT85_ADDRESS);
void setup()
@ -31,8 +31,8 @@ void setup()
Serial.println(SHT_LIB_VERSION);
Wire.begin();
sht.begin(SHT85_ADDRESS);
Wire.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);
@ -48,7 +48,7 @@ void setup()
void loop()
{
start = micros();
sht.read(); // default = true/fast slow = false
sht.read(); // default = true/fast slow = false
stop = micros();
Serial.print("\t");
@ -61,5 +61,5 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -20,7 +20,7 @@
#define SHT85_ADDRESS 0x44
SHT85 sht;
SHT85 sht(SHT85_ADDRESS);
void setup()
@ -31,8 +31,8 @@ void setup()
Serial.println(SHT_LIB_VERSION);
Wire.begin();
sht.begin(SHT85_ADDRESS);
Wire.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);
@ -57,7 +57,7 @@ void loop()
Serial.println(sht.getHumidity(), 1);
sht.requestData();
}
delay(1000); // do not call sensor too often (see datasheet)
delay(10000); // do not call sensor too often (see datasheet)
}

View File

@ -23,7 +23,7 @@ uint32_t stop;
uint16_t count = 0;
uint32_t last = 0;
SHT85 sht;
SHT85 sht(SHT85_ADDRESS);
void setup()
@ -34,8 +34,8 @@ void setup()
Serial.println(SHT_LIB_VERSION);
Wire.begin();
sht.begin(SHT85_ADDRESS);
Wire.setClock(100000);
sht.begin();
// uint16_t stat = sht.readStatus();
// Serial.print(stat, HEX);

View File

@ -23,8 +23,8 @@ uint32_t stop;
uint16_t count = 0;
uint32_t last = 0;
// SHT85 sht(&Wire1);
SHT85 sht;
// SHT85 sht(SHT85_ADDRESS, &Wire1);
SHT85 sht(SHT85_ADDRESS);
void setup()
@ -35,8 +35,8 @@ void setup()
// Serial.println(SHT_LIB_VERSION);
Wire.begin();
sht.begin(SHT85_ADDRESS);
Wire.setClock(100000);
sht.begin();
// uint16_t stat = sht.readStatus();
// Serial.print(stat, HEX);
@ -48,7 +48,7 @@ void setup()
void loop()
{
start = micros();
sht.read(); // default = true/fast slow = false
sht.read(); // default = true/fast slow = false
stop = micros();
Serial.print("\t");

View File

@ -18,9 +18,10 @@
#include "TCA9548.h"
TCA9548 MP(0x70);
#define SHT85_ADDRESS 0x44
SHT85 sht; // the object is reused in the multiplexing.
SHT85 sht(SHT85_ADDRESS); // the object is reused in the multiplexing.
void setup()
{
@ -45,7 +46,7 @@ void setup()
{
Serial.print(channel);
MP.selectChannel(channel); // rotate over all SHT85's
if (sht.begin(0x44) == false)
if (sht.begin() == false)
{
Serial.println("\tconnect error.");;
}
@ -66,7 +67,7 @@ void loop()
Serial.print("\t");
for (int channel = 0; channel < 4; channel++)
{
sht.read(); // default = true/fast slow = false
sht.read(); // default = true/fast slow = false
Serial.print(sht.getTemperature(), 1);
Serial.print("\t");
Serial.print(sht.getHumidity(), 1);

View File

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

View File

@ -1,5 +1,5 @@
name=SHT85
version=0.5.1
version=0.6.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the SHT85, SHT30, SHT31, SHT35 Sensirion temperature and humidity sensors and compatibles.

View File

@ -85,8 +85,10 @@ unittest(test_constants_2)
unittest(test_begin)
{
SHT85 sht;
bool b = sht.begin(0x44);
SHT85 sht(0x44);
Wire.begin();
bool b = sht.begin();
assertEqual(b, true);
assertTrue(sht.reset());
@ -109,8 +111,10 @@ unittest(test_begin)
unittest(test_read)
{
SHT85 sht;
bool b = sht.begin(0x44);
SHT85 sht(0x44);
Wire.begin();
bool b = sht.begin();
assertEqual(b, true);
assertTrue(sht.isConnected());
@ -121,8 +125,10 @@ unittest(test_read)
unittest(test_readStatus)
{
SHT85 sht;
bool b = sht.begin(0x44);
SHT85 sht(0x44);
Wire.begin();
bool b = sht.begin();
assertEqual(b, true);
assertEqual(0xFFFF, sht.readStatus());
@ -133,8 +139,10 @@ unittest(test_readStatus)
unittest(test_heater)
{
SHT85 sht;
bool b = sht.begin(0x44);
SHT85 sht(0x44);
Wire.begin();
bool b = sht.begin();
assertEqual(b, true);
assertTrue(sht.heatOn());
@ -153,8 +161,10 @@ unittest(test_heater)
unittest(test_async)
{
SHT85 sht;
bool b = sht.begin(0x44);
SHT85 sht(0x44);
Wire.begin();
bool b = sht.begin();
assertEqual(b, true);
assertTrue(sht.requestData());
@ -182,7 +192,10 @@ unittest(test_async)
unittest(test_offset)
{
SHT85 sht;
SHT85 sht(0x44);
Wire.begin();
bool b = sht.begin();
fprintf(stderr, "temperature\n");
for (int i = -5; i < 6; i++)
{
@ -204,11 +217,11 @@ unittest(test_offset)
//
unittest(test_getType)
{
SHT sht;
SHT30 sht0;
SHT31 sht1;
SHT35 sht2;
SHT85 sht3;
SHT sht(0x44);
SHT30 sht0(0x44);
SHT31 sht1(0x44);
SHT35 sht2(0x44);
SHT85 sht3(0x44);
assertEqual(00, sht.getType());
assertEqual(30, sht0.getType());