diff --git a/examples/TestSht3x/TestSht3x.ino b/examples/TestSht/TestSht.ino similarity index 56% rename from examples/TestSht3x/TestSht3x.ino rename to examples/TestSht/TestSht.ino index 7684fdc..e9730ec 100644 --- a/examples/TestSht3x/TestSht3x.ino +++ b/examples/TestSht/TestSht.ino @@ -1,33 +1,32 @@ #include +#if defined(ESP8266) AirGradient ag(DIY_BASIC); +#else +AirGradient ag(ONE_INDOOR); +#endif void failedHandler(String msg); void setup() { Serial.begin(115200); + Serial.println("Hello"); Wire.begin(ag.getI2cSdaPin(), ag.getI2cSclPin()); - if (ag.sht3x.begin(Wire, Serial) == false) { + if (ag.sht.begin(Wire) == false) { failedHandler("SHT3x init failed"); } } void loop() { - float temp = ag.sht3x.getTemperature(); - if (temp <= -256.0f) { - Serial.println("Get temperature failed"); - } else { + if (ag.sht.measure()) { + float hum = ag.sht.getRelativeHumidity(); + float temp = ag.sht.getTemperature(); Serial.printf("Get temperature: %f\r\n", temp); - } - - float hum = ag.sht3x.getRelativeHumidity(); - if (hum < 0) { - Serial.println("Get humidity failed"); + Serial.printf(" Get humidity: %f\r\n", hum); } else { - Serial.printf("Get humidity: %f\r\n", hum); + Serial.println("Measure failed"); } - delay(1000); } diff --git a/src/AirGradient.cpp b/src/AirGradient.cpp index 8f27f2f..510c3c8 100644 --- a/src/AirGradient.cpp +++ b/src/AirGradient.cpp @@ -3,9 +3,9 @@ #define AG_LIB_VER "3.0.2" AirGradient::AirGradient(BoardType type) - : pms5003(type), pms5003t_1(type), pms5003t_2(type), s8(type), sht4x(type), - sht3x(type), sgp41(type), display(type), boardType(type), button(type), - statusLed(type), ledBar(type), watchdog(type) {} + : pms5003(type), pms5003t_1(type), pms5003t_2(type), s8(type), sgp41(type), + display(type), boardType(type), button(type), statusLed(type), + ledBar(type), watchdog(type), sht(type) {} /** * @brief Get pin number for I2C SDA diff --git a/src/AirGradient.h b/src/AirGradient.h index 8034f60..2a1c102 100644 --- a/src/AirGradient.h +++ b/src/AirGradient.h @@ -11,8 +11,7 @@ #include "pms/pms5003t.h" #include "s8/s8.h" #include "sgp41/sgp41.h" -#include "sht/sht4x.h" -#include "sht/sht3x.h" +#include "sht/sht.h" /** * @brief Class with define all the sensor has supported by Airgradient. Each @@ -43,15 +42,10 @@ public: S8 s8; /** - * @brief SHT41 Temperature and humidity sensor + * @brief Temperature and humidity sensor supported SHT3x and SHT4x + * */ - Sht4x sht4x; - - /** - * @brief SHT3x Temperature and humidity sensor - * - */ - Sht3x sht3x; + Sht sht; /** * @brief SGP41 TVOC and NOx sensor diff --git a/src/library/SensirionSHT4x/.clang-format b/src/library/SensirionSHT4x/.clang-format deleted file mode 100644 index 047f2ad..0000000 --- a/src/library/SensirionSHT4x/.clang-format +++ /dev/null @@ -1,14 +0,0 @@ ---- -Language: Cpp -BasedOnStyle: LLVM -IndentWidth: 4 -AlignAfterOpenBracket: Align -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -IndentCaseLabels: true -SpacesBeforeTrailingComments: 2 -PointerAlignment: Left -AlignEscapedNewlines: Left -ForEachMacros: ['TEST_GROUP', 'TEST'] -... diff --git a/src/library/SensirionSHT4x/.gitignore b/src/library/SensirionSHT4x/.gitignore deleted file mode 100644 index 47ded03..0000000 --- a/src/library/SensirionSHT4x/.gitignore +++ /dev/null @@ -1,70 +0,0 @@ -app/bin/ -app/pde.jar -build/macosx/work/ -arduino-core/bin/ -arduino-core/arduino-core.jar -hardware/arduino/bootloaders/caterina_LUFA/Descriptors.o -hardware/arduino/bootloaders/caterina_LUFA/Descriptors.lst -hardware/arduino/bootloaders/caterina_LUFA/Caterina.sym -hardware/arduino/bootloaders/caterina_LUFA/Caterina.o -hardware/arduino/bootloaders/caterina_LUFA/Caterina.map -hardware/arduino/bootloaders/caterina_LUFA/Caterina.lst -hardware/arduino/bootloaders/caterina_LUFA/Caterina.lss -hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf -hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep -hardware/arduino/bootloaders/caterina_LUFA/.dep/ -build/*.zip -build/*.tar.bz2 -build/windows/work/ -build/windows/*.zip -build/windows/*.tgz -build/windows/*.tar.bz2 -build/windows/libastylej* -build/windows/liblistSerials* -build/windows/arduino-*.zip -build/windows/dist/*.tar.gz -build/windows/dist/*.tar.bz2 -build/windows/launch4j-*.tgz -build/windows/launch4j-*.zip -build/windows/launcher/launch4j -build/windows/WinAVR-*.zip -build/macosx/arduino-*.zip -build/macosx/dist/*.tar.gz -build/macosx/dist/*.tar.bz2 -build/macosx/*.tar.bz2 -build/macosx/libastylej* -build/macosx/appbundler*.jar -build/macosx/appbundler*.zip -build/macosx/appbundler -build/macosx/appbundler-1.0ea-arduino? -build/macosx/appbundler-1.0ea-arduino*.zip -build/macosx/appbundler-1.0ea-upstream*.zip -build/linux/work/ -build/linux/dist/*.tar.gz -build/linux/dist/*.tar.bz2 -build/linux/*.tgz -build/linux/*.tar.xz -build/linux/*.tar.bz2 -build/linux/*.zip -build/linux/libastylej* -build/linux/liblistSerials* -build/shared/arduino-examples* -build/shared/reference*.zip -build/shared/Edison*.zip -build/shared/Galileo*.zip -build/shared/WiFi101-Updater-ArduinoIDE-Plugin*.zip -test-bin -*.iml -.idea -.DS_Store -.directory -hardware/arduino/avr/libraries/Bridge/examples/XivelyClient/passwords.h -avr-toolchain-*.zip -/app/nbproject/private/ -/arduino-core/nbproject/private/ -/app/build/ -/arduino-core/build/ - -manifest.mf -nbbuild.xml -nbproject \ No newline at end of file diff --git a/src/library/SensirionSHT4x/.gitlab-ci.yml b/src/library/SensirionSHT4x/.gitlab-ci.yml deleted file mode 100644 index 2c74751..0000000 --- a/src/library/SensirionSHT4x/.gitlab-ci.yml +++ /dev/null @@ -1,103 +0,0 @@ -stages: - - validate - - test - -variables: - YQ_URL: https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64 - -compile_test: - stage: test - image: - name: registry.gitlab.sensirion.lokal/sensirion/docker/docker-arduino:0.4.0 - tags: [docker, linux] - before_script: - - rm -rf ../sensirion-core-arduino-library - script: - - git clone --depth 1 --branch 0.5.2 https://github.com/Sensirion/arduino-core.git ../sensirion-core-arduino-library - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:samd:mkrzero ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:mega ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:nano ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:uno ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn esp32:esp32:esp32 ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn esp8266:esp8266:generic ./examples/exampleUsage/exampleUsage.ino - -arduino_lint: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - mkdir ~/arlint - - PATH=~/arlint:$PATH - - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | BINDIR=~/arlint sh - - arduino-lint --library-manager false - -syntax_check: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - find . -type f -iregex ".*\.\(c\|h\|cpp\|ino\)" -exec clang-format-6.0 -i -style=file {} \; && git diff --exit-code - - -cppcheck: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - cppcheck --std=c++11 --language=c++ --error-exitcode=1 --enable=warning,style,performance,portability --suppress=unreadVariable src/* - -TODO_check: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - '! grep -rnw --exclude=.gitlab-ci.yml --exclude-dir=.git . -e "TODO"' - -metadata_check: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - before_script: - - apt-get -qq update && apt-get -qq install -y wget - - if ! [ -d downloads/ ]; then mkdir downloads; fi - - if ! [ -e downloads/yq ]; then wget --no-verbose $YQ_URL -O downloads/yq; fi - - cp downloads/yq /usr/local/bin/yq && chmod +x /usr/local/bin/yq - script: - # check if metadata.yml exists - - > - if ! [ -f "metadata.yml" ]; then - echo "metadata.yml file not found" - exit 1 - fi - # check that dg_status is 'released' - - export DG_STATUS=$(yq ".dg_status.[]" ./metadata.yml) - - > - if [ $DG_STATUS != "released" ]; then - echo "dg_status in metadata.yml has to be 'released', not '$DG_STATUS'" - exit 1 - fi - # check that last_generated is not older than timestamp of last non-merge commit (+ 3 minutes) - - export IS_MANUALLY_MODIFIED=$(yq ".is_manually_modified" ./metadata.yml) - - > - if [ $IS_MANUALLY_MODIFIED = false ]; then - export LAST_GENERATED_TS=$(yq ".last_generated" ./metadata.yml) - export LAST_GENERATED_TS_EPOCH=$(date -d "$LAST_GENERATED_TS" +%s) - export LAST_NON_MERGE_COMMIT_TS=$(git log --format=%ad --date=iso-strict --no-merges -1) - export COMMIT_TS_EPOCH=$(date -d "$LAST_NON_MERGE_COMMIT_TS" +%s) - if [ $(($LAST_GENERATED_TS_EPOCH + 180)) -lt $COMMIT_TS_EPOCH ]; then - echo "'last_generated' timestamp in metadata.yml is older than commit timestamp ($LAST_GENERATED_TS vs $LAST_NON_MERGE_COMMIT_TS)" - exit 1 - fi - fi - # check that 'is_manually_modified' is set to true if commit is not from driver generator - - export LAST_NON_MERGE_COMMIT_AUTHOR=$(git log --format=%an --no-merges -1) - - > - if ! [ "$LAST_NON_MERGE_COMMIT_AUTHOR" = "Driver Generator 2" ] && [ "$IS_MANUALLY_MODIFIED" = false ]; then - echo "Last commit is not from Driver Generator. Please update 'is_manually_modified' in metadata.yml" - exit 1 - fi \ No newline at end of file diff --git a/src/library/SensirionSHT4x/CHANGELOG.md b/src/library/SensirionSHT4x/CHANGELOG.md deleted file mode 100644 index 163fd7f..0000000 --- a/src/library/SensirionSHT4x/CHANGELOG.md +++ /dev/null @@ -1,19 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - - -## [Unreleased] - -Defined I2C addresses for different sensor models. -You must now pass the I2C address to use in the begin() method of SensirionI2cSht4x - -Improved README - -## [0.1.0] - 2021-07-27 - -Initial release - -[0.1.0]: https://github.com/Sensirion/arduino-i2c-sht4x/releases/tag/0.1.0 diff --git a/src/library/SensirionSHT4x/README.md b/src/library/SensirionSHT4x/README.md deleted file mode 100644 index d42340d..0000000 --- a/src/library/SensirionSHT4x/README.md +++ /dev/null @@ -1,206 +0,0 @@ -# Sensirion I²C SHT4X Arduino Library - -This is the Sensirion SHT4X library for Arduino allowing you to -communicate with a sensor of the SHT4X family over I²C. - - - -Click [here](https://sensirion.com/products/catalog/SEK-SHT40/) to learn more about the Sensirion SHT4X sensor family. - - - -## Supported sensor types - -| Sensor name | I²C Addresses | -| ------------- | -------------- | -|[SHT40](https://sensirion.com/products/catalog/SHT40/)| **0x44**, 0x45| -|[SHT41](https://sensirion.com/products/catalog/SHT41/)| **0x44**, 0x45| -|[SHT45](https://sensirion.com/products/catalog/SHT45/)| **0x44**, 0x45| - -The following instructions and examples use a *SHT40*. - - - -## Installation of the library - -This library can be installed using the Arduino Library manager: -Start the [Arduino IDE](http://www.arduino.cc/en/main/software) and open -the Library Manager via - -`Sketch` ➔ `Include Library` ➔ `Manage Libraries...` - -Search for the `Sensirion I2C SHT4X` library in the `Filter -your search...` field and install it by clicking the `install` button. - -If you cannot find it in the library manager, download the latest release as .zip file -and add it to your [Arduino IDE](http://www.arduino.cc/en/main/software) via - -`Sketch` ➔ `Include Library` ➔ `Add .ZIP Library...` - -Don't forget to **install the dependencies** listed below the same way via library -manager or `Add .ZIP Library` - -#### Dependencies -* [Sensirion Core](https://github.com/Sensirion/arduino-core) - -## Sensor wiring - -Use the following pin description to connect your SHT4X to the standard I²C bus of your Arduino board: - - - -| *Pin* | *Cable Color* | *Name* | *Description* | *Comments* | -|-------|---------------|:------:|----------------|------------| -| 1 | green | SDA | I2C: Serial data input / output | -| 2 | black | GND | Ground | -| 3 | yellow | SCL | I2C: Serial clock input | -| 4 | red | VDD | Supply Voltage | 1.1V to 3.6V - -The recommended voltage is 3.3V. - -Please refer to the datasheet for proper circuit setup. There are 3rd party boards for easy connection of the SHT4x sensor to your Arduino Board. - -### Board specific wiring -You will find pinout schematics for recommended board models below: - - - -
Arduino Uno -

- -| *SHT4X* | *SHT4X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | D18/SDA | -| GND | 2 | black | GND | -| SCL | 3 | yellow | D19/SCL | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
Arduino Nano -

- -| *SHT4X* | *SHT4X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | A4 | -| GND | 2 | black | GND | -| SCL | 3 | yellow | A5 | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
Arduino Micro -

- -| *SHT4X* | *SHT4X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | D2/SDA | -| GND | 2 | black | GND | -| SCL | 3 | yellow | ~D3/SCL | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
Arduino Mega 2560 -

- -| *SHT4X* | *SHT4X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | D20/SDA | -| GND | 2 | black | GND | -| SCL | 3 | yellow | D21/SCL | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
ESP32 DevKitC -

- -| *SHT4X* | *SHT4X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | GPIO 21 | -| GND | 2 | black | GND | -| SCL | 3 | yellow | GPIO 22 | -| VDD | 4 | red | 3V3 | - - - - -

-
- - -## Quick Start - -1. Install the libraries and dependencies according to [Installation of the library](#installation-of-the-library) - -2. Connect the SHT4X sensor to your Arduino as explained in [Sensor wiring](#sensor-wiring) - -3. Open the `exampleUsage` sample project within the Arduino IDE: - - `File` ➔ `Examples` ➔ `Sensirion I2C SHT4X` ➔ `exampleUsage` - - - The provided example is working with a SHT40, I²C address 0x44. - In order to use the code with another product or I²C address you need to change it in the code of `exampleUsage`. - You find the list with pre-defined addresses in `src/SensirionI2CSht4x.h`. - - -5. Click the `Upload` button in the Arduino IDE or `Sketch` ➔ `Upload` - -4. When the upload process has finished, open the `Serial Monitor` or `Serial - Plotter` via the `Tools` menu to observe the measurement values. Note that - the `Baud Rate` in the used tool has to be set to `115200 baud`. - -## Contributing - -**Contributions are welcome!** - -We develop and test this driver using our company internal tools (version -control, continuous integration, code review etc.) and automatically -synchronize the master branch with GitHub. But this doesn't mean that we don't -respond to issues or don't accept pull requests on GitHub. In fact, you're very -welcome to open issues or create pull requests :) - -This Sensirion library uses -[`clang-format`](https://releases.llvm.org/download.html) to standardize the -formatting of all our `.cpp` and `.h` files. Make sure your contributions are -formatted accordingly: - -The `-i` flag will apply the format changes to the files listed. - -```bash -clang-format -i src/*.cpp src/*.h -``` - -Note that differences from this formatting will result in a failed build until -they are fixed. - - -## License - -See [LICENSE](LICENSE). diff --git a/src/library/SensirionSHT4x/examples/exampleUsage/exampleUsage.ino b/src/library/SensirionSHT4x/examples/exampleUsage/exampleUsage.ino deleted file mode 100644 index ced6c91..0000000 --- a/src/library/SensirionSHT4x/examples/exampleUsage/exampleUsage.ino +++ /dev/null @@ -1,89 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * Generator: sensirion-driver-generator 0.32.0 - * Product: sht4x - * Model-Version: 2.0.0 - */ -/* - * Copyright (c) 2023, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include - -SensirionI2CSht4x sensor; - -static char errorMessage[64]; -static int16_t error; - -void setup() { - - Serial.begin(115200); - while (!Serial) { - delay(100); - } - Wire.begin(); - sensor.begin(Wire, SHT40_I2C_ADDR_44); - - sensor.softReset(); - delay(10); - uint32_t serialNumber = 0; - error = sensor.serialNumber(serialNumber); - if (error != NO_ERROR) { - Serial.print("Error trying to execute serialNumber(): "); - errorToString(error, errorMessage, sizeof errorMessage); - Serial.println(errorMessage); - return; - } - Serial.print("serialNumber: "); - Serial.print(serialNumber); - Serial.println(); -} - -void loop() { - - float aTemperature = 0.0; - float aHumidity = 0.0; - delay(20); - error = sensor.measureLowestPrecision(aTemperature, aHumidity); - if (error != NO_ERROR) { - Serial.print("Error trying to execute measureLowestPrecision(): "); - errorToString(error, errorMessage, sizeof errorMessage); - Serial.println(errorMessage); - return; - } - Serial.print("aTemperature: "); - Serial.print(aTemperature); - Serial.print("\t"); - Serial.print("aHumidity: "); - Serial.print(aHumidity); - Serial.println(); -} diff --git a/src/library/SensirionSHT4x/images/Arduino-Mega-2560-Rev3-i2c-pinout-3.3V.png b/src/library/SensirionSHT4x/images/Arduino-Mega-2560-Rev3-i2c-pinout-3.3V.png deleted file mode 100644 index 942173d..0000000 Binary files a/src/library/SensirionSHT4x/images/Arduino-Mega-2560-Rev3-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/SensirionSHT4x/images/Arduino-Micro-i2c-pinout-3.3V.png b/src/library/SensirionSHT4x/images/Arduino-Micro-i2c-pinout-3.3V.png deleted file mode 100644 index ca9ba6c..0000000 Binary files a/src/library/SensirionSHT4x/images/Arduino-Micro-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/SensirionSHT4x/images/Arduino-Nano-i2c-pinout-3.3V.png b/src/library/SensirionSHT4x/images/Arduino-Nano-i2c-pinout-3.3V.png deleted file mode 100644 index 55fd2ff..0000000 Binary files a/src/library/SensirionSHT4x/images/Arduino-Nano-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/SensirionSHT4x/images/Arduino-Uno-Rev3-i2c-pinout-3.3V.png b/src/library/SensirionSHT4x/images/Arduino-Uno-Rev3-i2c-pinout-3.3V.png deleted file mode 100644 index a6daad7..0000000 Binary files a/src/library/SensirionSHT4x/images/Arduino-Uno-Rev3-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/SensirionSHT4x/images/SHT40_pinout.png b/src/library/SensirionSHT4x/images/SHT40_pinout.png deleted file mode 100644 index d8b293b..0000000 Binary files a/src/library/SensirionSHT4x/images/SHT40_pinout.png and /dev/null differ diff --git a/src/library/SensirionSHT4x/images/esp32-devkitc-i2c-pinout-3.3V.png b/src/library/SensirionSHT4x/images/esp32-devkitc-i2c-pinout-3.3V.png deleted file mode 100644 index 319b021..0000000 Binary files a/src/library/SensirionSHT4x/images/esp32-devkitc-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/SensirionSHT4x/images/sht4x.png b/src/library/SensirionSHT4x/images/sht4x.png deleted file mode 100644 index 21609c5..0000000 Binary files a/src/library/SensirionSHT4x/images/sht4x.png and /dev/null differ diff --git a/src/library/SensirionSHT4x/keywords.txt b/src/library/SensirionSHT4x/keywords.txt deleted file mode 100644 index 272cdd0..0000000 --- a/src/library/SensirionSHT4x/keywords.txt +++ /dev/null @@ -1,46 +0,0 @@ -####################################### -# Syntax Coloring Map -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -SensirionI2CSht4x KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -measureHighPrecision KEYWORD2 -measureMediumPrecision KEYWORD2 -measureLowestPrecision KEYWORD2 -activateHighestHeaterPowerLong KEYWORD2 -activateHighestHeaterPowerShort KEYWORD2 -activateMediumHeaterPowerLong KEYWORD2 -activateMediumHeaterPowerShort KEYWORD2 -activateLowestHeaterPowerLong KEYWORD2 -activateLowestHeaterPowerShort KEYWORD2 -measureHighPrecisionTicks KEYWORD2 -measureMediumPrecisionTicks KEYWORD2 -measureLowestPrecisionTicks KEYWORD2 -activateHighestHeaterPowerLongTicks KEYWORD2 -activateHighestHeaterPowerShortTicks KEYWORD2 -activateMediumHeaterPowerLongTicks KEYWORD2 -activateMediumHeaterPowerShortTicks KEYWORD2 -activateLowestHeaterPowerLongTicks KEYWORD2 -activateLowestHeaterPowerShortTicks KEYWORD2 -serialNumber KEYWORD2 -softReset KEYWORD2 -signalTemperature KEYWORD2 -signalHumidity KEYWORD2 - -####################################### -# Instances (KEYWORD2) -####################################### - -sensor KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### \ No newline at end of file diff --git a/src/library/SensirionSHT4x/library.properties b/src/library/SensirionSHT4x/library.properties deleted file mode 100644 index 2439e57..0000000 --- a/src/library/SensirionSHT4x/library.properties +++ /dev/null @@ -1,11 +0,0 @@ -name=Sensirion I2C SHT4x -version=1.0.0 -author=Sensirion -maintainer=Sensirion -sentence=Library for the SHT4X sensor family by Sensirion -paragraph=Enables you to use the SHT4X sensor family via I2C. -url=https://github.com/Sensirion/arduino-i2c-sht4x -category=Sensors -architectures=* -depends=Sensirion Core -includes=SensirionI2CSht4x.h diff --git a/src/library/SensirionSHT4x/metadata.yml b/src/library/SensirionSHT4x/metadata.yml deleted file mode 100644 index 488048b..0000000 --- a/src/library/SensirionSHT4x/metadata.yml +++ /dev/null @@ -1,7 +0,0 @@ -generator_version: 0.32.0 -model_version: 2.0.0 -dg_status: -- released -is_manually_modified: true -first_generated: '2021-07-06 15:05' -last_generated: '2023-10-18 07:36' diff --git a/src/library/SensirionSHT4x/src/SensirionI2CSht4x.cpp b/src/library/SensirionSHT4x/src/SensirionI2CSht4x.cpp deleted file mode 100644 index 48d67b2..0000000 --- a/src/library/SensirionSHT4x/src/SensirionI2CSht4x.cpp +++ /dev/null @@ -1,436 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * Generator: sensirion-driver-generator 0.32.0 - * Product: sht4x - * Model-Version: 2.0.0 - */ -/* - * Copyright (c) 2023, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "SensirionI2CSht4x.h" -#include "../../SensirionCore/src/SensirionCore.h" -#include - - -static uint8_t communication_buffer[6] = {0}; - -SensirionI2CSht4x::SensirionI2CSht4x() { -} - -float SensirionI2CSht4x::signalTemperature(uint16_t temperatureTicks) { - float temperature = 0.0; - temperature = (float)(temperatureTicks); - temperature = (float)((temperature * 175.0) / 65535.0) - 45.0; - return temperature; -} - -float SensirionI2CSht4x::signalHumidity(uint16_t humidityTicks) { - float humidity = 0.0; - humidity = (float)(humidityTicks); - humidity = (float)((humidity * 125.0) / 65535.0) - 6.0; - return humidity; -} - -int16_t SensirionI2CSht4x::measureHighPrecision(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = measureHighPrecisionTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::measureMediumPrecision(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = measureMediumPrecisionTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::measureLowestPrecision(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = measureLowestPrecisionTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateHighestHeaterPowerLong(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = activateHighestHeaterPowerLongTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateHighestHeaterPowerShort(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = activateHighestHeaterPowerShortTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateMediumHeaterPowerLong(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = activateMediumHeaterPowerLongTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateMediumHeaterPowerShort(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = activateMediumHeaterPowerShortTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateLowestHeaterPowerLong(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = activateLowestHeaterPowerLongTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateLowestHeaterPowerShort(float& aTemperature, - float& aHumidity) { - uint16_t tempTicks = 0; - uint16_t humiTicks = 0; - int16_t localError = 0; - localError = activateLowestHeaterPowerShortTicks(tempTicks, humiTicks); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(tempTicks); - aHumidity = signalHumidity(humiTicks); - return localError; -} - -int16_t SensirionI2CSht4x::measureHighPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0xfd, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(10); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t -SensirionI2CSht4x::measureMediumPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0xf6, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t -SensirionI2CSht4x::measureLowestPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0xe0, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(2); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateHighestHeaterPowerLongTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x39, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(1100); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateHighestHeaterPowerShortTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x32, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(110); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateMediumHeaterPowerLongTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x2f, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(1100); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateMediumHeaterPowerShortTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x24, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(110); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateLowestHeaterPowerLongTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x1e, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(1100); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2CSht4x::activateLowestHeaterPowerShortTicks( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x15, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(110); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2CSht4x::serialNumber(uint32_t& serialNumber) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x89, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(10); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt32(serialNumber); - return localError; -} - -int16_t SensirionI2CSht4x::softReset() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt8Command(0x94, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(10); - return localError; -} - -void SensirionI2CSht4x::begin(TwoWire& i2cBus, uint8_t i2cAddress) { - _i2cBus = &i2cBus; - _i2cAddress = i2cAddress; -} diff --git a/src/library/SensirionSHT4x/src/SensirionI2CSht4x.h b/src/library/SensirionSHT4x/src/SensirionI2CSht4x.h deleted file mode 100644 index f3115f0..0000000 --- a/src/library/SensirionSHT4x/src/SensirionI2CSht4x.h +++ /dev/null @@ -1,424 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * Generator: sensirion-driver-generator 0.32.0 - * Product: sht4x - * Model-Version: 2.0.0 - */ -/* - * Copyright (c) 2023, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SENSIRIONI2CSHT4X_H -#define SENSIRIONI2CSHT4X_H - -#include - -#define NO_ERROR 0 -#define SHT40_I2C_ADDR_44 0x44 -#define SHT40_I2C_ADDR_45 0x45 -#define SHT41_I2C_ADDR_44 0x44 -#define SHT41_I2C_ADDR_45 0x45 -#define SHT45_I2C_ADDR_44 0x44 -#define SHT45_I2C_ADDR_45 0x45 - -typedef enum { - MEASURE_HIGH_PRECISION_TICKS_CMD_ID = 0xfd, - MEASURE_MEDIUM_PRECISION_TICKS_CMD_ID = 0xf6, - MEASURE_LOWEST_PRECISION_TICKS_CMD_ID = 0xe0, - ACTIVATE_HIGHEST_HEATER_POWER_LONG_TICKS_CMD_ID = 0x39, - ACTIVATE_HIGHEST_HEATER_POWER_SHORT_TICKS_CMD_ID = 0x32, - ACTIVATE_MEDIUM_HEATER_POWER_LONG_TICKS_CMD_ID = 0x2f, - ACTIVATE_MEDIUM_HEATER_POWER_SHORT_TICKS_CMD_ID = 0x24, - ACTIVATE_LOWEST_HEATER_POWER_LONG_TICKS_CMD_ID = 0x1e, - ACTIVATE_LOWEST_HEATER_POWER_SHORT_TICKS_CMD_ID = 0x15, - SERIAL_NUMBER_CMD_ID = 0x89, - SOFT_RESET_CMD_ID = 0x94, -} CmdId; - -class SensirionI2CSht4x { - public: - SensirionI2CSht4x(); - /** - * @brief Initializes the SHT4x class. - * - * @param i2cBus Arduino stream object to be used for communication. - */ - void begin(TwoWire& i2cBus, uint8_t i2cAddress); - - /** - * @brief Run measurement with high precision - * - * SHT4x command for a single shot measurement with high repeatability. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureHighPrecision(float& aTemperature, float& aHumidity); - - /** - * @brief Run measurement with medium precision - * - * SHT4x command for a single shot measurement with medium repeatability. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureMediumPrecision(float& aTemperature, float& aHumidity); - - /** - * @brief Run measurement with low precision - * - * SHT4x command for a single shot measurement with low repeatability. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureLowestPrecision(float& aTemperature, float& aHumidity); - - /** - * @brief Run measurement with high precision and the highest power heater - * for 1s - * - * SHT4x command to activate highest heater power and perform a single shot - * high precision measurement for 1s. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateHighestHeaterPowerLong(float& aTemperature, - float& aHumidity); - - /** - * @brief Run measurement with high precision and the highest power heater - * for 0.1s - * - * SHT4x command to activate highest heater power and perform a single shot - * high precision measurement for 0.1s. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateHighestHeaterPowerShort(float& aTemperature, - float& aHumidity); - - /** - * @brief Run measurement with high precision and the medium power heater - * for 1s - * - * SHT4x command to activate medium heater power and perform a single shot - * high precision measurement for 1s. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateMediumHeaterPowerLong(float& aTemperature, - float& aHumidity); - - /** - * @brief Run measurement with high precision and the medium power heater - * for 0.1s - * - * SHT4x command to activate medium heater power and perform a single shot - * high precision measurement for 0.1s. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateMediumHeaterPowerShort(float& aTemperature, - float& aHumidity); - - /** - * @brief Run measurement with high precision and the lowest power heater - * for 1s - * - * SHT4x command to activate lowest heater power and perform a single shot - * high precision measurement for 1s. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateLowestHeaterPowerLong(float& aTemperature, - float& aHumidity); - - /** - * @brief Run measurement with high precision and the lowest power heater - * for 0.1s - * - * SHT4x command to activate lowest heater power and perform a single shot - * high precision measurement for 0.1s. - * - * @param[out] aTemperature Converted from ticks to degrees celsius by (175 - * * ticks_value / 65535) - 45 - * @param[out] aHumidity Converted from ticks to percent relative humdity by - * (125 * ticks_value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateLowestHeaterPowerShort(float& aTemperature, - float& aHumidity); - - /** - * @brief measureHighPrecisionTicks - * - * SHT4x command for a single shot measurement with high repeatability. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureHighPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief measureMediumPrecisionTicks - * - * SHT4x command for a single shot measurement with medium repeatability. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureMediumPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief measureLowestPrecisionTicks - * - * SHT4x command for a single shot measurement with lowest repeatability. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureLowestPrecisionTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief activateHighestHeaterPowerLongTicks - * - * SHT4x command to activate highest heater power and perform a single shot - * high precision measurement for 1s. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateHighestHeaterPowerLongTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief activateHighestHeaterPowerShortTicks - * - * SHT4x command to activate highest heater power and perform a single shot - * high precision measurement for 0.1s. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateHighestHeaterPowerShortTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief activateMediumHeaterPowerLongTicks - * - * SHT4x command to activate medium heater power and perform a single shot - * high precision measurement for 1s. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateMediumHeaterPowerLongTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief activateMediumHeaterPowerShortTicks - * - * SHT4x command to activate medium heater power and perform a single shot - * high precision measurement for 0.1s. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateMediumHeaterPowerShortTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief activateLowestHeaterPowerLongTicks - * - * SHT4x command to activate lowest heater power and perform a single shot - * high precision measurement for 1s. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateLowestHeaterPowerLongTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief activateLowestHeaterPowerShortTicks - * - * SHT4x command to activate lowest heater power and perform a single shot - * high precision measurement for 0.1s. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by (175 * value / 65535) - 45 - * @param[out] humidityTicks Humidity ticks. Convert to degrees celsius by - * (125 - * * value / 65535) - 6 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t activateLowestHeaterPowerShortTicks(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief serialNumber - * - * Read out the serial number - * - * @param[out] serialNumber Unique serial number - * - * @note Each sensor has a unique serial number that is assigned by - * Sensirion during production.It is stored in the one-time-programmable - * memory and cannot be manipulated after production. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t serialNumber(uint32_t& serialNumber); - - /** - * @brief softReset - * - * Perform a soft reset. - * - * @note A reset of the sensor can be achieved in three ways: • Soft reset: - * use this function • I2C general call: all devices on the I2C bus are - * reset by sending the command 0x06 to the I2C address 0x00. • Power down - * (incl.pulling SCL and SDA low) - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t softReset(); - - private: - TwoWire* _i2cBus = nullptr; - uint8_t _i2cAddress = 0; - - /** - * @brief signalTemperature - * - * @param[in] temperatureTicks - * - * @return Converted from ticks to degrees celsius by (175 * ticks_value / - * 65535) - 45 - */ - float signalTemperature(uint16_t temperatureTicks); - - /** - * @brief signalHumidity - * - * @param[in] humidityTicks - * - * @return Converted from ticks to percent relative humdity by (125 * - * ticks_value / 65535) - 6 - */ - float signalHumidity(uint16_t humidityTicks); -}; - -#endif // SENSIRIONI2CSHT4X_H diff --git a/src/library/arduino-i2c-sht3x/.clang-format b/src/library/arduino-i2c-sht3x/.clang-format deleted file mode 100644 index 047f2ad..0000000 --- a/src/library/arduino-i2c-sht3x/.clang-format +++ /dev/null @@ -1,14 +0,0 @@ ---- -Language: Cpp -BasedOnStyle: LLVM -IndentWidth: 4 -AlignAfterOpenBracket: Align -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: false -IndentCaseLabels: true -SpacesBeforeTrailingComments: 2 -PointerAlignment: Left -AlignEscapedNewlines: Left -ForEachMacros: ['TEST_GROUP', 'TEST'] -... diff --git a/src/library/arduino-i2c-sht3x/.gitlab-ci.yml b/src/library/arduino-i2c-sht3x/.gitlab-ci.yml deleted file mode 100644 index 1b859e0..0000000 --- a/src/library/arduino-i2c-sht3x/.gitlab-ci.yml +++ /dev/null @@ -1,110 +0,0 @@ -stages: - - validate - - test - -variables: - YQ_URL: https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64 - -compile_test: - stage: test - image: - name: registry.gitlab.sensirion.lokal/sensirion/docker/docker-arduino:0.4.0 - tags: [docker, linux] - before_script: - - rm -rf ../sensirion-core-arduino-library - script: - - git clone --depth 1 --branch 0.5.2 https://github.com/Sensirion/arduino-core.git ../sensirion-core-arduino-library - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:samd:mkrzero ./examples/exampleUsageSingleShot/exampleUsageSingleShot.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:mega ./examples/exampleUsageSingleShot/exampleUsageSingleShot.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:nano ./examples/exampleUsageSingleShot/exampleUsageSingleShot.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:uno ./examples/exampleUsageSingleShot/exampleUsageSingleShot.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn esp32:esp32:esp32 ./examples/exampleUsageSingleShot/exampleUsageSingleShot.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn esp8266:esp8266:generic ./examples/exampleUsageSingleShot/exampleUsageSingleShot.ino - - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:samd:mkrzero ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:mega ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:nano ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn arduino:avr:uno ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn esp32:esp32:esp32 ./examples/exampleUsage/exampleUsage.ino - - arduino-cli compile --libraries=".." --warnings all --fqbn esp8266:esp8266:generic ./examples/exampleUsage/exampleUsage.ino - -arduino_lint: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - mkdir ~/arlint - - PATH=~/arlint:$PATH - - curl -fsSL https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh | BINDIR=~/arlint sh - - arduino-lint --library-manager false - -syntax_check: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - find . -type f -iregex ".*\.\(c\|h\|cpp\|ino\)" -exec clang-format-6.0 -i -style=file {} \; && git diff --exit-code - - -cppcheck: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - cppcheck --std=c++11 --language=c++ --error-exitcode=1 --enable=warning,style,performance,portability --suppress=unreadVariable src/* - -TODO_check: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - script: - - '! grep -rnw --exclude=.gitlab-ci.yml --exclude-dir=.git . -e "TODO"' - -metadata_check: - stage: validate - image: - name: registry.gitlab.sensirion.lokal/mso-sw/drivers/docker-driver-generator:0.2.0 - tags: [linux, docker] - before_script: - - apt-get -qq update && apt-get -qq install -y wget - - if ! [ -d downloads/ ]; then mkdir downloads; fi - - if ! [ -e downloads/yq ]; then wget --no-verbose $YQ_URL -O downloads/yq; fi - - cp downloads/yq /usr/local/bin/yq && chmod +x /usr/local/bin/yq - script: - # check if metadata.yml exists - - > - if ! [ -f "metadata.yml" ]; then - echo "metadata.yml file not found" - exit 1 - fi - # check that dg_status is 'released' - - export DG_STATUS=$(yq ".dg_status.[]" ./metadata.yml) - - > - if [ $DG_STATUS != "released" ]; then - echo "dg_status in metadata.yml has to be 'released', not '$DG_STATUS'" - exit 1 - fi - # check that last_generated is not older than timestamp of last non-merge commit (+ 3 minutes) - - export IS_MANUALLY_MODIFIED=$(yq ".is_manually_modified" ./metadata.yml) - - > - if [ $IS_MANUALLY_MODIFIED = false ]; then - export LAST_GENERATED_TS=$(yq ".last_generated" ./metadata.yml) - export LAST_GENERATED_TS_EPOCH=$(date -d "$LAST_GENERATED_TS" +%s) - export LAST_NON_MERGE_COMMIT_TS=$(git log --format=%ad --date=iso-strict --no-merges -1) - export COMMIT_TS_EPOCH=$(date -d "$LAST_NON_MERGE_COMMIT_TS" +%s) - if [ $(($LAST_GENERATED_TS_EPOCH + 180)) -lt $COMMIT_TS_EPOCH ]; then - echo "'last_generated' timestamp in metadata.yml is older than commit timestamp ($LAST_GENERATED_TS vs $LAST_NON_MERGE_COMMIT_TS)" - exit 1 - fi - fi - # check that 'is_manually_modified' is set to true if commit is not from driver generator - - export LAST_NON_MERGE_COMMIT_AUTHOR=$(git log --format=%an --no-merges -1) - - > - if ! [ "$LAST_NON_MERGE_COMMIT_AUTHOR" = "Driver Generator 2" ] && [ "$IS_MANUALLY_MODIFIED" = false ]; then - echo "Last commit is not from Driver Generator. Please update 'is_manually_modified' in metadata.yml" - exit 1 - fi \ No newline at end of file diff --git a/src/library/arduino-i2c-sht3x/CHANGELOG.md b/src/library/arduino-i2c-sht3x/CHANGELOG.md deleted file mode 100644 index 5baa52d..0000000 --- a/src/library/arduino-i2c-sht3x/CHANGELOG.md +++ /dev/null @@ -1,13 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - - -## [Unreleased] - -## [1.0.0] - 2023-10-27 - -Initial release - diff --git a/src/library/arduino-i2c-sht3x/LICENSE b/src/library/arduino-i2c-sht3x/LICENSE deleted file mode 100644 index f95f5fe..0000000 --- a/src/library/arduino-i2c-sht3x/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2023, Sensirion AG -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/library/arduino-i2c-sht3x/README.md b/src/library/arduino-i2c-sht3x/README.md deleted file mode 100644 index b77edaa..0000000 --- a/src/library/arduino-i2c-sht3x/README.md +++ /dev/null @@ -1,217 +0,0 @@ -# Sensirion I²C SHT3X Arduino Library - -This is the Sensirion SHT3X library for Arduino allowing you to -communicate with a sensor of the SHT3X family over I²C. - - - -Click [here](https://sensirion.com/products/catalog/SHT30-DIS-B) to learn more about the Sensirion SHT3X sensor family. - - -Not all sensors of this driver family support all measurements. -In case a measurement is not supported by all sensors, the products that -support it are listed in the API description. - - - -## Supported sensor types - -| Sensor name | I²C Addresses | -| ------------- | -------------- | -|[SHT30A](https://sensirion.com/products/catalog/SHT30A-DIS-B)| **0x44**, 0x45| -|[SHT30](https://sensirion.com/products/catalog/SHT30-DIS-B)| **0x44**, 0x45| -|[SHT31A](https://sensirion.com/products/catalog/SHT31A-DIS-B)| **0x44**, 0x45| -|[SHT31](https://sensirion.com/products/catalog/SHT31-DIS-B)| **0x44**, 0x45| -|[SHT33](https://sensirion.com/products/catalog/SHT33-DIS)| **0x44**, 0x45| -|[SHT35A](https://sensirion.com/products/catalog/SHT35A-DIS-B)| **0x44**, 0x45| -|[SHT35](https://sensirion.com/products/catalog/SHT35-DIS-B)| **0x44**, 0x45| -|[SHT85](https://sensirion.com/sht85)| **0x44** | - -The following instructions and examples use a *SHT30*. - - - -## Installation of the library - -This library can be installed using the Arduino Library manager: -Start the [Arduino IDE](http://www.arduino.cc/en/main/software) and open -the Library Manager via - -`Sketch` ➔ `Include Library` ➔ `Manage Libraries...` - -Search for the `Sensirion I2C SHT3X` library in the `Filter -your search...` field and install it by clicking the `install` button. - -If you cannot find it in the library manager, download the latest release as .zip file -and add it to your [Arduino IDE](http://www.arduino.cc/en/main/software) via - -`Sketch` ➔ `Include Library` ➔ `Add .ZIP Library...` - -Don't forget to **install the dependencies** listed below the same way via library -manager or `Add .ZIP Library` - -#### Dependencies -* [Sensirion Core](https://github.com/Sensirion/arduino-core) - -## Sensor wiring - -Use the following pin description to connect your SHT3X to the standard I²C bus of your Arduino board: - - - -| *Pin* | *Cable Color* | *Name* | *Description* | *Comments* | -|-------|---------------|:------:|----------------|------------| -| 1 | green | SDA | I2C: Serial data input / output | -| 2 | black | GND | Ground | -| 3 | yellow | SCL | I2C: Serial clock input | -| 4 | red | VDD | Supply Voltage | 2.15V to 5.5V - - - - -The recommended voltage is 3.3V. - -### Board specific wiring -You will find pinout schematics for recommended board models below: - - - -
Arduino Uno -

- -| *SHT3X* | *SHT3X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | D18/SDA | -| GND | 2 | black | GND | -| SCL | 3 | yellow | D19/SCL | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
Arduino Nano -

- -| *SHT3X* | *SHT3X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | A4 | -| GND | 2 | black | GND | -| SCL | 3 | yellow | A5 | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
Arduino Micro -

- -| *SHT3X* | *SHT3X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | D2/SDA | -| GND | 2 | black | GND | -| SCL | 3 | yellow | ~D3/SCL | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
Arduino Mega 2560 -

- -| *SHT3X* | *SHT3X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | D20/SDA | -| GND | 2 | black | GND | -| SCL | 3 | yellow | D21/SCL | -| VDD | 4 | red | 3.3V | - - - - -

-
- - - -
ESP32 DevKitC -

- -| *SHT3X* | *SHT3X Pin* | *Cable Color* | *Board Pin* | -| :---: | --- | --- | --- | -| SDA | 1 | green | GPIO 21 | -| GND | 2 | black | GND | -| SCL | 3 | yellow | GPIO 22 | -| VDD | 4 | red | 3V3 | - - - - -

-
- - -## Quick Start - -1. Install the libraries and dependencies according to [Installation of the library](#installation-of-the-library) - -2. Connect the SHT3X sensor to your Arduino as explained in [Sensor wiring](#sensor-wiring) - -3. Open the `exampleUsage` sample project within the Arduino IDE: - - `File` ➔ `Examples` ➔ `Sensirion I2C SHT3X` ➔ `exampleUsage` - - - The provided example is working with a SHT30, I²C address 0x44. - In order to use the code with another product or I²C address you need to change it in the code of `exampleUsage`. - You find the list with pre-defined addresses in `src/SensirionI2CSht3x.h`. - - -5. Click the `Upload` button in the Arduino IDE or `Sketch` ➔ `Upload` - -4. When the upload process has finished, open the `Serial Monitor` or `Serial - Plotter` via the `Tools` menu to observe the measurement values. Note that - the `Baud Rate` in the used tool has to be set to `115200 baud`. - -## Contributing - -**Contributions are welcome!** - -We develop and test this driver using our company internal tools (version -control, continuous integration, code review etc.) and automatically -synchronize the master branch with GitHub. But this doesn't mean that we don't -respond to issues or don't accept pull requests on GitHub. In fact, you're very -welcome to open issues or create pull requests :) - -This Sensirion library uses -[`clang-format`](https://releases.llvm.org/download.html) to standardize the -formatting of all our `.cpp` and `.h` files. Make sure your contributions are -formatted accordingly: - -The `-i` flag will apply the format changes to the files listed. - -```bash -clang-format -i src/*.cpp src/*.h -``` - -Note that differences from this formatting will result in a failed build until -they are fixed. - - -## License - -See [LICENSE](LICENSE). diff --git a/src/library/arduino-i2c-sht3x/examples/exampleUsage/exampleUsage.ino b/src/library/arduino-i2c-sht3x/examples/exampleUsage/exampleUsage.ino deleted file mode 100644 index 06a6945..0000000 --- a/src/library/arduino-i2c-sht3x/examples/exampleUsage/exampleUsage.ino +++ /dev/null @@ -1,98 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * Generator: sensirion-driver-generator 0.33.0 - * Product: sht3x - * Model-Version: 1.0.0 - */ -/* - * Copyright (c) 2023, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include - -SensirionI2cSht3x sensor; - -static char errorMessage[64]; -static int16_t error; - -void setup() { - - Serial.begin(115200); - while (!Serial) { - delay(100); - } - Wire.begin(); - sensor.begin(Wire, SHT30_I2C_ADDR_44); - - sensor.stopMeasurement(); - delay(1); - sensor.softReset(); - delay(100); - uint16_t aStatusRegister = 0u; - error = sensor.readStatusRegister(aStatusRegister); - if (error != NO_ERROR) { - Serial.print("Error trying to execute readStatusRegister(): "); - errorToString(error, errorMessage, sizeof errorMessage); - Serial.println(errorMessage); - return; - } - Serial.print("aStatusRegister: "); - Serial.print(aStatusRegister); - Serial.println(); - error = sensor.startPeriodicMeasurement(REPEATABILITY_MEDIUM, - MPS_ONE_PER_SECOND); - if (error != NO_ERROR) { - Serial.print("Error trying to execute startPeriodicMeasurement(): "); - errorToString(error, errorMessage, sizeof errorMessage); - Serial.println(errorMessage); - return; - } -} - -void loop() { - - float aTemperature = 0.0; - float aHumidity = 0.0; - error = sensor.blockingReadMeasurement(aTemperature, aHumidity); - if (error != NO_ERROR) { - Serial.print("Error trying to execute blockingReadMeasurement(): "); - errorToString(error, errorMessage, sizeof errorMessage); - Serial.println(errorMessage); - return; - } - Serial.print("aTemperature: "); - Serial.print(aTemperature); - Serial.print("\t"); - Serial.print("aHumidity: "); - Serial.print(aHumidity); - Serial.println(); -} diff --git a/src/library/arduino-i2c-sht3x/examples/exampleUsageSingleShot/exampleUsageSingleShot.ino b/src/library/arduino-i2c-sht3x/examples/exampleUsageSingleShot/exampleUsageSingleShot.ino deleted file mode 100644 index 0d65fc5..0000000 --- a/src/library/arduino-i2c-sht3x/examples/exampleUsageSingleShot/exampleUsageSingleShot.ino +++ /dev/null @@ -1,91 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * Generator: sensirion-driver-generator 0.33.0 - * Product: sht3x - * Model-Version: 1.0.0 - */ -/* - * Copyright (c) 2023, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include - -SensirionI2cSht3x sensor; - -static char errorMessage[64]; -static int16_t error; - -void setup() { - - Serial.begin(115200); - while (!Serial) { - delay(100); - } - Wire.begin(); - sensor.begin(Wire, SHT30_I2C_ADDR_44); - - sensor.stopMeasurement(); - delay(1); - sensor.softReset(); - delay(100); - uint16_t aStatusRegister = 0u; - error = sensor.readStatusRegister(aStatusRegister); - if (error != NO_ERROR) { - Serial.print("Error trying to execute readStatusRegister(): "); - errorToString(error, errorMessage, sizeof errorMessage); - Serial.println(errorMessage); - return; - } - Serial.print("aStatusRegister: "); - Serial.print(aStatusRegister); - Serial.println(); -} - -void loop() { - - float aTemperature = 0.0; - float aHumidity = 0.0; - error = sensor.measureSingleShot(REPEATABILITY_MEDIUM, false, aTemperature, - aHumidity); - if (error != NO_ERROR) { - Serial.print("Error trying to execute measureSingleShot(): "); - errorToString(error, errorMessage, sizeof errorMessage); - Serial.println(errorMessage); - return; - } - Serial.print("aTemperature: "); - Serial.print(aTemperature); - Serial.print("\t"); - Serial.print("aHumidity: "); - Serial.print(aHumidity); - Serial.println(); -} diff --git a/src/library/arduino-i2c-sht3x/images/Arduino-Mega-2560-Rev3-i2c-pinout-3.3V.png b/src/library/arduino-i2c-sht3x/images/Arduino-Mega-2560-Rev3-i2c-pinout-3.3V.png deleted file mode 100644 index 942173d..0000000 Binary files a/src/library/arduino-i2c-sht3x/images/Arduino-Mega-2560-Rev3-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/arduino-i2c-sht3x/images/Arduino-Micro-i2c-pinout-3.3V.png b/src/library/arduino-i2c-sht3x/images/Arduino-Micro-i2c-pinout-3.3V.png deleted file mode 100644 index ca9ba6c..0000000 Binary files a/src/library/arduino-i2c-sht3x/images/Arduino-Micro-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/arduino-i2c-sht3x/images/Arduino-Nano-i2c-pinout-3.3V.png b/src/library/arduino-i2c-sht3x/images/Arduino-Nano-i2c-pinout-3.3V.png deleted file mode 100644 index 55fd2ff..0000000 Binary files a/src/library/arduino-i2c-sht3x/images/Arduino-Nano-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/arduino-i2c-sht3x/images/Arduino-Uno-Rev3-i2c-pinout-3.3V.png b/src/library/arduino-i2c-sht3x/images/Arduino-Uno-Rev3-i2c-pinout-3.3V.png deleted file mode 100644 index a6daad7..0000000 Binary files a/src/library/arduino-i2c-sht3x/images/Arduino-Uno-Rev3-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/arduino-i2c-sht3x/images/SHT3x.png b/src/library/arduino-i2c-sht3x/images/SHT3x.png deleted file mode 100644 index 795f29d..0000000 Binary files a/src/library/arduino-i2c-sht3x/images/SHT3x.png and /dev/null differ diff --git a/src/library/arduino-i2c-sht3x/images/SHT3x_pinout.png b/src/library/arduino-i2c-sht3x/images/SHT3x_pinout.png deleted file mode 100644 index d8b293b..0000000 Binary files a/src/library/arduino-i2c-sht3x/images/SHT3x_pinout.png and /dev/null differ diff --git a/src/library/arduino-i2c-sht3x/images/esp32-devkitc-i2c-pinout-3.3V.png b/src/library/arduino-i2c-sht3x/images/esp32-devkitc-i2c-pinout-3.3V.png deleted file mode 100644 index 319b021..0000000 Binary files a/src/library/arduino-i2c-sht3x/images/esp32-devkitc-i2c-pinout-3.3V.png and /dev/null differ diff --git a/src/library/arduino-i2c-sht3x/keywords.txt b/src/library/arduino-i2c-sht3x/keywords.txt deleted file mode 100644 index 388e59e..0000000 --- a/src/library/arduino-i2c-sht3x/keywords.txt +++ /dev/null @@ -1,59 +0,0 @@ -####################################### -# Syntax Coloring Map -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -SensirionI2cSht3x KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -measureSingleShot KEYWORD2 -startPeriodicMeasurement KEYWORD2 -blockingReadMeasurement KEYWORD2 -readStatusRegister KEYWORD2 -measureSingleShotHighRepeatability KEYWORD2 -measureSingleShotHighRepeatabilityClockStretching KEYWORD2 -measureSingleShotMediumRepeatability KEYWORD2 -measureSingleShotMediumRepeatabilityClockStretching KEYWORD2 -measureSingleShotLowRepeatability KEYWORD2 -measureSingleShotLowRepeatabilityClockStretching KEYWORD2 -startMeasurement05MpsHighRepeatability KEYWORD2 -startMeasurement05MpsMediumRepeatability KEYWORD2 -startMeasurement05MpsLowRepeatability KEYWORD2 -startMeasurement1MpsHighRepeatability KEYWORD2 -startMeasurement1MpsMediumRepeatability KEYWORD2 -startMeasurement1MpsLowRepeatability KEYWORD2 -startMeasurement2MpsHighRepeatability KEYWORD2 -startMeasurement2MpsMediumRepeatability KEYWORD2 -startMeasurement2MpsLowRepeatability KEYWORD2 -startMeasurement4MpsHighRepeatability KEYWORD2 -startMeasurement4MpsMediumRepeatability KEYWORD2 -startMeasurement4MpsLowRepeatability KEYWORD2 -startMeasurement10MpsHighRepeatability KEYWORD2 -startMeasurement10MpsMediumRepeatability KEYWORD2 -startMeasurement10MpsLowRepeatability KEYWORD2 -startArtMeasurement KEYWORD2 -readMeasurement KEYWORD2 -stopMeasurement KEYWORD2 -enableHeater KEYWORD2 -disableHeater KEYWORD2 -llreadStatusRegister KEYWORD2 -clearStatusRegister KEYWORD2 -softReset KEYWORD2 -signalTemperature KEYWORD2 -signalHumidity KEYWORD2 - -####################################### -# Instances (KEYWORD2) -####################################### - -sensor KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### \ No newline at end of file diff --git a/src/library/arduino-i2c-sht3x/library.properties b/src/library/arduino-i2c-sht3x/library.properties deleted file mode 100644 index 0a86b30..0000000 --- a/src/library/arduino-i2c-sht3x/library.properties +++ /dev/null @@ -1,11 +0,0 @@ -name=SensirionI2cSht3x -version=1.0.0 -author=Sensirion -maintainer=Sensirion -sentence=Library for the SHT3X sensor family by Sensirion -paragraph=Enables you to use the SHT3X sensor family via I2C. -url=https://github.com/Sensirion/arduino-i2c-sht3x -category=Sensors -architectures=* -depends=Sensirion Core -includes=SensirionI2cSht3x.h diff --git a/src/library/arduino-i2c-sht3x/metadata.yml b/src/library/arduino-i2c-sht3x/metadata.yml deleted file mode 100644 index c438e43..0000000 --- a/src/library/arduino-i2c-sht3x/metadata.yml +++ /dev/null @@ -1,7 +0,0 @@ -generator_version: 0.33.0 -model_version: 1.0.0 -dg_status: -- released -is_manually_modified: true -first_generated: '2023-10-27 14:38' -last_generated: '2023-10-27 14:38' diff --git a/src/library/arduino-i2c-sht3x/src/SensirionI2cSht3x.cpp b/src/library/arduino-i2c-sht3x/src/SensirionI2cSht3x.cpp deleted file mode 100644 index 8d7d6fe..0000000 --- a/src/library/arduino-i2c-sht3x/src/SensirionI2cSht3x.cpp +++ /dev/null @@ -1,720 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * Generator: sensirion-driver-generator 0.33.0 - * Product: sht3x - * Model-Version: 1.0.0 - */ -/* - * Copyright (c) 2023, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "SensirionI2cSht3x.h" -#include - -static uint8_t communication_buffer[6] = {0}; - -SensirionI2cSht3x::SensirionI2cSht3x() { -} - -float SensirionI2cSht3x::signalTemperature(uint16_t temperatureTicks) { - float temperature = 0.0; - temperature = (float)(temperatureTicks); - temperature = -45 + ((temperature * 175.0) / 65535.0); - return temperature; -} - -float SensirionI2cSht3x::signalHumidity(uint16_t humidityTicks) { - float humidity = 0.0; - humidity = (float)(humidityTicks); - humidity = (100 * humidity) / 65535.0; - return humidity; -} - -int16_t -SensirionI2cSht3x::measureSingleShot(Repeatability measurementRepeatability, - bool isClockStretching, - float& aTemperature, float& aHumidity) { - uint16_t rawTemp = 0; - uint16_t rawHumi = 0; - int16_t localError = 0; - if (isClockStretching) { - if (measurementRepeatability == REPEATABILITY_HIGH) { - localError = measureSingleShotHighRepeatabilityClockStretching( - rawTemp, rawHumi); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_MEDIUM) { - localError = measureSingleShotMediumRepeatabilityClockStretching( - rawTemp, rawHumi); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_LOW) { - localError = measureSingleShotLowRepeatabilityClockStretching( - rawTemp, rawHumi); - if (localError != NO_ERROR) { - return localError; - } - } - } else if (measurementRepeatability == REPEATABILITY_HIGH) { - localError = measureSingleShotHighRepeatability(rawTemp, rawHumi); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_MEDIUM) { - localError = measureSingleShotMediumRepeatability(rawTemp, rawHumi); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_LOW) { - localError = measureSingleShotLowRepeatability(rawTemp, rawHumi); - if (localError != NO_ERROR) { - return localError; - } - } - aTemperature = signalTemperature(rawTemp); - aHumidity = signalHumidity(rawHumi); - return localError; -} - -int16_t SensirionI2cSht3x::startPeriodicMeasurement( - Repeatability measurementRepeatability, Mps messagesPerSecond) { - int16_t localError = 0; - if (messagesPerSecond == MPS_EVERY_TWO_SECONDS) { - if (measurementRepeatability == REPEATABILITY_HIGH) { - localError = startMeasurement05MpsHighRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_MEDIUM) { - localError = startMeasurement05MpsMediumRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_LOW) { - localError = startMeasurement05MpsLowRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } - } else if (messagesPerSecond == MPS_ONE_PER_SECOND) { - if (measurementRepeatability == REPEATABILITY_HIGH) { - localError = startMeasurement1MpsHighRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_MEDIUM) { - localError = startMeasurement1MpsMediumRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_LOW) { - localError = startMeasurement1MpsLowRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } - } else if (messagesPerSecond == MPS_TWO_PER_SECOND) { - if (measurementRepeatability == REPEATABILITY_HIGH) { - localError = startMeasurement2MpsHighRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_MEDIUM) { - localError = startMeasurement2MpsMediumRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_LOW) { - localError = startMeasurement2MpsLowRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } - } else if (messagesPerSecond == MPS_FOUR_PER_SECOND) { - if (measurementRepeatability == REPEATABILITY_HIGH) { - localError = startMeasurement4MpsHighRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_MEDIUM) { - localError = startMeasurement4MpsMediumRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_LOW) { - localError = startMeasurement4MpsLowRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } - } else if (messagesPerSecond == MPS_TEN_PER_SECOND) { - if (measurementRepeatability == REPEATABILITY_HIGH) { - localError = startMeasurement10MpsHighRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_MEDIUM) { - localError = startMeasurement10MpsMediumRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } else if (measurementRepeatability == REPEATABILITY_LOW) { - localError = startMeasurement10MpsLowRepeatability(); - if (localError != NO_ERROR) { - return localError; - } - } - } - return localError; -} - -int16_t SensirionI2cSht3x::blockingReadMeasurement(float& aTemperature, - float& aHumidity) { - uint16_t status = 0u; - uint16_t dataReadyFlag = 0u; - uint16_t rawTemp = 0; - uint16_t rawHumi = 0; - int16_t localError = 0; - localError = llreadStatusRegister(status); - if (localError != NO_ERROR) { - return localError; - } - dataReadyFlag = (status >> 6) & 15; - while (dataReadyFlag == 0) { - delay(100); - localError = llreadStatusRegister(status); - if (localError != NO_ERROR) { - return localError; - } - dataReadyFlag = (status >> 6) & 15; - } - localError = readMeasurement(rawTemp, rawHumi); - if (localError != NO_ERROR) { - return localError; - } - aTemperature = signalTemperature(rawTemp); - aHumidity = signalHumidity(rawHumi); - return localError; -} - -int16_t SensirionI2cSht3x::readStatusRegister(uint16_t& aStatusRegister) { - uint16_t status = 0u; - int16_t localError = 0; - localError = llreadStatusRegister(status); - if (localError != NO_ERROR) { - return localError; - } - aStatusRegister = static_cast(status); - - return localError; -} - -int16_t SensirionI2cSht3x::measureSingleShotHighRepeatability( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2400, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(16); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2cSht3x::measureSingleShotHighRepeatabilityClockStretching( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2c06, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(16); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2cSht3x::measureSingleShotMediumRepeatability( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x240b, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(7); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2cSht3x::measureSingleShotMediumRepeatabilityClockStretching( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2c0d, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(7); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t -SensirionI2cSht3x::measureSingleShotLowRepeatability(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2416, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2cSht3x::measureSingleShotLowRepeatabilityClockStretching( - uint16_t& temperatureTicks, uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2c10, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement05MpsHighRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2032, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(16); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement05MpsMediumRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2024, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(7); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement05MpsLowRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x202f, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement1MpsHighRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2130, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(16); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement1MpsMediumRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2126, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(7); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement1MpsLowRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x212d, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement2MpsHighRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2236, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(16); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement2MpsMediumRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2220, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(7); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement2MpsLowRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x222b, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement4MpsHighRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2334, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(16); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement4MpsMediumRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2322, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(7); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement4MpsLowRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2329, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement10MpsHighRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2737, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(16); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement10MpsMediumRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2721, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(7); - return localError; -} - -int16_t SensirionI2cSht3x::startMeasurement10MpsLowRepeatability() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x273a, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(5); - return localError; -} - -int16_t SensirionI2cSht3x::startArtMeasurement() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x2b32, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - return localError; -} - -int16_t SensirionI2cSht3x::readMeasurement(uint16_t& temperatureTicks, - uint16_t& humidityTicks) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0xe000, buffer_ptr, 6); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - SensirionI2CRxFrame rxFrame(buffer_ptr, 6); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 6, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(temperatureTicks); - localError |= rxFrame.getUInt16(humidityTicks); - return localError; -} - -int16_t SensirionI2cSht3x::stopMeasurement() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x3093, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(1); - return localError; -} - -int16_t SensirionI2cSht3x::enableHeater() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x306d, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(10); - return localError; -} - -int16_t SensirionI2cSht3x::disableHeater() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x3066, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(10); - return localError; -} - -int16_t SensirionI2cSht3x::llreadStatusRegister(uint16_t& statusRegister) { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0xf32d, buffer_ptr, 3); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(10); - SensirionI2CRxFrame rxFrame(buffer_ptr, 3); - localError = SensirionI2CCommunication::receiveFrame(_i2cAddress, 3, - rxFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - localError |= rxFrame.getUInt16(statusRegister); - return localError; -} - -int16_t SensirionI2cSht3x::clearStatusRegister() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x3041, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(10); - return localError; -} - -int16_t SensirionI2cSht3x::softReset() { - int16_t localError = NO_ERROR; - uint8_t* buffer_ptr = communication_buffer; - SensirionI2CTxFrame txFrame = - SensirionI2CTxFrame::createWithUInt16Command(0x30a2, buffer_ptr, 2); - localError = - SensirionI2CCommunication::sendFrame(_i2cAddress, txFrame, *_i2cBus); - if (localError != NO_ERROR) { - return localError; - } - delay(2); - return localError; -} - -void SensirionI2cSht3x::begin(TwoWire& i2cBus, uint8_t i2cAddress) { - _i2cBus = &i2cBus; - _i2cAddress = i2cAddress; -} diff --git a/src/library/arduino-i2c-sht3x/src/SensirionI2cSht3x.h b/src/library/arduino-i2c-sht3x/src/SensirionI2cSht3x.h deleted file mode 100644 index e9ff789..0000000 --- a/src/library/arduino-i2c-sht3x/src/SensirionI2cSht3x.h +++ /dev/null @@ -1,548 +0,0 @@ -/* - * THIS FILE IS AUTOMATICALLY GENERATED - * - * Generator: sensirion-driver-generator 0.33.0 - * Product: sht3x - * Model-Version: 1.0.0 - */ -/* - * Copyright (c) 2023, Sensirion AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of Sensirion AG nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SENSIRIONI2CSHT3X_H -#define SENSIRIONI2CSHT3X_H - -#include "../../SensirionCore/src/SensirionCore.h" -#include - -#define NO_ERROR 0 -#define SHT30A_I2C_ADDR_44 0x44 -#define SHT30A_I2C_ADDR_45 0x45 -#define SHT30_I2C_ADDR_44 0x44 -#define SHT30_I2C_ADDR_45 0x45 -#define SHT31A_I2C_ADDR_44 0x44 -#define SHT31A_I2C_ADDR_45 0x45 -#define SHT31_I2C_ADDR_44 0x44 -#define SHT31_I2C_ADDR_45 0x45 -#define SHT33_I2C_ADDR_44 0x44 -#define SHT33_I2C_ADDR_45 0x45 -#define SHT35A_I2C_ADDR_44 0x44 -#define SHT35A_I2C_ADDR_45 0x45 -#define SHT35_I2C_ADDR_44 0x44 -#define SHT35_I2C_ADDR_45 0x45 - -typedef enum { - MEASURE_SINGLE_SHOT_HIGH_REPEATABILITY_CMD_ID = 0x2400, - MEASURE_SINGLE_SHOT_HIGH_REPEATABILITY_CLOCK_STRETCHING_CMD_ID = 0x2c06, - MEASURE_SINGLE_SHOT_MEDIUM_REPEATABILITY_CMD_ID = 0x240b, - MEASURE_SINGLE_SHOT_MEDIUM_REPEATABILITY_CLOCK_STRETCHING_CMD_ID = 0x2c0d, - MEASURE_SINGLE_SHOT_LOW_REPEATABILITY_CMD_ID = 0x2416, - MEASURE_SINGLE_SHOT_LOW_REPEATABILITY_CLOCK_STRETCHING_CMD_ID = 0x2c10, - START_MEASUREMENT_0_5_MPS_HIGH_REPEATABILITY_CMD_ID = 0x2032, - START_MEASUREMENT_0_5_MPS_MEDIUM_REPEATABILITY_CMD_ID = 0x2024, - START_MEASUREMENT_0_5_MPS_LOW_REPEATABILITY_CMD_ID = 0x202f, - START_MEASUREMENT_1_MPS_HIGH_REPEATABILITY_CMD_ID = 0x2130, - START_MEASUREMENT_1_MPS_MEDIUM_REPEATABILITY_CMD_ID = 0x2126, - START_MEASUREMENT_1_MPS_LOW_REPEATABILITY_CMD_ID = 0x212d, - START_MEASUREMENT_2_MPS_HIGH_REPEATABILITY_CMD_ID = 0x2236, - START_MEASUREMENT_2_MPS_MEDIUM_REPEATABILITY_CMD_ID = 0x2220, - START_MEASUREMENT_2_MPS_LOW_REPEATABILITY_CMD_ID = 0x222b, - START_MEASUREMENT_4_MPS_HIGH_REPEATABILITY_CMD_ID = 0x2334, - START_MEASUREMENT_4_MPS_MEDIUM_REPEATABILITY_CMD_ID = 0x2322, - START_MEASUREMENT_4_MPS_LOW_REPEATABILITY_CMD_ID = 0x2329, - START_MEASUREMENT_10_MPS_HIGH_REPEATABILITY_CMD_ID = 0x2737, - START_MEASUREMENT_10_MPS_MEDIUM_REPEATABILITY_CMD_ID = 0x2721, - START_MEASUREMENT_10_MPS_LOW_REPEATABILITY_CMD_ID = 0x273a, - START_ART_MEASUREMENT_CMD_ID = 0x2b32, - READ_MEASUREMENT_CMD_ID = 0xe000, - STOP_MEASUREMENT_CMD_ID = 0x3093, - ENABLE_HEATER_CMD_ID = 0x306d, - DISABLE_HEATER_CMD_ID = 0x3066, - READ_STATUS_REGISTER_CMD_ID = 0xf32d, - CLEAR_STATUS_REGISTER_CMD_ID = 0x3041, - SOFT_RESET_CMD_ID = 0x30a2, -} CmdId; - -typedef enum { - REPEATABILITY_LOW = 0, - REPEATABILITY_MEDIUM = 1, - REPEATABILITY_HIGH = 2, -} Repeatability; - -typedef enum { - MPS_EVERY_TWO_SECONDS = 0, - MPS_ONE_PER_SECOND = 1, - MPS_TWO_PER_SECOND = 2, - MPS_FOUR_PER_SECOND = 4, - MPS_TEN_PER_SECOND = 10, -} Mps; - -class SensirionI2cSht3x { - public: - SensirionI2cSht3x(); - /** - * @brief Initializes the SHT3x class. - * - * @param i2cBus Arduino stream object to be used for communication. - */ - void begin(TwoWire& i2cBus, uint8_t i2cAddress); - - /** - * @brief Single shot measurement with the specified properties - * - * @param[in] measurementRepeatability The repeatability of the periodic - * measurement - * @param[in] isClockStretching Toggle clock stretching - * @param[out] aTemperature Converted from ticks to degrees celsius by -45 + - * (175 * value / 65535) - * @param[out] aHumidity Converted from ticks to relative humidity by 100 * - * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureSingleShot(Repeatability measurementRepeatability, - bool isClockStretching, float& aTemperature, - float& aHumidity); - - /** - * @brief startPeriodicMeasurement - * - * Start the periodic measurement measurement mode. - * - * This is a convenience method that selects the correct measurement command - * based on the provided arguments. - * - * @param[in] measurementRepeatability The repeatability of the periodic - * measurement - * @param[in] messagesPerSecond The messages per second of the periodic - * measurement - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startPeriodicMeasurement(Repeatability measurementRepeatability, - Mps messagesPerSecond); - - /** - * @brief blockingReadMeasurement - * - * This is a convenience method that combines polling the data ready flag - * and reading out the data. As the minimal measurement interval is 2s and - * we sleep for 100ms we iterate at most 200 times. Note that this is - * blocking the system for a considerable amount of time! - * - * @param[out] aTemperature Converted from ticks to degrees celsius by -45 + - * (175 * value / 65535) - * @param[out] aHumidity Converted from ticks to relative humidity by 100 * - * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t blockingReadMeasurement(float& aTemperature, float& aHumidity); - - /** - * @brief Read the contents of the status register - * - * @param[out] aStatusRegister - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t readStatusRegister(uint16_t& aStatusRegister); - - /** - * @brief measureSingleShotHighRepeatability - * - * Single shot measurement with high repeatability - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by -45 + 175 * value / 65535 - * @param[out] humidityTicks Humidity ticks. Convert to relative humidity by - * 100 - * * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureSingleShotHighRepeatability(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief measureSingleShotHighRepeatabilityClockStretching - * - * Single shot measurement with high repeatability and clock stretching - * enabled - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by -45 + 175 * value / 65535 - * @param[out] humidityTicks Humidity ticks. Convert to relative humidity by - * 100 - * * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureSingleShotHighRepeatabilityClockStretching( - uint16_t& temperatureTicks, uint16_t& humidityTicks); - - /** - * @brief measureSingleShotMediumRepeatability - * - * Single shot measurement with medium repeatability - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by -45 + 175 * value / 65535 - * @param[out] humidityTicks Humidity ticks. Convert to relative humidity by - * 100 - * * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureSingleShotMediumRepeatability(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief measureSingleShotMediumRepeatabilityClockStretching - * - * Single shot measurement with medium repeatability and clock stretching - * enabled - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by -45 + 175 * value / 65535 - * @param[out] humidityTicks Humidity ticks. Convert to relative humidity by - * 100 - * * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureSingleShotMediumRepeatabilityClockStretching( - uint16_t& temperatureTicks, uint16_t& humidityTicks); - - /** - * @brief measureSingleShotLowRepeatability - * - * Single shot measurement with low repeatability - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by -45 + 175 * value / 65535 - * @param[out] humidityTicks Humidity ticks. Convert to relative humidity by - * 100 - * * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t measureSingleShotLowRepeatability(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief measureSingleShotLowRepeatabilityClockStretching - * - * Single shot measurement with low repeatability and clock stretching - * enabled - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by -45 + 175 * value / 65535 - * @param[out] humidityTicks Humidity ticks. Convert to relative humidity by - * 100 - * * value / 65535 - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t - measureSingleShotLowRepeatabilityClockStretching(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief startMeasurement05MpsHighRepeatability - * - * Start periodic measurement mode with 0.5 mps and high repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement05MpsHighRepeatability(); - - /** - * @brief startMeasurement05MpsMediumRepeatability - * - * Start periodic measurement mode with 0.5 mps and medium repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement05MpsMediumRepeatability(); - - /** - * @brief startMeasurement05MpsLowRepeatability - * - * Start periodic measurement mode with 0.5 mps and low repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement05MpsLowRepeatability(); - - /** - * @brief startMeasurement1MpsHighRepeatability - * - * Start periodic measurement mode with 1 mps and high repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement1MpsHighRepeatability(); - - /** - * @brief startMeasurement1MpsMediumRepeatability - * - * Start periodic measurement mode with 1 mps and medium repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement1MpsMediumRepeatability(); - - /** - * @brief startMeasurement1MpsLowRepeatability - * - * Start periodic measurement mode with 1 mps and low repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement1MpsLowRepeatability(); - - /** - * @brief startMeasurement2MpsHighRepeatability - * - * Start periodic measurement mode with 2 mps and high repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement2MpsHighRepeatability(); - - /** - * @brief startMeasurement2MpsMediumRepeatability - * - * Start periodic measurement mode with 2 mps and medium repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement2MpsMediumRepeatability(); - - /** - * @brief startMeasurement2MpsLowRepeatability - * - * Start periodic measurement mode with 2 mps and low repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement2MpsLowRepeatability(); - - /** - * @brief startMeasurement4MpsHighRepeatability - * - * Start periodic measurement mode with 4 mps and high repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement4MpsHighRepeatability(); - - /** - * @brief startMeasurement4MpsMediumRepeatability - * - * Start periodic measurement mode with 4 mps and medium repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement4MpsMediumRepeatability(); - - /** - * @brief startMeasurement4MpsLowRepeatability - * - * Start periodic measurement mode with 4 mps and low repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement4MpsLowRepeatability(); - - /** - * @brief startMeasurement10MpsHighRepeatability - * - * Start periodic measurement mode with 10 mps and high repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement10MpsHighRepeatability(); - - /** - * @brief startMeasurement10MpsMediumRepeatability - * - * Start periodic measurement mode with 10 mps and medium repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement10MpsMediumRepeatability(); - - /** - * @brief startMeasurement10MpsLowRepeatability - * - * Start periodic measurement mode with 10 mps and low repeatability. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startMeasurement10MpsLowRepeatability(); - - /** - * @brief startArtMeasurement - * - * Start ART (accelerated response time) measurement - * - * @note After issuing the ART command the sensor will start acquiring data - * with a frequency of 4Hz. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t startArtMeasurement(); - - /** - * @brief readMeasurement - * - * Read out data after a "start measurement" or "start art measurement" - * command has been issued. - * - * @param[out] temperatureTicks Temperature ticks. Convert to degrees - * celsius by -45 + 175 * value / 65535 - * @param[out] humidityTicks Humidity ticks. Convert to relative humidity by - * 100 - * * value / 65535 - * - * @note After the read out command fetch data has been issued, the data - * memory is cleared, i.e. no measurement data is present. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t readMeasurement(uint16_t& temperatureTicks, - uint16_t& humidityTicks); - - /** - * @brief stopMeasurement - * - * Stop the periodic measurement mode. - * - * @note Upon reception of this command the sensor will abort the ongoing - * measurement and enter the single shot mode. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t stopMeasurement(); - - /** - * @brief enableHeater - * - * Enable the heater - * - * @note The SHT3x is equipped with an internal heater, which is meant for - * plausibility checking only. The temperature increase achieved by the - * heater depends on various parameters and lies in the range of a few - * degrees centigrade. - * - * After a reset the heater is disabled (default condition). - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t enableHeater(); - - /** - * @brief disableHeater - * - * Disable the heater - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t disableHeater(); - - /** - * @brief llreadStatusRegister - * - * Read out the status register - * - * @param[out] statusRegister The contents of the status register - * - * @note The status register contains information on the operational status - * of the heater, the alert mode and on the execution status of the last - * command and the last write sequence. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t llreadStatusRegister(uint16_t& statusRegister); - - /** - * @brief clearStatusRegister - * - * Clear (set to zero) all flags (Bit 4) in the status register. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t clearStatusRegister(); - - /** - * @brief softReset - * - * Perform a soft reset. - * - * @note A system reset of the SHT3x can be achieved in multiple ways: - - * Soft reset: use this command - I2C general call: all devices on the I2C - * bus are reset by sending the command 0x06 to the I2C address 0x00 - Reset - * pin: send a pulse to the dedicated nReset pin. The nReset pin has to be - * pulled low for a minimum of 1 µs to generate a reset of the sensor. - - * Hard reset: Power down (incl. pulling SDA, SCL and ADDR low) - * - * During the reset procedure the sensor will not process commands. - * - * @return error_code 0 on success, an error code otherwise. - */ - int16_t softReset(); - - private: - TwoWire* _i2cBus = nullptr; - uint8_t _i2cAddress = 0; - - /** - * @brief signalTemperature - * - * @param[in] temperatureTicks - * - * @return Converted from ticks to degrees celsius by -45 + (175 * value / - * 65535) - */ - float signalTemperature(uint16_t temperatureTicks); - - /** - * @brief signalHumidity - * - * @param[in] humidityTicks - * - * @return Converted from ticks to relative humidity by 100 * value / 65535 - */ - float signalHumidity(uint16_t humidityTicks); -}; - -#endif // SENSIRIONI2CSHT3X_H diff --git a/src/library/SensirionSHT4x/LICENSE b/src/library/arduino-sht/LICENSE similarity index 60% rename from src/library/SensirionSHT4x/LICENSE rename to src/library/arduino-sht/LICENSE index f95f5fe..e8ed322 100644 --- a/src/library/SensirionSHT4x/LICENSE +++ b/src/library/arduino-sht/LICENSE @@ -1,21 +1,19 @@ -BSD 3-Clause License - -Copyright (c) 2023, Sensirion AG +Copyright (c) 2018, Sensirion AG All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. +* Neither the name of Sensirion AG nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE diff --git a/src/library/arduino-sht/README.md b/src/library/arduino-sht/README.md new file mode 100644 index 0000000..80d3db4 --- /dev/null +++ b/src/library/arduino-sht/README.md @@ -0,0 +1,72 @@ +# arduino-sht +Repository for Sensirion humidity and temperature sensor support on Arduino + +## Supported sensors: +- SHTC1 +- SHTC3 +- SHTW1 +- SHTW2 +- SHT2x (SHT20, SHT21, SHT25) +- SHT3x-DIS (I2C) +- SHT3x-ARP (ratiometric analog voltage output) +- SHT85 +- SHT4x + +For sht3x and sht4x there are specific drivers available in separate repositories. + +## Installation + +The recommended way to install ```arduino-sht``` is through the Library +Manager of the Arduino IDE. To access it, go to the ```Tools``` menu and +select ```Manage Libraries...```, and search for the library name there. + +If you prefer to install it manually, you can download either via git or from +the releases page and place it in your Arduino/libraries directory. After +restarting the Arduino IDE, you will see the new SHTSensor menu items under +libraries and examples. + +## Integrating it into your sketch + +Assuming you installed the library as described above, the following steps are +necessary: + +1. Import the Wire library like this: From the menu bar, select Sketch > Import + Library > Wire +1. Import the arduino-sht library: From the menu bar, select Sketch > + Import Library > arduino-sht +1. Create an instance of the `SHTSensor` class (`SHTSensor sht;`) +2. In `setup()`, make sure to init the Wire library with `Wire.begin()` +3. Also in `setup()`, call `sht.init()` +5. If you want to use the serial console, remember to initialize the Serial + library with `Serial.begin(9600)` +1. Call `sht.readSample()` in the `loop()` function, which reads a temperature + and humidity sample from the sensor +2. Use `sht.getHumidity()` and `sht.getTemperature()` to get the values from + the last sample + +*Important:* `getHumidity()` and `getTemperature()` do *not* read a new sample +from the sensor, but return the values read last. To read a new sample, make +sure to call `readSample()` + +### Using an custom or alternative I2C port/Wire instance + +Some Arduino boards have multiple predefined I2C ports; generally, the second port will be called `Wire1`. + +The `arduino-sht` library allows to use an alternative interface; to do so, pass the port you want to use as an argument to `sht.init()`, like this: +``` + if (sht.init(Wire1)) { + Serial.print("init(): success\n"); + } else { + Serial.print("init(): failed\n"); + } +``` + +## Example projects + +See example project +[sht-autodetect](examples/sht-autodetect/sht-autodetect.ino) + +### Usage with multiple SHT31 sensors + +See example project +[multiple-sht-sensors](examples/multiple-sht-sensors/multiple-sht-sensors.ino) diff --git a/src/library/arduino-sht/SHTSensor.cpp b/src/library/arduino-sht/SHTSensor.cpp new file mode 100644 index 0000000..2b6bcb2 --- /dev/null +++ b/src/library/arduino-sht/SHTSensor.cpp @@ -0,0 +1,442 @@ +/* + * Copyright (c) 2018, Sensirion AG + * Copyright (c) 2015-2016, Johannes Winkelmann + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sensirion AG nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "SHTSensor.h" + + +// +// class SHTSensorDriver +// + +SHTSensorDriver::~SHTSensorDriver() +{ +} + +bool SHTSensorDriver::readSample() +{ + return false; +} + + +// +// class SHTI2cSensor +// + +const uint8_t SHTI2cSensor::EXPECTED_DATA_SIZE = 6; + +bool SHTI2cSensor::readFromI2c(TwoWire & wire, + uint8_t i2cAddress, + const uint8_t *i2cCommand, + uint8_t commandLength, uint8_t *data, + uint8_t dataLength, + uint8_t duration) +{ + wire.beginTransmission(i2cAddress); + for (int i = 0; i < commandLength; ++i) { + if (wire.write(i2cCommand[i]) != 1) { + return false; + } + } + + if (wire.endTransmission() != 0) { + return false; + } + + delay(duration); + + wire.requestFrom(i2cAddress, dataLength); + + // check if the same number of bytes are received that are requested. + if (wire.available() != dataLength) { + return false; + } + + for (int i = 0; i < dataLength; ++i) { + data[i] = wire.read(); + } + return true; +} + +uint8_t SHTI2cSensor::crc8(const uint8_t *data, uint8_t len, uint8_t crcInit) +{ + // adapted from SHT21 sample code from + // http://www.sensirion.com/en/products/humidity-temperature/download-center/ + + uint8_t crc = crcInit; + uint8_t byteCtr; + for (byteCtr = 0; byteCtr < len; ++byteCtr) { + crc ^= data[byteCtr]; + for (uint8_t bit = 8; bit > 0; --bit) { + if (crc & 0x80) { + crc = (crc << 1) ^ 0x31; + } else { + crc = (crc << 1); + } + } + } + return crc; +} + + +bool SHTI2cSensor::readSample() +{ + uint8_t data[EXPECTED_DATA_SIZE]; + uint8_t cmd[mCmd_Size]; + + cmd[0] = mI2cCommand >> 8; + //is omitted for SHT4x Sensors + cmd[1] = mI2cCommand & 0xff; + + if (!readFromI2c(mWire, mI2cAddress, cmd, mCmd_Size, data, + EXPECTED_DATA_SIZE, mDuration)) { + return false; + } + + // -- Important: assuming each 2 byte of data is followed by 1 byte of CRC + + // check CRC for both RH and T + if (crc8(&data[0], 2) != data[2] || crc8(&data[3], 2) != data[5]) { + return false; + } + + // convert to Temperature/Humidity + uint16_t val; + val = (data[0] << 8) + data[1]; + mTemperature = mA + mB * (val / mC); + + val = (data[3] << 8) + data[4]; + mHumidity = mX + mY * (val / mZ); + + return true; + +} + +// +// class SHTC1Sensor +// + +class SHTC1Sensor : public SHTI2cSensor +{ +public: + SHTC1Sensor(TwoWire & wire) + // clock stretching disabled, high precision, T first + : SHTI2cSensor(0x70, 0x7866, 15, -45, 175, 65535, 0, 100, 65535, 2, wire) + { + } +}; + +// +// class SHT2xSensor (SHT20, SHT21, SHT25) +// + +class SHT2xSensor : public SHTI2cSensor +{ +public: + SHT2xSensor(TwoWire &wire) + // clock stretching disabled + : SHTI2cSensor(0x40, // i2cAddress + 0xF3F5, // i2cCommand Hi: T, Lo: RH + 85, // duration + -46.85, // a (sht_t_poly1) + 175.72, // b (sht_t_poly2) + 65536.0, // c (sht_t_poly3) + -6.0, // x (sht_h_poly1) + 125.0, // y (sht_h_poly2) + 65536.0, // z (sht_h_poly3) + 1, // cmd_Size + wire) + { + } + + bool readSample() override + { + uint8_t data[EXPECTED_DATA_SIZE]; + uint8_t cmd[mCmd_Size]; + + // SHT2x sends T and RH in two separate commands (different to other sensors) + // so we have to spit the command into two bytes and + // have to read from I2C two times with EXPECTED_DATA_SIZE / 2 + + // Upper byte is T for SHT2x Sensors + cmd[0] = mI2cCommand >> 8; + // Lower byte is RH for SHT2x Sensors + cmd[1] = mI2cCommand & 0xff; + + // read T from SHT2x Sensor + if (!readFromI2c(mWire, mI2cAddress, cmd, mCmd_Size, data, + EXPECTED_DATA_SIZE / 2, mDuration)) { + DEBUG_SHT("SHT2x readFromI2c(T) false\n"); + return false; + } + // read RH from SHT2x Sensor + if (!readFromI2c(mWire, mI2cAddress, &cmd[1], mCmd_Size, &data[3], + EXPECTED_DATA_SIZE / 2, mDuration)) { + DEBUG_SHT("SHT2x readFromI2c(RH) false\n"); + return false; + } + + // -- Important: assuming each 2 byte of data is followed by 1 byte of CRC + + // check CRC for both RH and T with a crc init value of 0 + if (crc8(&data[0], 2, 0) != data[2] || crc8(&data[3], 2, 0) != data[5]) { + DEBUG_SHT("SHT2x crc8 false\n"); + return false; + } + + // check status bits [1..0] (see datasheet) + // bit 0: not used, bit 1: measurement type (0: temperature, 1 humidity) + if (((data[1] & 0x02) != 0x00) || ((data[4] & 0x02) != 0x02)) { + DEBUG_SHT("SHT2x status bits false\n"); + return false; + } + + // convert to Temperature/Humidity + uint16_t val; + val = (data[0] << 8) + (data[1] & ~0x03); // get value and clear status bits [1..0] + mTemperature = mA + mB * (val / mC); + + val = (data[3] << 8) + (data[4] & ~0x03); // get value and clear status bits [1..0] + mHumidity = mX + mY * (val / mZ); + + return true; + } +}; + +// +// class SHT3xSensor +// + +class SHT3xSensor : public SHTI2cSensor +{ +private: + static const uint16_t SHT3X_ACCURACY_HIGH = 0x2400; + static const uint16_t SHT3X_ACCURACY_MEDIUM = 0x240b; + static const uint16_t SHT3X_ACCURACY_LOW = 0x2416; + + static const uint8_t SHT3X_ACCURACY_HIGH_DURATION = 15; + static const uint8_t SHT3X_ACCURACY_MEDIUM_DURATION = 6; + static const uint8_t SHT3X_ACCURACY_LOW_DURATION = 4; + +public: + static const uint8_t SHT3X_I2C_ADDRESS_44 = 0x44; + static const uint8_t SHT3X_I2C_ADDRESS_45 = 0x45; + + SHT3xSensor(TwoWire & wire, uint8_t i2cAddress = SHT3X_I2C_ADDRESS_44) + : SHTI2cSensor(i2cAddress, SHT3X_ACCURACY_HIGH, + SHT3X_ACCURACY_HIGH_DURATION, + -45, 175, 65535, 0, 100, 65535, 2, wire) + { + } + + virtual bool setAccuracy(SHTSensor::SHTAccuracy newAccuracy) + { + switch (newAccuracy) { + case SHTSensor::SHT_ACCURACY_HIGH: + mI2cCommand = SHT3X_ACCURACY_HIGH; + mDuration = SHT3X_ACCURACY_HIGH_DURATION; + break; + case SHTSensor::SHT_ACCURACY_MEDIUM: + mI2cCommand = SHT3X_ACCURACY_MEDIUM; + mDuration = SHT3X_ACCURACY_MEDIUM_DURATION; + break; + case SHTSensor::SHT_ACCURACY_LOW: + mI2cCommand = SHT3X_ACCURACY_LOW; + mDuration = SHT3X_ACCURACY_LOW_DURATION; + break; + default: + return false; + } + return true; + } +}; + + +// +// class SHT4xSensor +// + +class SHT4xSensor : public SHTI2cSensor +{ +private: + static const uint16_t SHT4X_ACCURACY_HIGH = 0xFD00; + static const uint16_t SHT4X_ACCURACY_MEDIUM = 0xF600; + static const uint16_t SHT4X_ACCURACY_LOW = 0xE000; + + static const uint8_t SHT4X_ACCURACY_HIGH_DURATION = 10; + static const uint8_t SHT4X_ACCURACY_MEDIUM_DURATION = 4; + static const uint8_t SHT4X_ACCURACY_LOW_DURATION = 2; + +public: + static const uint8_t SHT4X_I2C_ADDRESS_44 = 0x44; + static const uint8_t SHT4X_I2C_ADDRESS_45 = 0x45; + + SHT4xSensor(TwoWire & wire, uint8_t i2cAddress = SHT4X_I2C_ADDRESS_44) + : SHTI2cSensor(i2cAddress, SHT4X_ACCURACY_HIGH, + SHT4X_ACCURACY_HIGH_DURATION, + -45, 175, 65535, -6, 125, 65535, 1, wire) + { + } + + virtual bool setAccuracy(SHTSensor::SHTAccuracy newAccuracy) + { + switch (newAccuracy) { + case SHTSensor::SHT_ACCURACY_HIGH: + mI2cCommand = SHT4X_ACCURACY_HIGH; + mDuration = SHT4X_ACCURACY_HIGH_DURATION; + break; + case SHTSensor::SHT_ACCURACY_MEDIUM: + mI2cCommand = SHT4X_ACCURACY_MEDIUM; + mDuration = SHT4X_ACCURACY_MEDIUM_DURATION; + break; + case SHTSensor::SHT_ACCURACY_LOW: + mI2cCommand = SHT4X_ACCURACY_LOW; + mDuration = SHT4X_ACCURACY_LOW_DURATION; + break; + default: + return false; + } + return true; + } +}; + + +// +// class SHT3xAnalogSensor +// + +float SHT3xAnalogSensor::readHumidity() +{ + float max_adc = (float)((1 << mReadResolutionBits) - 1); + return -12.5f + 125 * (analogRead(mHumidityAdcPin) / max_adc); +} + +float SHT3xAnalogSensor::readTemperature() +{ + float max_adc = (float)((1 << mReadResolutionBits) - 1); + return -66.875f + 218.75f * (analogRead(mTemperatureAdcPin) / max_adc); +} + + +// +// class SHTSensor +// + +const SHTSensor::SHTSensorType SHTSensor::AUTO_DETECT_SENSORS[] = { + SHT4X, // IMPORTANT: SHT4x needs to be probed before the SHT3x, since they + // share their I2C address, and probing for an SHT3x can cause the + // first reading of and SHT4x to be off. + // see https://github.com/Sensirion/arduino-sht/issues/27 + + SHT2X, + SHT3X, + SHT3X_ALT, + SHTC1 +}; +const float SHTSensor::TEMPERATURE_INVALID = NAN; +const float SHTSensor::HUMIDITY_INVALID = NAN; + +bool SHTSensor::init(TwoWire & wire) +{ + if (mSensor != NULL) { + cleanup(); + } + + switch(mSensorType) { + case SHT2X: + mSensor = new SHT2xSensor(wire); + break; + + case SHT3X: + case SHT85: + mSensor = new SHT3xSensor(wire); + break; + + case SHT3X_ALT: + mSensor = new SHT3xSensor(wire, SHT3xSensor::SHT3X_I2C_ADDRESS_45); + break; + + case SHTW1: + case SHTW2: + case SHTC1: + case SHTC3: + mSensor = new SHTC1Sensor(wire); + break; + case SHT4X: + mSensor = new SHT4xSensor(wire); + break; + case AUTO_DETECT: + { + bool detected = false; + for (unsigned int i = 0; + i < sizeof(AUTO_DETECT_SENSORS) / sizeof(AUTO_DETECT_SENSORS[0]); + ++i) { + mSensorType = AUTO_DETECT_SENSORS[i]; + delay(40); // TODO: this was necessary to make SHT4x autodetect work; revisit to find root cause + if (init(wire)) { + detected = true; + break; + } + } + if (!detected) { + cleanup(); + } + break; + } + } + + // to finish the initialization, attempt to read to make sure the communication works + // Note: readSample() will check for a NULL mSensor in case auto detect failed + return readSample(); +} + +bool SHTSensor::readSample() +{ + if (!mSensor || !mSensor->readSample()) + return false; + mTemperature = mSensor->mTemperature; + mHumidity = mSensor->mHumidity; + return true; +} + +bool SHTSensor::setAccuracy(SHTAccuracy newAccuracy) +{ + if (!mSensor) + return false; + return mSensor->setAccuracy(newAccuracy); +} + +void SHTSensor::cleanup() +{ + if (mSensor) { + delete mSensor; + mSensor = NULL; + } +} diff --git a/src/library/arduino-sht/SHTSensor.h b/src/library/arduino-sht/SHTSensor.h new file mode 100644 index 0000000..69ed99a --- /dev/null +++ b/src/library/arduino-sht/SHTSensor.h @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2018, Sensirion AG + * Copyright (c) 2015-2016, Johannes Winkelmann + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sensirion AG nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef SHTSENSOR_H +#define SHTSENSOR_H + +#include +#include + +//#define DEBUG_SHT_SENSOR + +#ifdef DEBUG_SHT_SENSOR +#ifdef DEBUG_ESP_PORT +#define DEBUG_SHT(f) do { DEBUG_ESP_PORT.print(PSTR(f)); } while (0) +#else +#define DEBUG_SHT(f) do { Serial.print(PSTR(f)); } while (0) +#endif +#else +#define DEBUG_SHT(x...) do { (void)0; } while (0) +#endif + +// Forward declaration +class SHTSensorDriver; + +/** + * Official interface for Sensirion SHT Sensors + */ +class SHTSensor +{ +public: + /** + * Enum of the supported Digital Sensirion SHT Sensors. + * For analog sensors, see SHT3xAnalogSensor. + * Using the special AUTO_DETECT sensor causes all i2c sensors to be + * probed. The first matching sensor will then be used. + */ + enum SHTSensorType { + /** Automatically detect the sensor type (only i2c sensors listed above) */ + AUTO_DETECT, + // i2c Sensors: + /** SHT3x-DIS with ADDR (sensor pin 2) connected to VSS (default) */ + SHT3X, + SHT85, + /** SHT3x-DIS with ADDR (sensor pin 2) connected to VDD */ + SHT3X_ALT, + SHTC1, + SHTC3, + SHTW1, + SHTW2, + SHT4X, + SHT2X + }; + + /** + * Accuracy setting of measurement. + * Not all sensors support changing the sampling accuracy. + */ + enum SHTAccuracy { + /** Highest repeatability at the cost of slower measurement */ + SHT_ACCURACY_HIGH, + /** Balanced repeatability and speed of measurement */ + SHT_ACCURACY_MEDIUM, + /** Fastest measurement but lowest repeatability */ + SHT_ACCURACY_LOW + }; + + /** Value reported by getHumidity() when the sensor is not initialized */ + static const float HUMIDITY_INVALID; + /** Value reported by getTemperature() when the sensor is not initialized */ + static const float TEMPERATURE_INVALID; + /** + * Auto-detectable sensor types. + * Note that the SHTC3, SHTW1 and SHTW2 share exactly the same driver as the SHTC1 + * and are thus not listed individually. + */ + static const SHTSensorType AUTO_DETECT_SENSORS[]; + + /** + * Instantiate a new SHTSensor + * By default, the i2c bus is queried for known SHT Sensors. To address + * a specific sensor, set the `sensorType'. + */ + SHTSensor(SHTSensorType sensorType = AUTO_DETECT) + : mSensorType(sensorType), + mSensor(NULL), + mTemperature(SHTSensor::TEMPERATURE_INVALID), + mHumidity(SHTSensor::HUMIDITY_INVALID) + { + } + + virtual ~SHTSensor() { + cleanup(); + } + + /** + * Initialize the sensor driver, and probe for the sensor on the bus + * + * If SHTSensor() was created with an empty constructor or with 'sensorType' + * AUTO_DETECT, init() will also try to automatically detect a sensor. + * Auto detection will stop as soon as the first sensor was found; if you have + * multiple sensor types on the bus, use the 'sensorType' argument of the + * constructor to control which sensor type will be instantiated. + * + * To read out the sensor use readSample(), followed by getTemperature() and + * getHumidity() to retrieve the values from the sample + * + * Returns true if communication with a sensor on the bus was successful, false otherwise + */ + bool init(TwoWire & wire = Wire); + + /** + * Read new values from the sensor + * After the call, use getTemperature() and getHumidity() to retrieve the + * values + * Returns true if the sample was read and the values are cached + */ + bool readSample(); + + /** + * Get the relative humidity in percent read from the last sample + * Use readSample() to trigger a new sensor reading + */ + float getHumidity() const { + return mHumidity; + } + + /** + * Get the temperature in Celsius read from the last sample + * Use readSample() to trigger a new sensor reading + */ + float getTemperature() const { + return mTemperature; + } + + /** + * Change the sensor accurancy, if supported by the sensor + * Returns true if the accuracy was changed + */ + bool setAccuracy(SHTAccuracy newAccuracy); + + SHTSensorType mSensorType; + +private: + void cleanup(); + + + SHTSensorDriver *mSensor; + float mTemperature; + float mHumidity; +}; + + +/** Abstract class for a digital SHT Sensor driver */ +class SHTSensorDriver +{ +public: + virtual ~SHTSensorDriver() = 0; + + /** + * Set the sensor accuracy. + * Returns false if the sensor does not support changing the accuracy + */ + virtual bool setAccuracy(SHTSensor::SHTAccuracy /* newAccuracy */) { + return false; + } + + /** Returns true if the next sample was read and the values are cached */ + virtual bool readSample(); + + /** + * Get the relative humidity in percent read from the last sample + * Use readSample() to trigger a new sensor reading + */ + float getHumidity() const { + return mHumidity; + } + + /** + * Get the humidity in percent read from the last sample + * Use readSample() to trigger a new sensor reading + */ + float getTemperature() const { + return mTemperature; + } + + float mTemperature; + float mHumidity; +}; + +/** Base class for i2c SHT Sensor drivers */ +class SHTI2cSensor : public SHTSensorDriver { +public: + /** Size of i2c commands to send */ + + + /** Size of i2c replies to expect */ + static const uint8_t EXPECTED_DATA_SIZE; + + /** + * Constructor for i2c SHT Sensors + * Takes the `i2cAddress' to read, the `i2cCommand' issues when sampling + * the sensor and the values `a', `b', `c' to convert the fixed-point + * temperature value received by the sensor to a floating point value using + * the formula: temperature = a + b * (rawTemperature / c) + * and the values `x' and `y' to convert the fixed-point humidity value + * received by the sensor to a floating point value using the formula: + * humidity = x + y * (rawHumidity / z) + * duration is the duration in milliseconds of one measurement + */ + SHTI2cSensor(uint8_t i2cAddress, uint16_t i2cCommand, uint8_t duration, + float a, float b, float c, + float x, float y, float z, uint8_t cmd_Size, + TwoWire & wire = Wire) + : mI2cAddress(i2cAddress), mI2cCommand(i2cCommand), mDuration(duration), + mA(a), mB(b), mC(c), mX(x), mY(y), mZ(z), mCmd_Size(cmd_Size), + mWire(wire) + { + } + + virtual ~SHTI2cSensor() + { + } + + virtual bool readSample(); + + uint8_t mI2cAddress; + uint16_t mI2cCommand; + uint8_t mDuration; + float mA; + float mB; + float mC; + float mX; + float mY; + float mZ; + uint8_t mCmd_Size; + TwoWire & mWire; + +private: + +protected: + static uint8_t crc8(const uint8_t *data, uint8_t len, uint8_t crcInit = 0xff); + static bool readFromI2c(TwoWire & wire, + uint8_t i2cAddress, + const uint8_t *i2cCommand, + uint8_t commandLength, uint8_t *data, + uint8_t dataLength, uint8_t duration); +}; + +class SHT3xAnalogSensor +{ +public: + + /** + * Instantiate a new Sensirion SHT3x Analog sensor driver instance. + * The required paramters are `humidityPin` and `temperaturePin` + * An optional `readResolutionBits' can be set since the Arduino/Genuino Zero + * support 12bit precision analog readings. By default, 10 bit precision is + * used. + * + * Example usage: + * SHT3xAnalogSensor sht3xAnalog(HUMIDITY_PIN, TEMPERATURE_PIN); + * float humidity = sht.readHumidity(); + * float temperature = sht.readTemperature(); + */ + SHT3xAnalogSensor(uint8_t humidityPin, uint8_t temperaturePin, + uint8_t readResolutionBits = 10) + : mHumidityAdcPin(humidityPin), mTemperatureAdcPin(temperaturePin), + mReadResolutionBits(readResolutionBits) + { + } + + virtual ~SHT3xAnalogSensor() + { + } + + float readHumidity(); + float readTemperature(); + + uint8_t mHumidityAdcPin; + uint8_t mTemperatureAdcPin; + uint8_t mReadResolutionBits; +}; + +#endif /* SHTSENSOR_H */ diff --git a/src/library/arduino-sht/arduino-sht.h b/src/library/arduino-sht/arduino-sht.h new file mode 100644 index 0000000..72b14fd --- /dev/null +++ b/src/library/arduino-sht/arduino-sht.h @@ -0,0 +1,6 @@ +#ifndef ARDUINO_SHT_H +#define ARDUINO_SHT_H + +#include "SHTSensor.h" + +#endif diff --git a/src/library/arduino-sht/examples/multiple-sht-sensors/multiple-sht-sensors.ino b/src/library/arduino-sht/examples/multiple-sht-sensors/multiple-sht-sensors.ino new file mode 100644 index 0000000..d19140c --- /dev/null +++ b/src/library/arduino-sht/examples/multiple-sht-sensors/multiple-sht-sensors.ino @@ -0,0 +1,62 @@ +#include +#include "SHTSensor.h" + +// Note that all i2c devices sharing one bus must have distinct addresses. Thus +// this example only works with sensors that have distinct i2c addresses (e.g. +// SHT3x and SHT3x_alt, or SHT3x and SHTC3). +// Make sure not to use auto-detection as it will only pick up one sensor. + +// Sensor with normal i2c address +// Sensor 1 with address pin pulled to GND +SHTSensor sht1(SHTSensor::SHT3X); + +// Sensor with alternative i2c address +// Sensor 2 with address pin pulled to Vdd +SHTSensor sht2(SHTSensor::SHT3X_ALT); + +void setup() { + // put your setup code here, to run once: + Wire.begin(); + Serial.begin(9600); + delay(1000); // let serial console settle + + // init on a specific sensor type (i.e. without auto detecting), + // does not check if the sensor is responding and will thus always succeed. + + // initialize sensor with normal i2c-address + sht1.init(); + + // initialize sensor with alternative i2c-address + sht2.init(); +} + +void loop() { + // put your main code here, to run repeatedly: + // read from first sensor + if (sht1.readSample()) { + Serial.print("SHT1 :\n"); + Serial.print(" RH: "); + Serial.print(sht1.getHumidity(), 2); + Serial.print("\n"); + Serial.print(" T: "); + Serial.print(sht1.getTemperature(), 2); + Serial.print("\n"); + } else { + Serial.print("Sensor 1: Error in readSample()\n"); + } + + // read from second sensor + if (sht2.readSample()) { + Serial.print("SHT2:\n"); + Serial.print(" RH: "); + Serial.print(sht2.getHumidity(), 2); + Serial.print("\n"); + Serial.print(" T: "); + Serial.print(sht2.getTemperature(), 2); + Serial.print("\n"); + } else { + Serial.print("Sensor 2: Error in readSample()\n"); + } + + delay(1000); +} diff --git a/src/library/arduino-sht/examples/sht-autodetect/sht-autodetect.ino b/src/library/arduino-sht/examples/sht-autodetect/sht-autodetect.ino new file mode 100644 index 0000000..ed1eaf8 --- /dev/null +++ b/src/library/arduino-sht/examples/sht-autodetect/sht-autodetect.ino @@ -0,0 +1,41 @@ +#include + +#include "SHTSensor.h" + +SHTSensor sht; +// To use a specific sensor instead of probing the bus use this command: +// SHTSensor sht(SHTSensor::SHT3X); + +void setup() { + // put your setup code here, to run once: + + Wire.begin(); + Serial.begin(9600); + delay(1000); // let serial console settle + + if (sht.init()) { + Serial.print("init(): success\n"); + } else { + Serial.print("init(): failed\n"); + } + sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM); // only supported by SHT3x + +} + +void loop() { + // put your main code here, to run repeatedly: + + if (sht.readSample()) { + Serial.print("SHT:\n"); + Serial.print(" RH: "); + Serial.print(sht.getHumidity(), 2); + Serial.print("\n"); + Serial.print(" T: "); + Serial.print(sht.getTemperature(), 2); + Serial.print("\n"); + } else { + Serial.print("Error in readSample()\n"); + } + + delay(1000); +} diff --git a/src/library/arduino-sht/examples/sht3xanalog/sht3xanalog.ino b/src/library/arduino-sht/examples/sht3xanalog/sht3xanalog.ino new file mode 100644 index 0000000..931e7e2 --- /dev/null +++ b/src/library/arduino-sht/examples/sht3xanalog/sht3xanalog.ino @@ -0,0 +1,27 @@ +#include +#include + +#include "SHTSensor.h" + +SHT3xAnalogSensor sht3xAnalog(A0, A1); + +void setup() { + // put your setup code here, to run once: + + Wire.begin(); + Serial.begin(9600); + + delay(1000); // let serial console settle +} + +void loop() { + Serial.print("SHT3x Analog:\n"); + Serial.print(" RH: "); + Serial.print(sht3xAnalog.readHumidity(), 2); + Serial.print("\n"); + Serial.print(" T: "); + Serial.print(sht3xAnalog.readTemperature(), 2); + Serial.print("\n"); + + delay(1000); +} diff --git a/src/library/arduino-sht/keywords.txt b/src/library/arduino-sht/keywords.txt new file mode 100644 index 0000000..4064e9f --- /dev/null +++ b/src/library/arduino-sht/keywords.txt @@ -0,0 +1,29 @@ +####################################### +# Syntax Coloring Map For arduino-sht +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SHTSensorType KEYWORD1 +SHTAccuracy KEYWORD1 +SHTSensor KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +init KEYWORD2 +readSample KEYWORD2 +getHumidity KEYWORD2 +getTemperature KEYWORD2 +setAccuracy KEYWORD2 + +####################################### +# Instances (KEYWORD2) +####################################### + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/src/library/arduino-sht/library.properties b/src/library/arduino-sht/library.properties new file mode 100644 index 0000000..8076896 --- /dev/null +++ b/src/library/arduino-sht/library.properties @@ -0,0 +1,9 @@ +name=arduino-sht +version=1.2.3 +author=Johannes Winkelmann, Andreas Brauchli +maintainer=Johannes Winkelmann +sentence=Support for Sensirion's humidity and temperature sensors. +paragraph=Supported sensors: SHTC1, SHTC3, SHTW1, SHTW2, SHT3x-DIS (I2C), SHT2x, SHT85, SHT3x-ARP, SHT4x +category=Sensors +url=https://developer.sensirion.com +architectures=* diff --git a/src/sht/sht.cpp b/src/sht/sht.cpp new file mode 100644 index 0000000..7e5f9e6 --- /dev/null +++ b/src/sht/sht.cpp @@ -0,0 +1,149 @@ +#include "sht.h" + +#include "../library/arduino-sht/SHTSensor.h" + +/** Cast _sensor to SHTSensor */ +#define shtSensor() ((SHTSensor *)(this->_sensor)) + +/** + * @brief Check that is sensor initialized + * + * @return true Initialized + * @return false Not-initialized + */ +bool Sht::isBegin(void) { + if (this->_isBegin) { + return true; + } + AgLog("Sensor not-initialized"); + return false; +} + +/** + * @brief Check board is support I2C to work with this sensor + * + * @return true Supported + * @return false Not supported + */ +bool Sht::boardSupported(void) { + if (this->_bsp == NULL) { + this->_bsp = getBoardDef(this->_boardType); + } + + if ((this->_bsp == NULL) || (this->_bsp->I2C.supported == false)) { + AgLog("Board not supported"); + return false; + } + return true; +} + +/** + * @brief Construct a new Sht:: Sht object + * + * @param type + */ +Sht::Sht(BoardType type) : _boardType(type) {} + +/** + * @brief Destroy the Sht:: Sht object + * + */ +Sht::~Sht() {} + +#if defined(ESP8266) +/** + * @brief Init sensor, Ifthis funciton not call the other funtion call will + * always return false or value invalid + * + * @param wire wire TwoWire instance, Must be initialized + * @param debugStream Point to debug Serial to print debug log + * @return true Sucecss + * @return false Failure + */ +bool Sht::begin(TwoWire &wire, Stream &debugStream) { + _debugStream = &debugStream; + return begin(wire); +} +#else +#endif +/** + * @brief Initialize sensor, should be init sensor before use other API, if not + * return result always failed + * + * @param wire TwoWire instance, Must be initialized + * @return true Success + * @return false Failure + */ +bool Sht::begin(TwoWire &wire) { + if (_isBegin) { + AgLog("Initialized, call end() then try again"); + return true; + } + + if (boardSupported() == false) { + return false; + } + + /** Create new sensor */ + _sensor = new SHTSensor(); + if (_sensor == nullptr) { + AgLog("Create SHTSensor failed"); + return false; + } + + /** Initialize sensor */ + if (shtSensor()->init(wire) == false) { + AgLog("Initialize SHTSensor failed"); + return false; + } + + // Only supported by SHT3x + if (shtSensor()->setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM) == false) { + AgLog("Configure sensor failed"); + return false; + } + + AgLog("Initialize"); + _isBegin = true; + return true; +} + +/** + * @brief De-initialize sht sensor + * + */ +void Sht::end(void) { + if (_isBegin == false) { + return; + } + delete shtSensor(); + _isBegin = false; +#if defined(ESP8266) + _debugStream = nullptr; +#else +#endif + _isBegin = false; + AgLog("De-Initialize"); +} + +/** + * @brief Get temprature degree celcius + * + * @return float + */ +float Sht::getTemperature(void) { return shtSensor()->getTemperature(); } + +/** + * @brief Get humidity + * + * @return float + */ +float Sht::getRelativeHumidity(void) { return shtSensor()->getHumidity(); } + +/** + * @brief Measure temperature and humidity + * + * @return true Success + * @return false Failure + */ +bool Sht::measure(void) { return shtSensor()->readSample(); } diff --git a/src/sht/sht4x.h b/src/sht/sht.h similarity index 53% rename from src/sht/sht4x.h rename to src/sht/sht.h index b7a3b11..6a9e9e1 100644 --- a/src/sht/sht4x.h +++ b/src/sht/sht.h @@ -1,40 +1,42 @@ -#ifndef _AIR_GRADIENT_SHT_H_ -#define _AIR_GRADIENT_SHT_H_ +#ifndef _SHT_H_ +#define _SHT_H_ +#include "../main/BoardDef.h" #include #include -#include "../main/BoardDef.h" - /** - * @brief The class with define how to handle the Sensirion sensor SHT41 - * (temperature and humidity sensor). + * @brief This class with define how to handlet sensirion sensor sht4x and + * sht3x(Temperature and humidity sensor) + * */ -class Sht4x { -public: -#if defined(ESP8266) - bool begin(TwoWire &wire, Stream &debugStream); -#else -#endif - Sht4x(BoardType type); - bool begin(TwoWire &wire); - void end(void); - float getTemperature(void); - float getRelativeHumidity(void); - +class Sht { private: BoardType _boardType; - bool _isBegin = false; /** Flag indicate that sensor initialized or not */ + bool _isBegin = false; void *_sensor; const BoardDef *_bsp = NULL; #if defined(ESP8266) Stream *_debugStream = nullptr; - const char *TAG = "SHT4x"; + const char *TAG = "SHT"; #else #endif bool isBegin(void); bool boardSupported(void); - bool measureMediumPrecision(float &temperature, float &humidity); + +public: + Sht(BoardType type); + ~Sht(); + +#if defined(ESP8266) + bool begin(TwoWire &wire, Stream &debugStream); +#else +#endif + bool begin(TwoWire &wire); + void end(void); + bool measure(void); + float getTemperature(void); + float getRelativeHumidity(void); }; -#endif /** _AIR_GRADIENT_SHT_H_ */ +#endif /** _SHT_H_ */ diff --git a/src/sht/sht3x.cpp b/src/sht/sht3x.cpp deleted file mode 100644 index 62aa5e3..0000000 --- a/src/sht/sht3x.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "sht3x.h" -#include "../library/arduino-i2c-sht3x/src/SensirionI2cSht3x.h" - -#define sht3x() ((SensirionI2cSht3x *)(this->_sensor)) - -/** - * @brief Check that sensor has initialized - * - * @return true Initialized - * @return false Not-initialized - */ -bool Sht3x::isBegin(void) { - if (_isBegin) { - return true; - } - AgLog("Sensor not-initialized"); - return false; -} - -/** - * @brief Check sensor has supported by board - * - * @return true Supported - * @return false Not-supported - */ -bool Sht3x::boardSupported(void) { - if (_bsp == NULL) { - _bsp = getBoardDef(_boarType); - } - - if ((_bsp == NULL) || (_bsp->I2C.supported == false)) { - AgLog("Board not supported"); - return false; - } - return true; -} - -/** - * @brief Get temperature and humidity data - * - * @param temp Tempreature read out - * @param hum Humidity read out - * @return true Success - * @return false Failure - */ -bool Sht3x::measure(float &temp, float &hum) { - if (isBegin() == false) { - return false; - } - - if (sht3x()->measureSingleShot(REPEATABILITY_MEDIUM, false, temp, hum) == - NO_ERROR) { - return true; - } - return false; -} - -/** - * @brief Construct a new Sht 3x:: Sht 3x object - * - * @param type - */ -Sht3x::Sht3x(BoardType type) : _boarType(type) {} - -/** - * @brief Destroy the Sht 3x:: Sht 3x object - * - */ -Sht3x::~Sht3x() { end(); } - -#ifdef ESP8266 -/** - * @brief Initialized sensor - * - * @param wire TwoWire instance, must be initialized - * @param debugStream Point to debug Serial to print debug log - * @return true Success - * @return false Failure - */ -bool Sht3x::begin(TwoWire &wire, Stream &debugStream) { - _debugStream = &debugStream; - return begin(wire); -} -#else -#endif - -/** - * @brief Init sensor, should init before use sensor, if not call other method - * always return invalid - * - * @param wire TwoWire instance, must be initialized - * @return true Success - * @return false Failure - */ -bool Sht3x::begin(TwoWire &wire) { - if (_isBegin) { - AgLog("Initialized, call end() then try again"); - return true; - } - - /** Check sensor has supported on board */ - if (boardSupported() == false) { - return false; - } - - /** Create sensor and init */ - _sensor = new SensirionI2cSht3x(); - sht3x()->begin(wire, SHT30_I2C_ADDR_44); - if (sht3x()->softReset() != NO_ERROR) { - AgLog("Reset sensor fail, look like sensor is not on I2C bus"); - return false; - } - - _isBegin = true; - AgLog("Initialize"); - return true; -} - -/** - * @brief De-initialize sensor - * - */ -void Sht3x::end(void) { - if (_isBegin == false) { - return; - } - _isBegin = false; - _bsp = NULL; - delete sht3x(); -#ifdef ESP8266 - _debugStream = nullptr; -#endif - AgLog("De-initialize"); -} - -/** - * @brief Get temperature degree celsius - * - * @return float value <= 256.0f is invalid, that mean sensor has issue or - * communication to sensor not worked as well - */ -float Sht3x::getTemperature(void) { - float temp; - float hum; - if (measure(temp, hum)) { - return temp; - } - return -256.0f; -} - -/** - * @brief Get humidity - * - * @return float Percent(0 - 100), value < 0 is invalid. - */ -float Sht3x::getRelativeHumidity(void) { - float temp; - float hum; - if (measure(temp, hum)) { - return hum; - } - return -1.0f; -} diff --git a/src/sht/sht3x.h b/src/sht/sht3x.h deleted file mode 100644 index 971aaa6..0000000 --- a/src/sht/sht3x.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _AIR_GRADIENT_SHT3X_H_ -#define _AIR_GRADIENT_SHT3X_H_ - -#include "../main/BoardDef.h" -#include -#include - -/** - * @brief The class with define how to handle the Sensirion sensor SHT3x - * (temperature and humidity sensor). - */ -class Sht3x { -private: - BoardType _boarType; - bool _isBegin = false; - const BoardDef *_bsp = NULL; - void *_sensor; -#ifdef ESP8266 - Stream *_debugStream = nullptr; - const char *TAG = "SHT3x"; -#else -#endif - - bool isBegin(void); - bool boardSupported(void); - bool measure(float &temp, float &hum); - -public: - Sht3x(BoardType type); - ~Sht3x(); - -#ifdef ESP8266 - bool begin(TwoWire &wire, Stream &debugStream); -#else -#endif - bool begin(TwoWire &wire); - void end(void); - float getTemperature(void); - float getRelativeHumidity(void); -}; - -#endif /** _AIR_GRADIENT_SHT3X_H_ */ diff --git a/src/sht/sht4x.cpp b/src/sht/sht4x.cpp deleted file mode 100644 index df49b7e..0000000 --- a/src/sht/sht4x.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include "sht4x.h" -#include "../library/SensirionSHT4x/src/SensirionI2CSht4x.h" - -/** Cast _sensor to SensirionI2CSht4x */ -#define shtSensor() ((SensirionI2CSht4x *)(this->_sensor)) - -#if defined(ESP8266) -/** - * @brief Init sensor, Ifthis funciton not call the other funtion call will - * always return false or value invalid - * - * @param wire wire TwoWire instance, Must be initialized - * @param debugStream Point to debug Serial to print debug log - * @return true Sucecss - * @return false Failure - */ -bool Sht4x::begin(TwoWire &wire, Stream &debugStream) { - this->_debugStream = &debugStream; - return this->begin(wire); -} -#else -#endif - -/** - * @brief Construct a new Sht4x:: Sht4x object - * - * @param type Board type @ref BoardType - */ -Sht4x::Sht4x(BoardType type) : _boardType(type) {} - -/** - * @brief Init sensor, Ifthis funciton not call the other funtion call will - * always return false or value invalid - * - * @param wire TwoWire instance, Must be initialized - * @return true Success - * @return false Failure - */ -bool Sht4x::begin(TwoWire &wire) { - /** Ignore next step if sensor has intiialized */ - if (this->_isBegin) { - AgLog("Initialized, call end() then try again"); - return true; - } - - /** Check sensor has supported on board */ - if (this->boardSupported() == false) { - return false; - } - - /** Create new SensirionI2CSht4x and init */ - this->_sensor = new SensirionI2CSht4x(); - shtSensor()->begin(wire, SHT40_I2C_ADDR_44); - if (shtSensor()->softReset() != 0) { - AgLog("Reset sensor fail, look like sensor is not on I2C bus"); - return false; - } - - delay(10); - - this->_isBegin = true; - AgLog("Initialize"); - return true; -} - -/** - * @brief De-initialize SHT41 sensor - * - */ -void Sht4x::end(void) { - if (this->_isBegin == false) { - return; - } - - this->_isBegin = false; - _bsp = NULL; - delete shtSensor(); -#if defined(ESP8266) - _debugStream = nullptr; -#endif -AgLog("De-initialize"); -} - -/** - * @brief Get temperature degrees celsius - * - * @return float value <= 256.0f is invalid, That mean sensor has issue or - * communication to sensor not worked as well. - */ -float Sht4x::getTemperature(void) { - float temperature; - float humidity; - if (this->measureMediumPrecision(temperature, humidity)) { - return temperature; - } - - return -256.0f; -} - -/** - * @brief Get humidity - * - * @return float Percent(0 - 100), value < 0 is invalid. - */ -float Sht4x::getRelativeHumidity(void) { - float temperature; - float humidity; - if (this->measureMediumPrecision(temperature, humidity)) { - return humidity; - } - - return -1.0f; -} - -/** - * @brief Check sensor has supported by board - * - * @return true Supported - * @return false Not supported - */ -bool Sht4x::boardSupported(void) { - if (this->_bsp == NULL) { - this->_bsp = getBoardDef(this->_boardType); - } - - if ((this->_bsp == NULL) || (this->_bsp->I2C.supported == false)) { - AgLog("Board not supported"); - return false; - } - return true; -} - -/** - * @brief Check that sensor has initialized - * - * @return true Initialized - * @return false Not-initialized - */ -bool Sht4x::isBegin(void) { - if (this->_isBegin) { - return true; - } - AgLog("Sensor not-initialized"); - return false; -} - -/** - * @brief Ge SHT41 temperature and humidity value with medium meaure precision - * - * @param temperature Read out temperarure - * @param humidity Read humidity - * @return true Success - * @return false Failure - */ -bool Sht4x::measureMediumPrecision(float &temperature, float &humidity) { - if (this->isBegin() == false) { - return false; - } - - if (shtSensor()->measureMediumPrecision(temperature, humidity) == 0) { - return true; - } - return false; -} -