0.2.0 SHT31_SW

This commit is contained in:
Rob Tillaart 2023-12-09 19:54:36 +01:00
parent 2d93065d5e
commit f04075ab5b
15 changed files with 60 additions and 57 deletions

View File

@ -6,10 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.0] - 2023-12-09
- refactor API, follow SHT31
----
## [0.1.3] - 2023-11-22 ## [0.1.3] - 2023-11-22
- update readme.md - update readme.md
## [0.1.2] - 2023-07-23 ## [0.1.2] - 2023-07-23
- update documentation - update documentation
- remove commented **SoftwareWire** version => own repo. - remove commented **SoftwareWire** version => own repo.

View File

@ -59,6 +59,12 @@ Test on UNO
| SHT85 | ~0.2 | 1.5 | no | See SHT31_SWW | SHT85 | ~0.2 | 1.5 | no | See SHT31_SWW
#### 0.2.0 Breaking change
Version 0.2.0 introduced a breaking change in constructor and begin().
Parameters have moved from begin() to the constructor.
#### Related #### Related
These libraries need to be installed to get SHT31_SW working: These libraries need to be installed to get SHT31_SW working:

View File

@ -1,7 +1,7 @@
// //
// FILE: SHT31_SW.cpp // FILE: SHT31_SW.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart, Gunter Haug
// VERSION: 0.1.3 // VERSION: 0.2.0
// DATE: 2019-02-08 (base SHT31 lib) // DATE: 2019-02-08 (base SHT31 lib)
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor // PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
// to be used with the SoftWire library instead of (hardware) Wire. // to be used with the SoftWire library instead of (hardware) Wire.
@ -14,10 +14,10 @@
#include "SHT31_SW.h" #include "SHT31_SW.h"
SHT31_SW::SHT31_SW() SHT31_SW::SHT31_SW(const uint8_t address, SoftWire *softWire)
{ {
_softWire = NULL; _address = address;
_address = 0; _softWire = softWire;
_lastRead = 0; _lastRead = 0;
_rawTemperature = 0; _rawTemperature = 0;
_rawHumidity = 0; _rawHumidity = 0;
@ -29,25 +29,17 @@ SHT31_SW::SHT31_SW()
} }
bool SHT31_SW::begin(const uint8_t address, SoftWire *softWire) bool SHT31_SW::begin()
{ {
if ((address != 0x44) && (address != 0x45)) if ((_address != 0x44) && (_address != 0x45))
{ {
return false; return false;
} }
_address = address;
_softWire = softWire;
_softWire->begin(); _softWire->begin();
return reset(); return reset();
} }
bool SHT31_SW::begin(SoftWire *softWire)
{
return begin(SHT_DEFAULT_ADDRESS, softWire);
}
bool SHT31_SW::isConnected() bool SHT31_SW::isConnected()
{ {
_softWire->beginTransmission(_address); _softWire->beginTransmission(_address);

View File

@ -2,7 +2,7 @@
// //
// FILE: SHT31_SW.h // FILE: SHT31_SW.h
// AUTHOR: Rob Tillaart, Gunter Haug // AUTHOR: Rob Tillaart, Gunter Haug
// VERSION: 0.1.3 // VERSION: 0.2.0
// DATE: 2019-02-08 (base SHT31 lib) // DATE: 2019-02-08 (base SHT31 lib)
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor // PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
// to be used with the SoftWire library instead of (hardware) Wire. // to be used with the SoftWire library instead of (hardware) Wire.
@ -12,7 +12,7 @@
// https://github.com/RobTillaart/SHT31 // https://github.com/RobTillaart/SHT31
#define SHT31_SW_LIB_VERSION (F("0.1.3")) #define SHT31_SW_LIB_VERSION (F("0.2.0"))
#include "Arduino.h" #include "Arduino.h"
@ -23,11 +23,8 @@
class SHT31_SW : public SHT31 class SHT31_SW : public SHT31
{ {
public: public:
SHT31_SW(); SHT31_SW(uint8_t address, SoftWire *wire);
bool begin();
// use SHT_DEFAULT_ADDRESS
bool begin(const uint8_t address, SoftWire *wire);
bool begin(SoftWire *wire);
// check if sensor is reachable over I2C // check if sensor is reachable over I2C
bool isConnected(); bool isConnected();

View File

@ -16,7 +16,7 @@ SoftWire sw(6, 7);
uint32_t start; uint32_t start;
uint32_t stop; uint32_t stop;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup() void setup()
@ -27,8 +27,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION); Serial.println(SHT31_SW_LIB_VERSION);
sw.begin(); sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000); sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus(); uint16_t stat = sht.readStatus();
Serial.print(stat, HEX); Serial.print(stat, HEX);
@ -58,7 +58,7 @@ void test()
Serial.print(sht.getTemperature(), 1); Serial.print(sht.getTemperature(), 1);
Serial.print("\t"); Serial.print("\t");
Serial.println(sht.getHumidity(), 1); Serial.println(sht.getHumidity(), 1);
delay(100); delay(1000);
} }

View File

@ -17,7 +17,7 @@ uint32_t start;
uint32_t stop; uint32_t stop;
uint32_t cnt; uint32_t cnt;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup() void setup()
@ -28,8 +28,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION); Serial.println(SHT31_SW_LIB_VERSION);
sw.begin(); sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000); sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus(); uint16_t stat = sht.readStatus();
Serial.print(stat, HEX); Serial.print(stat, HEX);
@ -45,9 +45,9 @@ void loop()
if (sht.dataReady()) if (sht.dataReady())
{ {
start = micros(); start = micros();
bool success = sht.readData(); // default = true = fast bool success = sht.readData(); // default = true = fast
stop = micros(); stop = micros();
sht.requestData(); // request for next sample sht.requestData(); // request for next sample
Serial.print("\t"); Serial.print("\t");
Serial.print(stop - start); Serial.print(stop - start);
@ -66,8 +66,8 @@ void loop()
cnt = 0; cnt = 0;
} }
} }
cnt++; // simulate other activity cnt++; // simulate other activity
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -16,7 +16,7 @@ SoftWire sw(6, 7);
uint32_t start; uint32_t start;
uint32_t stop; uint32_t stop;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup() void setup()
@ -28,7 +28,7 @@ void setup()
sw.begin(); sw.begin();
sw.setClock(100000); sw.setClock(100000);
sht.begin(SHT31_ADDRESS, &sw); sht.begin();
Serial.print("CON:\t"); Serial.print("CON:\t");
Serial.println(sht.isConnected()); Serial.println(sht.isConnected());

View File

@ -16,7 +16,7 @@ SoftWire sw(6, 7);
uint32_t start; uint32_t start;
uint32_t stop; uint32_t stop;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
uint16_t status; uint16_t status;
@ -28,10 +28,10 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION); Serial.println(SHT31_SW_LIB_VERSION);
sw.begin(); sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000); sw.setClock(100000);
sht.begin();
sht.setHeatTimeout(30); // heater timeout 30 seconds, just for demo. sht.setHeatTimeout(30); // heater timeout 30 seconds, just for demo.
status = sht.readStatus(); status = sht.readStatus();
printHeaterStatus(status); printHeaterStatus(status);
@ -71,4 +71,4 @@ void printHeaterStatus(uint16_t status)
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -17,7 +17,7 @@ uint32_t start;
uint32_t stop; uint32_t stop;
uint32_t connectionFails = 0; uint32_t connectionFails = 0;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup() void setup()
@ -28,8 +28,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION); Serial.println(SHT31_SW_LIB_VERSION);
sw.begin(); sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000); sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus(); uint16_t stat = sht.readStatus();
Serial.print(stat, HEX); Serial.print(stat, HEX);

View File

@ -16,7 +16,7 @@ SoftWire sw(6, 7);
uint32_t start; uint32_t start;
uint32_t stop; uint32_t stop;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup() void setup()
@ -27,8 +27,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION); Serial.println(SHT31_SW_LIB_VERSION);
sw.begin(); sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000); sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus(); uint16_t stat = sht.readStatus();
@ -39,7 +39,7 @@ void setup()
void loop() void loop()
{ {
sht.read(); // default = true/fast slow = false sht.read(); // default = true/fast slow = false
Serial.print("\t"); Serial.print("\t");
Serial.print(sht.lastRead()); Serial.print(sht.lastRead());
Serial.print("\t"); Serial.print("\t");
@ -50,5 +50,5 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -17,7 +17,7 @@ uint32_t start;
uint32_t stop; uint32_t stop;
uint32_t cnt; uint32_t cnt;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup() void setup()
@ -28,8 +28,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION); Serial.println(SHT31_SW_LIB_VERSION);
sw.begin(); sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000); sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus(); uint16_t stat = sht.readStatus();
@ -49,9 +49,9 @@ void loop()
if (sht.dataReady()) if (sht.dataReady())
{ {
start = micros(); start = micros();
bool success = sht.readData(); // default = true = fast bool success = sht.readData(); // default = true = fast
stop = micros(); stop = micros();
sht.requestData(); // request for next sample sht.requestData(); // request for next sample
Serial.print("\t"); Serial.print("\t");
Serial.print(stop - start); Serial.print(stop - start);
@ -66,19 +66,23 @@ void loop()
rawHumidity = sht.getRawHumidity(); rawHumidity = sht.getRawHumidity();
Serial.print(rawTemperature, HEX); Serial.print(rawTemperature, HEX);
Serial.print(" = "); Serial.print(" = ");
Serial.print(rawTemperature * (175.0 / 65535) - 45, 1); // This formula comes from page 14 of the SHT31 datasheet
// This formula comes from page 14 of the SHT31 datasheet
Serial.print(rawTemperature * (175.0 / 65535) - 45, 1);
Serial.print("°C\t"); Serial.print("°C\t");
Serial.print(sht.getRawHumidity(), HEX); Serial.print(sht.getRawHumidity(), HEX);
Serial.print(" = "); Serial.print(" = ");
Serial.print(rawHumidity * (100.0 / 65535), 1); // This formula comes from page 14 of the SHT31 datasheet
// This formula comes from page 14 of the SHT31 datasheet
Serial.print(rawHumidity * (100.0 / 65535), 1);
Serial.print("%\t"); Serial.print("%\t");
Serial.println(cnt); Serial.println(cnt);
cnt = 0; cnt = 0;
} }
} }
cnt++; // simulate other activity cnt++; // simulate other activity
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -16,7 +16,7 @@ SoftWire sw(6, 7);
uint32_t start; uint32_t start;
uint32_t stop; uint32_t stop;
SHT31_SW sht; SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup() void setup()
@ -27,8 +27,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION); Serial.println(SHT31_SW_LIB_VERSION);
sw.begin(); sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000); sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus(); uint16_t stat = sht.readStatus();
Serial.print(stat, HEX); Serial.print(stat, HEX);

View File

@ -31,7 +31,7 @@
"version": "^1.1.2" "version": "^1.1.2"
} }
], ],
"version": "0.1.3", "version": "0.2.0",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=SHT31_SW name=SHT31_SW
version=0.1.3 version=0.2.0
author=Rob Tillaart <rob.tillaart@gmail.com>, Gunter Haug author=Rob Tillaart <rob.tillaart@gmail.com>, Gunter Haug
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the I2C SHT31 temperature and humidity sensor sentence=Arduino library for the I2C SHT31 temperature and humidity sensor

View File

@ -36,7 +36,7 @@
#include "SHT31_SW.h" #include "SHT31_SW.h"
int expect; // TODO needed as there seems a problem with 8 bit comparisons (char?) int expect; // TODO needed as there seems a problem with 8 bit comparisons (char?)
uint32_t start, stop; uint32_t start, stop;