0.1.1 SHT31_SW

This commit is contained in:
Rob Tillaart 2023-05-12 17:01:00 +02:00
parent 45a5c60aa2
commit 2ee0388db8
9 changed files with 190 additions and 72 deletions

View File

@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.1] - 2023-05-12
- add **commented** version with **SoftwareWire** to "fix" issue #5
- clean up SHT31_SW.cpp
- update keywords.txt
- update readme.md
## [0.1.0] - 2023-03-23
- initial version, derives from SHT31 0.3.8
- uses **SoftWire** I2C library.

View File

@ -13,12 +13,13 @@ Arduino library for the SHT31 temperature and humidity sensor - using **SoftWire
## Description
This library features the class SHT31_SW derived from - https://github.com/RobTillaart/SHT31
This experimental library features the class SHT31_SW derived from - https://github.com/RobTillaart/SHT31
It has the same interface as the SHT31 class so please use that documentation
as it will be the "leading class".
The main difference is that this SHT31_SW class uses the **SoftWire**
library for communication instead of the **TwoWire** based **Wire** class.
See SHT31 PR #35.
**SoftWire** is a software I2C bus library to be able to select other pins
than the default (AVR) hardware I2C pins (SDA and SCL).
@ -26,10 +27,18 @@ An important reason to use this version is when you want more than two
devices on one Arduino.
#### Status
#### SoftwareWire (AVR only)
- experimental
- created as alternative for SHT31 PR #35.
The **SoftWire** library is portable, but seems less stable as it could not read
the SHT85 sensor which is command compatible with the SHT3x.
The cause is not found yet, so until then an alternative **SoftwareWire** is included.
(If you know a solution, please let me know).
The **SoftwareWire** library is an AVR specific and worked for the SHT85.
See https://github.com/RobTillaart/SHT31_SW/issues/5
You need to comment/uncomment the .h and .cpp file and of course use **SoftwareWire**
instead of **SoftWire** in your project.
#### SHT sensors
@ -40,21 +49,22 @@ This library should also work for SHT30/35/85 but these are not tested yet.
Accuracy table
| SENSOR | Temperature | Humidity |
|:--------:|:-------------:|:----------:|
| SHT30 | ~0.3 | 2.0 |
| SHT31 | ~0.3 | 1.5 |
| SHT35 | ~0.2 | 1.5 |
| SHT85 | ~0.2 | 1.5 |
| SENSOR | Temperature | Humidity | works with |
|:--------:|:-------------:|:----------:|:---------------|
| SHT30 | ~0.3 | 2.0 | (not tested) |
| SHT31 | ~0.3 | 1.5 | SoftWire |
| SHT35 | ~0.2 | 1.5 | (not tested) |
| SHT85 | ~0.2 | 1.5 | SoftwareWire |
#### Links
These libraries need to be installed to get SHT31_SW working:
- https://github.com/RobTillaart/SHT31
- https://github.com/stevemarple/SoftWire
- https://github.com/stevemarple/AsyncDelay
- https://github.com/RobTillaart/SHT31
- https://github.com/Testato/SoftwareWire // AVR only
## Interface
@ -169,6 +179,15 @@ Returns false if reading fails or in case of a CRC failure.
## Future
- keep in sync with (leading) SHT31 library
#### Must
- keep in sync with (leading) SHT31 library.
- remove script for atomic if not needed any more.
- investigate why SHT85 does not work with SoftWire.
#### Should
#### Could
#### Wont

View File

@ -1,7 +1,7 @@
//
// FILE: SHT31_SW.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// VERSION: 0.1.1
// 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,21 +14,6 @@
#include "SHT31_SW.h"
// SUPPORTED COMMANDS - single shot mode only
#define SHT31_READ_STATUS 0xF32D
#define SHT31_CLEAR_STATUS 0x3041
#define SHT31_SOFT_RESET 0x30A2
#define SHT31_HARD_RESET 0x0006
#define SHT31_MEASUREMENT_FAST 0x2416 // page 10 datasheet
#define SHT31_MEASUREMENT_SLOW 0x2400 // no clock stretching
#define SHT31_HEAT_ON 0x306D
#define SHT31_HEAT_OFF 0x3066
#define SHT31_HEATER_TIMEOUT 180000UL // milliseconds
SHT31_SW::SHT31_SW()
{
_softWire = NULL;
@ -79,7 +64,7 @@ bool SHT31_SW::isConnected()
bool SHT31_SW::writeCmd(uint16_t cmd)
{
_softWire->beginTransmission(_address);
_softWire->write(cmd >> 8 );
_softWire->write(cmd >> 8);
_softWire->write(cmd & 0xFF);
if (_softWire->endTransmission() != 0)
{
@ -106,5 +91,95 @@ bool SHT31_SW::readBytes(uint8_t n, uint8_t *val)
}
/////////////////////////////////////////////////////////
//
// This version is using an AVR specific SoftwareWire
// it can read the SHT85 where the above can't.
// See https://github.com/RobTillaart/SHT31_SW/issues/5
//
// you need to comment the above version (also in .h file)
// and use SoftwareWire instead of SoftWire in your project.
//
/*
SHT31_SW::SHT31_SW()
{
_softWire = NULL;
_address = 0;
_lastRead = 0;
_rawTemperature = 0;
_rawHumidity = 0;
_heatTimeout = 0;
_heaterStart = 0;
_heaterStop = 0;
_heaterOn = false;
_error = SHT31_OK;
}
bool SHT31_SW::begin(const uint8_t address, SoftwareWire *softWire)
{
if ((address != 0x44) && (address != 0x45))
{
return false;
}
_address = address;
_softWire = softWire;
_softWire->begin();
return reset();
}
bool SHT31_SW::begin(SoftwareWire *softWire)
{
return begin(SHT_DEFAULT_ADDRESS, softWire);
}
bool SHT31_SW::isConnected()
{
_softWire->beginTransmission(_address);
int rv = _softWire->endTransmission();
if (rv != 0) _error = SHT31_ERR_NOT_CONNECT;
return (rv == 0);
}
////////////////////////////////////////////////////
//
// PRIVATE
//
bool SHT31_SW::writeCmd(uint16_t cmd)
{
_softWire->beginTransmission(_address);
_softWire->write(cmd >> 8 );
_softWire->write(cmd & 0xFF);
if (_softWire->endTransmission() != 0)
{
_error = SHT31_ERR_WRITECMD;
return false;
}
return true;
}
bool SHT31_SW::readBytes(uint8_t n, uint8_t *val)
{
int rv = _softWire->requestFrom(_address, (uint8_t) n);
if (rv == n)
{
for (uint8_t i = 0; i < n; i++)
{
val[i] = _softWire->read();
}
return true;
}
_error = SHT31_ERR_READBYTES;
return false;
}
*/
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: SHT31_SW.h
// AUTHOR: Rob Tillaart, Gunter Haug
// VERSION: 0.1.0
// VERSION: 0.1.1
// 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,14 +12,14 @@
// URL: https://github.com/RobTillaart/SHT31
#define SHT31_SW_LIB_VERSION (F("0.1.1"))
#include "Arduino.h"
#include "SoftWire.h"
#include "SHT31.h"
#define SHT31_SW_LIB_VERSION (F("0.1.0"))
class SHT31_SW : public SHT31
{
public:
@ -39,5 +39,43 @@ private:
};
/////////////////////////////////////////////////////////
//
// This version is using an AVR specific SoftwareWire
// it can read the SHT85 where the above can't.
// See https://github.com/RobTillaart/SHT31_SW/issues/5
//
// you need to comment the above version (also in .cpp file)
// and use SoftwareWire instead of SoftWire in your project.
//
/*
#include "Arduino.h"
#include "SoftwareWire.h"
#include "SHT31.h"
class SHT31_SW : public SHT31
{
public:
SHT31_SW();
// use SHT_DEFAULT_ADDRESS
bool begin(const uint8_t address, SoftwareWire *wire);
bool begin(SoftwareWire *wire);
// check sensor is reachable over I2C
bool isConnected();
private:
bool writeCmd(uint16_t cmd);
bool readBytes(uint8_t n, uint8_t *val);
SoftwareWire* _softWire;
};
*/
// -- END OF FILE --

View File

@ -27,8 +27,13 @@ void setup()
Serial.println(SHT31_SW_LIB_VERSION);
sw.begin();
sht.begin(SHT31_ADDRESS, &sw);
sw.setClock(100000);
sht.begin(SHT31_ADDRESS, &sw);
Serial.print("CON:\t");
Serial.println(sht.isConnected());
delay(100);
uint16_t stat = sht.readStatus();
Serial.print(stat, HEX);
@ -48,7 +53,7 @@ void loop()
Serial.print(sht.getTemperature(), 1);
Serial.print("\t");
Serial.println(sht.getHumidity(), 1);
delay(100);
delay(3000);
}

View File

@ -1,4 +1,4 @@
# Syntax Colouring Map For SHT31 temperature and humidity sensor
# Syntax Colouring Map For SHT31_SW temperature and humidity sensor
# Data types (KEYWORD1)
@ -6,42 +6,12 @@ SHT31_SW KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
read KEYWORD2
isConnected KEYWORD2
readStatus KEYWORD2
lastRead KEYWORD2
reset KEYWORD2
setHeatTimeout KEYWORD2
heatOn KEYWORD2
heatOff KEYWORD2
isHeaterOn KEYWORD2
getHumidity KEYWORD2
getTemperature KEYWORD2
requestData KEYWORD2
dataReady KEYWORD2
readData KEYWORD2
getRawHumidity KEYWORD2
getRawTemperature KEYWORD2
# Instances (KEYWORD2)
# Constants (LITERAL1)
SHT31_LIB_VERSION LITERAL1
SHT31_SW_LIB_VERSION LITERAL1
SHT31_STATUS_ALERT_PENDING LITERAL1
SHT31_STATUS_HEATER_ON LITERAL1
SHT31_STATUS_HUM_TRACK_ALERT LITERAL1
SHT31_STATUS_TEMP_TRACK_ALERT LITERAL1
SHT31_STATUS_SYSTEM_RESET LITERAL1
SHT31_STATUS_COMMAND_STATUS LITERAL1
SHT31_STATUS_WRITE_CRC_STATUS LITERAL1
SHT31_ERR_HEATER_COOLDOWN LITERAL1
SHT31_ERR_HEATER_ON LITERAL1

View File

@ -1,6 +1,6 @@
{
"name": "SHT31_SW",
"keywords": "SoftWire,I2C,SHT30,SHT35,SHT85",
"keywords": "SoftWire,I2C,SHT30,SHT31,SHT35,SHT85",
"description": "Arduino library for the I2C SHT31 temperature and humidity sensor.",
"authors":
[
@ -18,7 +18,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/SHT31_SW"
},
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,9 +1,9 @@
name=SHT31_SW
version=0.1.0
version=0.1.1
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
paragraph=SoftWire,I2C,SHT30,SHT35,SHT85
paragraph=SoftWire,I2C,SHT30,SHT31,SHT35,SHT85
category=Sensors
url=https://github.com/RobTillaart/SHT31_SW
architectures=*

View File

@ -198,4 +198,6 @@ unittest(test_async)
unittest_main()
// --------
// -- END OF FILE --