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/).
## [0.2.0] - 2023-12-09
- refactor API, follow SHT31
----
## [0.1.3] - 2023-11-22
- update readme.md
## [0.1.2] - 2023-07-23
- update documentation
- remove commented **SoftwareWire** version => own repo.

View File

@ -59,6 +59,12 @@ Test on UNO
| 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
These libraries need to be installed to get SHT31_SW working:

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ uint32_t start;
uint32_t stop;
uint32_t cnt;
SHT31_SW sht;
SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup()
@ -28,8 +28,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION);
sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);
@ -45,9 +45,9 @@ void loop()
if (sht.dataReady())
{
start = micros();
bool success = sht.readData(); // default = true = fast
bool success = sht.readData(); // default = true = fast
stop = micros();
sht.requestData(); // request for next sample
sht.requestData(); // request for next sample
Serial.print("\t");
Serial.print(stop - start);
@ -66,8 +66,8 @@ void loop()
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 stop;
SHT31_SW sht;
SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup()
@ -28,7 +28,7 @@ void setup()
sw.begin();
sw.setClock(100000);
sht.begin(SHT31_ADDRESS, &sw);
sht.begin();
Serial.print("CON:\t");
Serial.println(sht.isConnected());

View File

@ -16,7 +16,7 @@ SoftWire sw(6, 7);
uint32_t start;
uint32_t stop;
SHT31_SW sht;
SHT31_SW sht(SHT31_ADDRESS, &sw);
uint16_t status;
@ -28,10 +28,10 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION);
sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
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();
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 connectionFails = 0;
SHT31_SW sht;
SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup()
@ -28,8 +28,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION);
sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);

View File

@ -16,7 +16,7 @@ SoftWire sw(6, 7);
uint32_t start;
uint32_t stop;
SHT31_SW sht;
SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup()
@ -27,8 +27,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION);
sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
@ -39,7 +39,7 @@ void setup()
void loop()
{
sht.read(); // default = true/fast slow = false
sht.read(); // default = true/fast slow = false
Serial.print("\t");
Serial.print(sht.lastRead());
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 cnt;
SHT31_SW sht;
SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup()
@ -28,8 +28,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION);
sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
@ -49,9 +49,9 @@ void loop()
if (sht.dataReady())
{
start = micros();
bool success = sht.readData(); // default = true = fast
bool success = sht.readData(); // default = true = fast
stop = micros();
sht.requestData(); // request for next sample
sht.requestData(); // request for next sample
Serial.print("\t");
Serial.print(stop - start);
@ -66,19 +66,23 @@ void loop()
rawHumidity = sht.getRawHumidity();
Serial.print(rawTemperature, HEX);
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(sht.getRawHumidity(), HEX);
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.println(cnt);
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 stop;
SHT31_SW sht;
SHT31_SW sht(SHT31_ADDRESS, &sw);
void setup()
@ -27,8 +27,8 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION);
sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000);
sht.begin();
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);

View File

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

View File

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

View File

@ -36,7 +36,7 @@
#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;