mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.1 tinySHT2x (experimental)
This commit is contained in:
parent
ac771f1efd
commit
0532be1da2
12
libraries/tinySHT2x/.arduino-ci.yml
Normal file
12
libraries/tinySHT2x/.arduino-ci.yml
Normal 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
|
13
libraries/tinySHT2x/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/tinySHT2x/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/tinySHT2x/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/tinySHT2x/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/tinySHT2x/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/tinySHT2x/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
21
libraries/tinySHT2x/LICENSE
Normal file
21
libraries/tinySHT2x/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
33
libraries/tinySHT2x/README.md
Normal file
33
libraries/tinySHT2x/README.md
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/tinySHT2x/actions/workflows/arduino_test_runner.yml/badge.svg)](https://github.com/RobTillaart/tinySHT2x/actions/workflows/arduino_test_runner.yml)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/tinySHT2x/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/tinySHT2x/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/tinySHT2x/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/tinySHT2x/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/tinySHT2x/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/tinySHT2x.svg?maxAge=3600)](https://github.com/RobTillaart/tinySHT2x/releases)
|
||||
|
||||
|
||||
# tinySHT2x
|
||||
|
||||
Arduino library specific for AVR tiny processors.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
Experimental ^2
|
||||
Not portable, AVR only
|
||||
|
||||
Based upon https://github.com/RobTillaart/SHT2x
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
- see https://github.com/RobTillaart/SHT2x
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- test test test test (Viktor)
|
||||
- improve documentation
|
||||
- Can a tiny have another Wire than Wire?
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
[InternetShortcut]
|
||||
URL=https://create.arduino.cc/projecthub/arjun/programming-attiny85-with-arduino-uno-afb829
|
12
libraries/tinySHT2x/examples/tinySHT2x_demo/.arduino-ci.yml
Normal file
12
libraries/tinySHT2x/examples/tinySHT2x_demo/.arduino-ci.yml
Normal 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.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__);
|
||||
|
||||
sht.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(sht.getTemperature());
|
||||
Serial.print("\t");
|
||||
Serial.println(sht.getHumidity());
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
20
libraries/tinySHT2x/keywords.txt
Normal file
20
libraries/tinySHT2x/keywords.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# Syntax Colouring Map For SHT2x temperature and humidity sensor
|
||||
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
tinySHT2x KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
getHumidity KEYWORD2
|
||||
reset KEYWORD2
|
||||
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
|
||||
# Constants (LITERAL1)
|
||||
TINY_SHT2x_LIB_VERSION LITERAL1
|
||||
TINY_SHT2x_NO_VALUE LITERAL1
|
||||
|
23
libraries/tinySHT2x/library.json
Normal file
23
libraries/tinySHT2x/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "tinySHT2x",
|
||||
"keywords": "SHT2x,Temperature,Humidity,I2C,SHT20,SHT21,SHT25",
|
||||
"description": "Arduino library for the I2C SHT2x series temperature and humidity sensor, optimized for AVR tiny",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/tinySHT2x.git"
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"headers": "tinySHT2x.h"
|
||||
}
|
11
libraries/tinySHT2x/library.properties
Normal file
11
libraries/tinySHT2x/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=tinySHT2x
|
||||
version=0.1.1
|
||||
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.
|
||||
paragraph=Supports SHT20 and SHT25 too.
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/tinySHT2x
|
||||
architectures=*
|
||||
includes=tinySHT2x.h
|
||||
depends=
|
65
libraries/tinySHT2x/test/unit_test_001.cpp
Normal file
65
libraries/tinySHT2x/test/unit_test_001.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-12-29
|
||||
// PURPOSE: unit tests for the timing libraty
|
||||
// https://github.com/RobTillaart/timing
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual); // a == b
|
||||
// assertNotEqual(unwanted, actual); // a != b
|
||||
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
||||
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
||||
// assertLess(upperBound, actual); // a < b
|
||||
// assertMore(lowerBound, actual); // a > b
|
||||
// assertLessOrEqual(upperBound, actual); // a <= b
|
||||
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
||||
// assertTrue(actual);
|
||||
// assertFalse(actual);
|
||||
// assertNull(actual);
|
||||
|
||||
// // special cases for floats
|
||||
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
||||
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
||||
// assertInfinity(actual); // isinf(a)
|
||||
// assertNotInfinity(actual); // !isinf(a)
|
||||
// assertNAN(arg); // isnan(a)
|
||||
// assertNotNAN(arg); // !isnan(a)
|
||||
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "tinySHT2x.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "TINY_SHT2x_LIB_VERSION: %s\n", (char *) TINY_SHT2x_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
tinySHT2x sht;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// --------
|
115
libraries/tinySHT2x/tinySHT2x.cpp
Normal file
115
libraries/tinySHT2x/tinySHT2x.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
//
|
||||
// FILE: tinytinySHT2x.cpp
|
||||
// AUTHOR: Rob Tillaart, Viktor Balint
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2021-09-27
|
||||
// PURPOSE: Arduino library for the SHT2x temperature and humidity sensor optimized for AVR tiny
|
||||
// URL: https://github.com/RobTillaart/tinytinySHT2x
|
||||
//
|
||||
|
||||
// HISTORY:
|
||||
// 0.1.0 2021-09-27 initial version
|
||||
// 0.1.1 2021-12-29 update library.json, readme, license, minor edits
|
||||
|
||||
|
||||
#include "tinySHT2x.h"
|
||||
|
||||
#define SHT2x_GET_TEMPERATURE_NO_HOLD 0xF3
|
||||
#define SHT2x_GET_HUMIDITY_NO_HOLD 0xF5
|
||||
#define SHT2x_SOFT_RESET 0xFE
|
||||
#define SHT2x_ADDRESS 0x40
|
||||
|
||||
|
||||
tinySHT2x::tinySHT2x()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void tinySHT2x::begin(TwoWire *wire)
|
||||
{
|
||||
_wire = wire;
|
||||
_wire->begin();
|
||||
}
|
||||
|
||||
|
||||
float tinySHT2x::getTemperature()
|
||||
{
|
||||
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;
|
||||
}
|
||||
raw = buffer[0] << 8;
|
||||
raw += buffer[1];
|
||||
raw &= 0xFFFC;
|
||||
|
||||
return -46.85 + (175.72 / 65536.0) * raw;
|
||||
}
|
||||
|
||||
|
||||
float tinySHT2x::getHumidity()
|
||||
{
|
||||
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 -999;
|
||||
}
|
||||
raw = buffer[0] << 8;
|
||||
raw += buffer[1];
|
||||
raw &= 0xFFFC;
|
||||
|
||||
return -6.0 + (125.0 / 65536.0) * raw;
|
||||
}
|
||||
|
||||
|
||||
bool tinySHT2x::reset()
|
||||
{
|
||||
return writeCmd(SHT2x_SOFT_RESET);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
bool tinySHT2x::writeCmd(uint8_t cmd)
|
||||
{
|
||||
_wire->beginTransmission(SHT2x_ADDRESS);
|
||||
_wire->write(cmd);
|
||||
return (_wire->endTransmission() == 0);
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
while (_wire->available() < n)
|
||||
{
|
||||
if (millis() - start > maxDuration)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < n; i++)
|
||||
{
|
||||
val[i] = _wire->read();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
38
libraries/tinySHT2x/tinySHT2x.h
Normal file
38
libraries/tinySHT2x/tinySHT2x.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: tinySHT2x.h
|
||||
// AUTHOR: Rob Tillaart, Viktor Balint
|
||||
// VERSION: 0.1.1
|
||||
// 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.1"))
|
||||
|
||||
#define TINY_SHT2x_NO_VALUE -999
|
||||
|
||||
|
||||
class tinySHT2x
|
||||
{
|
||||
public:
|
||||
tinySHT2x();
|
||||
|
||||
void begin(TwoWire *wire = &Wire);
|
||||
bool reset();
|
||||
float getTemperature();
|
||||
float getHumidity();
|
||||
|
||||
private:
|
||||
bool writeCmd(uint8_t cmd);
|
||||
bool readBytes(uint8_t n, uint8_t *val, uint8_t maxDuration);
|
||||
TwoWire* _wire;
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
Loading…
x
Reference in New Issue
Block a user