mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.0 tinySHT2x
This commit is contained in:
parent
6d253e21a6
commit
a2adba097d
@ -6,11 +6,20 @@ 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-04
|
||||
- refactor API, more in line with other Wire based libs.
|
||||
- update readme.md
|
||||
- added **isConnected()**
|
||||
- added asynchronous interface.
|
||||
- rewrote the synchronous interface.
|
||||
- add examples.
|
||||
|
||||
----
|
||||
|
||||
## [0.1.3] - 2023-11-22
|
||||
- update readme.md
|
||||
- fix version number
|
||||
|
||||
|
||||
## [0.1.2] - 2022-11-26
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
|
@ -16,13 +16,22 @@ Arduino library specific for AVR tiny processors.
|
||||
|
||||
## Description
|
||||
|
||||
**Experimental**
|
||||
The tinySHT2x is an **Experimental** Arduino library to read the SHT2X sensor.
|
||||
This sensor provides temperature and humidity.
|
||||
|
||||
The library is meant for AVR only, tiny platform, so it is minimal (not?) portable.
|
||||
|
||||
|
||||
#### 0.2.0 Breaking change
|
||||
|
||||
Version 0.2.0 introduced a breaking change.
|
||||
Wire parameter has moved from **begin()** to the Constructor.
|
||||
The user has to call **Wire.begin()** before calling **begin()**.
|
||||
|
||||
Not portable, AVR only
|
||||
|
||||
#### Related
|
||||
|
||||
Based upon https://github.com/RobTillaart/SHT2x
|
||||
- https://github.com/RobTillaart/SHT2x (based upon).
|
||||
|
||||
|
||||
## Interface
|
||||
@ -31,6 +40,33 @@ Based upon https://github.com/RobTillaart/SHT2x
|
||||
#include "tinySHT2x.h"
|
||||
```
|
||||
|
||||
#### Functions
|
||||
|
||||
- **tinySHT2x(TwoWire \* wire = &Wire)** Constructor
|
||||
- **bool begin()** initializes internals. Returns true if device can be found.
|
||||
- **bool isConnected()** Returns true if device can be found.
|
||||
- **bool reset()** sends SOFT_RESET command to sensor.
|
||||
returns false if I2C failed to send it.
|
||||
|
||||
|
||||
#### Async interface
|
||||
|
||||
With the Async interface the user must watch keep track of the appropriate
|
||||
delay between the request and read.
|
||||
For temperature this is typical around 70 millis and for humidity 30 millis().
|
||||
|
||||
- **void requestTemperature()** sends GET_TEMPERATURE command to sensor.
|
||||
- **void requestHumidity()** sends GET_HUMIDITY command to sensor.
|
||||
- **float readTemperature()** fetches data from the sensor.
|
||||
- **float readHumidity()** fetches data from the sensor.
|
||||
|
||||
#### Sync interface
|
||||
|
||||
- **float getTemperature(uint8_t del = 70)** requests and read the temperature.
|
||||
It uses a delay of 70 milliseconds which can be tuned by the user.
|
||||
- **float getHumidity(uint8_t del = 30)** requests and read the humidity.
|
||||
It uses a delay of30 milliseconds which can be tuned by the user.
|
||||
|
||||
- see https://github.com/RobTillaart/SHT2x
|
||||
|
||||
|
||||
@ -45,6 +81,9 @@ Based upon https://github.com/RobTillaart/SHT2x
|
||||
|
||||
#### Could
|
||||
|
||||
- investigate async interface
|
||||
- splitting requestHumidity() and getHumidity().
|
||||
- idem for temperature.
|
||||
- Can a tiny have another Wire than Wire?
|
||||
- Check the status bit (temperature / humidity flag)
|
||||
- datasheet page 8, LSB bit 1 - bit 0 not used)
|
||||
|
@ -0,0 +1,2 @@
|
||||
[InternetShortcut]
|
||||
URL=https://www.sensirion.com/en/download-center/humidity-sensors/humidity-temperature-sensor-sht2x-digital-i2c-accurate/
|
BIN
libraries/tinySHT2x/documents/SHT20_datasheet.pdf
Normal file
BIN
libraries/tinySHT2x/documents/SHT20_datasheet.pdf
Normal file
Binary file not shown.
BIN
libraries/tinySHT2x/documents/SHT21_datasheet.pdf
Normal file
BIN
libraries/tinySHT2x/documents/SHT21_datasheet.pdf
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -16,6 +16,7 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
Wire.begin();
|
||||
sht.begin();
|
||||
}
|
||||
|
||||
@ -29,5 +30,5 @@ void loop()
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
- leonardo
|
||||
# - m4
|
||||
#- esp32
|
||||
# - esp8266
|
||||
- mega2560
|
||||
# - trinket
|
@ -0,0 +1,38 @@
|
||||
//
|
||||
// FILE: tinySHT2x_demo_async.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/tinySHT2x
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
#include "tinySHT2x.h"
|
||||
|
||||
tinySHT2x sht;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
Wire.begin();
|
||||
sht.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
sht.requestTemperature();
|
||||
delay(65); // tune to work
|
||||
Serial.print(sht.readTemperature());
|
||||
Serial.print("\t");
|
||||
|
||||
sht.requestHumidity();
|
||||
delay(28); // tune to work
|
||||
Serial.println(sht.getHumidity());
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,12 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
- leonardo
|
||||
# - m4
|
||||
#- esp32
|
||||
# - esp8266
|
||||
- mega2560
|
||||
# - trinket
|
@ -0,0 +1,33 @@
|
||||
//
|
||||
// FILE: tinySHT2x_demo_delay.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/tinySHT2x
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
#include "tinySHT2x.h"
|
||||
|
||||
tinySHT2x sht;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
|
||||
Wire.begin();
|
||||
sht.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(sht.getTemperature(65)); // adjust delay if needed
|
||||
Serial.print("\t");
|
||||
Serial.println(sht.getHumidity(28)); // adjust delay if needed
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -7,9 +7,16 @@ tinySHT2x KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
reset KEYWORD2
|
||||
|
||||
requestTemperature KEYWORD2
|
||||
requestHumidity KEYWORD2
|
||||
readTemperature KEYWORD2
|
||||
readHumidity KEYWORD2
|
||||
|
||||
getTemperature KEYWORD2
|
||||
getHumidity KEYWORD2
|
||||
reset KEYWORD2
|
||||
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/tinySHT2x.git"
|
||||
},
|
||||
"version": "0.1.3",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "avr",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=tinySHT2x
|
||||
version=0.1.3
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for the SHT20, SHT21 and SHT25 temperature and humidity sensor. Optimized for AVR tiny.
|
||||
|
@ -56,16 +56,19 @@ unittest(test_constant)
|
||||
unittest(test_constructor)
|
||||
{
|
||||
tinySHT2x sht;
|
||||
|
||||
|
||||
Wire.begin();
|
||||
|
||||
sht.begin();
|
||||
assertTrue(sht.reset());
|
||||
// need godmode for these
|
||||
// assertEqualFloat(TINY_SHT2x_NO_VALUE, sht.getTemperature(), 0.01);
|
||||
// assertEqualFloat(TINY_SHT2x_NO_VALUE, sht.getHumidity(), 0.01);
|
||||
// need godmode for these
|
||||
// assertEqualFloat(TINY_SHT2x_NO_VALUE, sht.getTemperature(), 0.01);
|
||||
// assertEqualFloat(TINY_SHT2x_NO_VALUE, sht.getHumidity(), 0.01);
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// --------
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
//
|
||||
// FILE: tinytinySHT2x.cpp
|
||||
// FILE: tinySHT2x.cpp
|
||||
// AUTHOR: Rob Tillaart, Viktor Balint
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2021-09-27
|
||||
// PURPOSE: Arduino library for the SHT2x temperature and humidity sensor optimized for AVR tiny
|
||||
// URL: https://github.com/RobTillaart/tinytinySHT2x
|
||||
// URL: https://github.com/RobTillaart/tinySHT2x
|
||||
|
||||
|
||||
|
||||
@ -16,25 +16,46 @@
|
||||
#define SHT2x_ADDRESS 0x40
|
||||
|
||||
|
||||
tinySHT2x::tinySHT2x()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void tinySHT2x::begin(TwoWire *wire)
|
||||
tinySHT2x::tinySHT2x(TwoWire *wire)
|
||||
{
|
||||
_wire = wire;
|
||||
_wire->begin();
|
||||
}
|
||||
|
||||
|
||||
float tinySHT2x::getTemperature()
|
||||
bool tinySHT2x::begin()
|
||||
{
|
||||
return isConnected();
|
||||
}
|
||||
|
||||
|
||||
bool tinySHT2x::isConnected()
|
||||
{
|
||||
_wire->beginTransmission(SHT2x_ADDRESS);
|
||||
return (_wire->endTransmission() == 0);
|
||||
}
|
||||
|
||||
|
||||
bool tinySHT2x::reset()
|
||||
{
|
||||
return writeCmd(SHT2x_SOFT_RESET);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
//
|
||||
// ASYNC INTERFACE
|
||||
//
|
||||
void tinySHT2x::requestTemperature()
|
||||
{
|
||||
writeCmd(SHT2x_GET_TEMPERATURE_NO_HOLD);
|
||||
}
|
||||
|
||||
|
||||
float tinySHT2x::readTemperature()
|
||||
{
|
||||
uint8_t buffer[3];
|
||||
uint16_t raw;
|
||||
|
||||
writeCmd(SHT2x_GET_TEMPERATURE_NO_HOLD);
|
||||
delay(70);
|
||||
if (readBytes(3, (uint8_t*) &buffer[0], 90) == false)
|
||||
{
|
||||
return TINY_SHT2x_NO_VALUE;
|
||||
@ -47,14 +68,17 @@ float tinySHT2x::getTemperature()
|
||||
}
|
||||
|
||||
|
||||
float tinySHT2x::getHumidity()
|
||||
void tinySHT2x::requestHumidity()
|
||||
{
|
||||
writeCmd(SHT2x_GET_HUMIDITY_NO_HOLD);
|
||||
}
|
||||
|
||||
|
||||
float tinySHT2x::readHumidity()
|
||||
{
|
||||
uint8_t buffer[3];
|
||||
uint16_t raw;
|
||||
|
||||
// HUMIDITY
|
||||
writeCmd(SHT2x_GET_HUMIDITY_NO_HOLD);
|
||||
delay(30);
|
||||
if (readBytes(3, (uint8_t*) &buffer[0], 30) == false)
|
||||
{
|
||||
return TINY_SHT2x_NO_VALUE;
|
||||
@ -67,9 +91,23 @@ float tinySHT2x::getHumidity()
|
||||
}
|
||||
|
||||
|
||||
bool tinySHT2x::reset()
|
||||
///////////////////////////////////
|
||||
//
|
||||
// SYNC INTERFACE
|
||||
//
|
||||
float tinySHT2x::getTemperature(uint8_t del)
|
||||
{
|
||||
return writeCmd(SHT2x_SOFT_RESET);
|
||||
requestTemperature();
|
||||
delay(del);
|
||||
return readTemperature();
|
||||
}
|
||||
|
||||
|
||||
float tinySHT2x::getHumidity(uint8_t del)
|
||||
{
|
||||
requestHumidity();
|
||||
delay(del);
|
||||
return readHumidity();
|
||||
}
|
||||
|
||||
|
||||
@ -77,7 +115,6 @@ bool tinySHT2x::reset()
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
bool tinySHT2x::writeCmd(uint8_t cmd)
|
||||
{
|
||||
_wire->beginTransmission(SHT2x_ADDRESS);
|
||||
@ -86,7 +123,7 @@ bool tinySHT2x::writeCmd(uint8_t cmd)
|
||||
}
|
||||
|
||||
|
||||
bool tinySHT2x::readBytes(uint8_t n, uint8_t *val, uint8_t maxDuration)
|
||||
bool tinySHT2x::readBytes(uint8_t n, uint8_t * val, uint8_t maxDuration)
|
||||
{
|
||||
_wire->requestFrom((uint8_t)SHT2x_ADDRESS, (uint8_t) n);
|
||||
uint32_t start = millis();
|
||||
|
@ -2,17 +2,17 @@
|
||||
//
|
||||
// FILE: tinySHT2x.h
|
||||
// AUTHOR: Rob Tillaart, Viktor Balint
|
||||
// VERSION: 0.1.3
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2021-09-27
|
||||
// PURPOSE: Arduino library for the SHT2x temperature and humidity sensor optimized for AVR tiny
|
||||
// URL: https://github.com/RobTillaart/tinySHT2x
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#define TINY_SHT2x_LIB_VERSION (F("0.1.3"))
|
||||
#define TINY_SHT2x_LIB_VERSION (F("0.2.0"))
|
||||
|
||||
#define TINY_SHT2x_NO_VALUE -999
|
||||
|
||||
@ -20,16 +20,26 @@
|
||||
class tinySHT2x
|
||||
{
|
||||
public:
|
||||
tinySHT2x();
|
||||
tinySHT2x(TwoWire *wire = &Wire);
|
||||
|
||||
void begin(TwoWire *wire = &Wire);
|
||||
bool begin();
|
||||
bool isConnected();
|
||||
bool reset();
|
||||
float getTemperature();
|
||||
float getHumidity();
|
||||
|
||||
// ASYNC INTERFACE
|
||||
void requestTemperature();
|
||||
void requestHumidity();
|
||||
float readTemperature();
|
||||
float readHumidity();
|
||||
|
||||
// SYNC INTERFACE
|
||||
float getTemperature(uint8_t del = 70);
|
||||
float getHumidity(uint8_t del = 30);
|
||||
|
||||
|
||||
private:
|
||||
bool writeCmd(uint8_t cmd);
|
||||
bool readBytes(uint8_t n, uint8_t *val, uint8_t maxDuration);
|
||||
bool readBytes(uint8_t n, uint8_t * val, uint8_t maxDuration);
|
||||
TwoWire* _wire;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user