From 1df73f732a764221ff3a9107821f69600f90579e Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Fri, 5 Apr 2024 10:40:16 +0200 Subject: [PATCH] 0.5.1 AM232X --- libraries/AM232X/.github/FUNDING.yml | 3 +- .../AM232X/.github/workflows/arduino-lint.yml | 3 +- .../.github/workflows/arduino_test_runner.yml | 7 +- .../AM232X/.github/workflows/jsoncheck.yml | 5 +- libraries/AM232X/AM232X.cpp | 38 ++++----- libraries/AM232X/AM232X.h | 24 +++--- libraries/AM232X/CHANGELOG.md | 5 ++ libraries/AM232X/LICENSE | 2 +- libraries/AM232X/examples/AM2320/AM2320.ino | 8 +- .../examples/AM2320_ESP32/AM2320_ESP32.ino | 2 +- .../examples/AM2320_test/AM2320_test.ino | 6 +- libraries/AM232X/examples/AM2322/AM2322.ino | 8 +- .../AM2322_plotter/AM2322_plotter.ino | 2 +- .../TCA9548_demo_AM2320/.arduino-ci.yml | 30 +++++++ .../TCA9548_demo_AM2320.ino | 82 +++++++++++++++++++ libraries/AM232X/library.json | 2 +- libraries/AM232X/library.properties | 6 +- 17 files changed, 176 insertions(+), 57 deletions(-) create mode 100644 libraries/AM232X/examples/TCA9548_demo_AM2320/.arduino-ci.yml create mode 100644 libraries/AM232X/examples/TCA9548_demo_AM2320/TCA9548_demo_AM2320.ino diff --git a/libraries/AM232X/.github/FUNDING.yml b/libraries/AM232X/.github/FUNDING.yml index 90d9ab4c..2859c159 100644 --- a/libraries/AM232X/.github/FUNDING.yml +++ b/libraries/AM232X/.github/FUNDING.yml @@ -1,4 +1,5 @@ # These are supported funding model platforms -github: RobTillaart +github: RobTillaart +custom: "https://www.paypal.me/robtillaart" diff --git a/libraries/AM232X/.github/workflows/arduino-lint.yml b/libraries/AM232X/.github/workflows/arduino-lint.yml index 8a26f14a..70d8d1c3 100644 --- a/libraries/AM232X/.github/workflows/arduino-lint.yml +++ b/libraries/AM232X/.github/workflows/arduino-lint.yml @@ -5,8 +5,9 @@ on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/arduino-lint-action@v1 with: library-manager: update diff --git a/libraries/AM232X/.github/workflows/arduino_test_runner.yml b/libraries/AM232X/.github/workflows/arduino_test_runner.yml index a1090a68..501768ee 100644 --- a/libraries/AM232X/.github/workflows/arduino_test_runner.yml +++ b/libraries/AM232X/.github/workflows/arduino_test_runner.yml @@ -1,4 +1,4 @@ ---- + name: Arduino CI on: [push, pull_request] @@ -6,12 +6,13 @@ on: [push, pull_request] jobs: runTest: runs-on: ubuntu-latest + timeout-minutes: 20 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 - run: | gem install arduino_ci - arduino_ci.rb \ No newline at end of file + arduino_ci.rb diff --git a/libraries/AM232X/.github/workflows/jsoncheck.yml b/libraries/AM232X/.github/workflows/jsoncheck.yml index 37a11298..fd05f5f8 100644 --- a/libraries/AM232X/.github/workflows/jsoncheck.yml +++ b/libraries/AM232X/.github/workflows/jsoncheck.yml @@ -9,10 +9,11 @@ on: jobs: test: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: json-syntax-check - uses: limitusus/json-syntax-check@v1 + uses: limitusus/json-syntax-check@v2 with: pattern: "\\.json$" diff --git a/libraries/AM232X/AM232X.cpp b/libraries/AM232X/AM232X.cpp index 5bd5b534..81b1dff7 100644 --- a/libraries/AM232X/AM232X.cpp +++ b/libraries/AM232X/AM232X.cpp @@ -1,7 +1,7 @@ // // FILE: AM232X.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.5.0 +// VERSION: 0.5.1 // PURPOSE: AM232X library for AM2320 for Arduino. // URL: https://github.com/RobTillaart/AM232X @@ -60,7 +60,7 @@ int AM232X::read() } _lastRead = millis(); - // READ HUMIDITY AND TEMPERATURE REGISTERS + // READ HUMIDITY AND TEMPERATURE REGISTERS int rv = _readRegister(0x00, 4); if (rv < 0) return rv; @@ -71,7 +71,7 @@ int AM232X::read() _humidity = AM232X_INVALID_VALUE; _temperature = AM232X_INVALID_VALUE; } - return rv; // propagate error value + return rv; // propagate error value } // EXTRACT HUMIDITY AND TEMPERATURE @@ -79,7 +79,7 @@ int AM232X::read() int16_t t = ((_bits[4] & 0x7F) * 256 + _bits[5]); if (t == 0) { - _temperature = 0.0; // prevent -0.0; + _temperature = 0.0; // prevent -0.0; } else { @@ -91,7 +91,7 @@ int AM232X::read() } #ifdef AM232X_VALUE_OUT_OF_RANGE - // TEST OUT OF RANGE + // TEST OUT OF RANGE if (_humidity > 100) { return AM232X_HUMIDITY_OUT_OF_RANGE; @@ -127,7 +127,7 @@ void AM232X::setReadDelay(uint16_t readDelay) _readDelay = readDelay; if (_readDelay == 0) { - _readDelay = 2000; // reset + _readDelay = 2000; // reset } }; @@ -218,17 +218,17 @@ int AM232X::setUserRegisterB(int value) //////////////////////////////////////////////////////////////////// // -// PROTECTED +// PROTECTED // int AM232X::_readRegister(uint8_t reg, uint8_t count) { - // HANDLE PENDING IRQ + // HANDLE PENDING IRQ yield(); - // WAKE UP the sensor + // WAKE UP the sensor if (! wakeUp() ) return AM232X_ERROR_CONNECT; - // request the data + // request the data _wire->beginTransmission(AM232X_ADDRESS); _wire->write(0x03); _wire->write(reg); @@ -236,22 +236,22 @@ int AM232X::_readRegister(uint8_t reg, uint8_t count) int rv = _wire->endTransmission(); if (rv < 0) return rv; - // request 4 extra, 2 for cmd + 2 for CRC + // request 4 extra, 2 for command + 2 for CRC rv = _getData(count + 4); return rv; } -int AM232X::_writeRegister(uint8_t reg, uint8_t cnt, int16_t value) +int AM232X::_writeRegister(uint8_t reg, uint8_t count, int16_t value) { if (! wakeUp() ) return AM232X_ERROR_CONNECT; - // prepare data to send + // prepare data to send _bits[0] = 0x10; _bits[1] = reg; - _bits[2] = cnt; + _bits[2] = count; - if (cnt == 2) + if (count == 2) { _bits[4] = value & 0xFF; _bits[3] = (value >> 8) & 0xFF; @@ -261,8 +261,8 @@ int AM232X::_writeRegister(uint8_t reg, uint8_t cnt, int16_t value) _bits[3] = value & 0xFF; } - // send data - uint8_t length = cnt + 3; // 3 = cmd, startReg, #bytes + // send data + uint8_t length = count + 3; // 3 = command, startReg, #bytes _wire->beginTransmission(AM232X_ADDRESS); for (int i = 0; i < length; i++) { @@ -320,10 +320,10 @@ int AM232X::_getData(uint8_t length) } -uint16_t AM232X::_crc16(uint8_t *ptr, uint8_t len) +uint16_t AM232X::_crc16(uint8_t *ptr, uint8_t length) { uint16_t crc = 0xFFFF; - while(len--) + while(length--) { crc ^= *ptr++; for (uint8_t i = 0; i < 8; i++) diff --git a/libraries/AM232X/AM232X.h b/libraries/AM232X/AM232X.h index 14960e12..47759241 100644 --- a/libraries/AM232X/AM232X.h +++ b/libraries/AM232X/AM232X.h @@ -3,7 +3,7 @@ // FILE: AM232X.h // AUTHOR: Rob Tillaart // PURPOSE: AM232X Temperature and Humidity sensor library for Arduino -// VERSION: 0.5.0 +// VERSION: 0.5.1 // URL: https://github.com/RobTillaart/AM232X // // AM232X PIN layout AM2315 COLOR @@ -16,14 +16,14 @@ // |o | SCL GREY // +---+ // -// do not forget pull up resistors between SDA, SCL and VDD. +// do not forget pull up resistors between SDA, SCL and VDD. #include "Arduino.h" #include "Wire.h" -#define AM232X_LIB_VERSION (F("0.5.0")) +#define AM232X_LIB_VERSION (F("0.5.1")) #define AM232X_OK 0 @@ -100,8 +100,8 @@ public: // might introduce under- or overflow at the ends of the sensor range void setHumOffset(float offset = 0) { _humOffset = offset; }; void setTempOffset(float offset = 0) { _tempOffset = offset; }; - float getHumOffset() { return _humOffset; }; - float getTempOffset() { return _tempOffset; }; + float getHumOffset() { return _humOffset; }; + float getTempOffset() { return _tempOffset; }; // suppress error values of -999 => check return value of read() instead bool getSuppressError() { return _suppressError; }; @@ -109,8 +109,9 @@ public: bool wakeUp() { return isConnected(); }; + protected: - uint8_t _bits[8]; // buffer to hold raw data + uint8_t _bits[8]; // buffer to hold raw data float _humidity = 0.0; float _temperature = 0.0; float _humOffset = 0.0; @@ -120,11 +121,11 @@ protected: bool _suppressError = false; - int _readRegister(uint8_t reg, uint8_t cnt); - int _writeRegister(uint8_t reg, uint8_t cnt, int16_t value); + int _readRegister(uint8_t reg, uint8_t count); + int _writeRegister(uint8_t reg, uint8_t count, int16_t value); int _getData(uint8_t length); - uint16_t _crc16(uint8_t *ptr, uint8_t len); + uint16_t _crc16(uint8_t *ptr, uint8_t length); TwoWire* _wire; }; @@ -132,7 +133,7 @@ protected: ///////////////////////////////////////////////////////////////////////////// // -// AM232X derived classes +// AM232X derived classes // class AM2320 : public AM232X { @@ -155,8 +156,5 @@ public: }; - - - // -- END OF FILE -- diff --git a/libraries/AM232X/CHANGELOG.md b/libraries/AM232X/CHANGELOG.md index 745d2669..b9fe0220 100644 --- a/libraries/AM232X/CHANGELOG.md +++ b/libraries/AM232X/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.5.1] - 2024-04-04 +- update GitHub actions +- minor edits + + ## [0.5.0] - 2023-10-15 - simplify begin - update readme.md diff --git a/libraries/AM232X/LICENSE b/libraries/AM232X/LICENSE index 562b0ffe..a4357241 100644 --- a/libraries/AM232X/LICENSE +++ b/libraries/AM232X/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2023 Rob Tillaart +Copyright (c) 2017-2024 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/AM232X/examples/AM2320/AM2320.ino b/libraries/AM232X/examples/AM2320/AM2320.ino index 06308f63..eb6916b8 100644 --- a/libraries/AM232X/examples/AM2320/AM2320.ino +++ b/libraries/AM232X/examples/AM2320/AM2320.ino @@ -13,7 +13,7 @@ // |o | SCL GREY // +---+ // -// do not forget pull up resistors between SDA, SCL and VDD.. +// do not forget pull up resistors between SDA, SCL and VDD.. #include "AM232X.h" @@ -44,7 +44,7 @@ void setup() void loop() { - // READ DATA + // READ DATA Serial.print("AM2320, \t"); int status = AM2320.read(); switch (status) @@ -57,7 +57,7 @@ void loop() Serial.print("\t"); break; } - // DISPLAY DATA, sensor only returns one decimal. + // DISPLAY DATA, sensor only returns one decimal. Serial.print(AM2320.getHumidity(), 1); Serial.print(",\t"); Serial.println(AM2320.getTemperature(), 1); @@ -66,4 +66,4 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/AM232X/examples/AM2320_ESP32/AM2320_ESP32.ino b/libraries/AM232X/examples/AM2320_ESP32/AM2320_ESP32.ino index aa99d8b8..c5cb0be4 100644 --- a/libraries/AM232X/examples/AM2320_ESP32/AM2320_ESP32.ino +++ b/libraries/AM232X/examples/AM2320_ESP32/AM2320_ESP32.ino @@ -39,7 +39,7 @@ void setup() I2C_IMU.begin(); I2C_DHT.begin(pd_sda_dht, pd_scl_dht, 100000ul); - + if (! AM2320.begin() ) { Serial.println("Sensor not found"); diff --git a/libraries/AM232X/examples/AM2320_test/AM2320_test.ino b/libraries/AM232X/examples/AM2320_test/AM2320_test.ino index 51d0c9d7..dad4cde0 100644 --- a/libraries/AM232X/examples/AM2320_test/AM2320_test.ino +++ b/libraries/AM232X/examples/AM2320_test/AM2320_test.ino @@ -13,7 +13,7 @@ // |o | SCL GREY // +---+ // -// do not forget pull up resistors between SDA, SCL and VDD. +// do not forget pull up resistors between SDA, SCL and VDD. #include "AM232X.h" @@ -38,7 +38,7 @@ void setup() AM2320.wakeUp(); delay(2000); - // sensor only returns one decimal. + // sensor only returns one decimal. Serial.println(); Serial.println("Read:\t"); @@ -112,4 +112,4 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/AM232X/examples/AM2322/AM2322.ino b/libraries/AM232X/examples/AM2322/AM2322.ino index b3348f01..1ce533d0 100644 --- a/libraries/AM232X/examples/AM2322/AM2322.ino +++ b/libraries/AM232X/examples/AM2322/AM2322.ino @@ -13,7 +13,7 @@ // |o | SCL GREY // +---+ // -// do not forget pull up resistors between SDA, SCL and VDD. +// do not forget pull up resistors between SDA, SCL and VDD. #include "AM232X.h" @@ -44,7 +44,7 @@ void setup() void loop() { - // READ DATA + // READ DATA Serial.print("AM2322, \t"); int status = AM2322.read(); switch (status) @@ -57,7 +57,7 @@ void loop() Serial.print("\t"); break; } - // DISPLAY DATA, sensor only returns one decimal. + // DISPLAY DATA, sensor only returns one decimal. Serial.print(AM2322.getHumidity(), 1); Serial.print(",\t"); Serial.println(AM2322.getTemperature(), 1); @@ -66,4 +66,4 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/AM232X/examples/AM2322_plotter/AM2322_plotter.ino b/libraries/AM232X/examples/AM2322_plotter/AM2322_plotter.ino index d60ea204..ca3394a1 100644 --- a/libraries/AM232X/examples/AM2322_plotter/AM2322_plotter.ino +++ b/libraries/AM232X/examples/AM2322_plotter/AM2322_plotter.ino @@ -28,7 +28,7 @@ void setup() // Serial.print("LIBRARY VERSION: "); // Serial.println(AM232X_LIB_VERSION); // Serial.println(); - + Wire.begin(); if (! AM2322.begin() ) { diff --git a/libraries/AM232X/examples/TCA9548_demo_AM2320/.arduino-ci.yml b/libraries/AM232X/examples/TCA9548_demo_AM2320/.arduino-ci.yml new file mode 100644 index 00000000..4282dd83 --- /dev/null +++ b/libraries/AM232X/examples/TCA9548_demo_AM2320/.arduino-ci.yml @@ -0,0 +1,30 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + +compile: + # Choosing to run compilation tests on 2 different Arduino platforms + platforms: + - uno + # - due + # - zero + # - leonardo + - m4 + - esp32 + - esp8266 + # - mega2560 + - rpipico + libraries: + - "AM232X" + - "TCA9548" diff --git a/libraries/AM232X/examples/TCA9548_demo_AM2320/TCA9548_demo_AM2320.ino b/libraries/AM232X/examples/TCA9548_demo_AM2320/TCA9548_demo_AM2320.ino new file mode 100644 index 00000000..bd1c1a85 --- /dev/null +++ b/libraries/AM232X/examples/TCA9548_demo_AM2320/TCA9548_demo_AM2320.ino @@ -0,0 +1,82 @@ +// +// FILE: TCA9548_demo_AM2320.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo TCA9548 I2C multiplexer +// URL: https://github.com/RobTillaart/TCA9548 + + +#include "AM232X.h" +#include "TCA9548.h" + + +PCA9546 MP(0x70); +uint8_t channels = 0; + +AM232X living; // channel 0 +AM232X kitchen; // channel 1 +AM232X outside; // channel 2 + +uint32_t lastTime = 0; + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("TCA9548_LIB_VERSION: "); + Serial.println(TCA9548_LIB_VERSION); + Serial.print("AM232X_LIB_VERSION: "); + Serial.println(AM232X_LIB_VERSION); + Serial.println(); + + Wire.begin(); + // initialize multiplexer + if (MP.begin() == false) + { + Serial.println("Multiplexer error"); + } + channels = MP.channelCount(); + + // initialize the temperature sensors + MP.selectChannel(0); + if (living.begin() == false) + { + Serial.println("living error"); + } + MP.selectChannel(1); + if (kitchen.begin() == false ) + { + Serial.println("kitchen error"); + } + MP.selectChannel(2); + if (outside.begin() == false ) + { + Serial.println("outside error"); + } +} + + +void loop() +{ + if ((millis() - lastTime) > 5000) + { + lastTime = millis(); + + MP.selectChannel(0); + living.read(); + Serial.print(living.getTemperature(), 1); + Serial.print("\t"); + + MP.selectChannel(1); + kitchen.read(); + Serial.print(kitchen.getTemperature(), 1); + Serial.print("\t"); + + MP.selectChannel(2); + outside.read(); + Serial.print(outside.getTemperature(), 1); + Serial.print("\n"); + } +} + + +// -- END OF FILE -- diff --git a/libraries/AM232X/library.json b/libraries/AM232X/library.json index c0ffaa3e..83ee289b 100644 --- a/libraries/AM232X/library.json +++ b/libraries/AM232X/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AM232X" }, - "version": "0.5.0", + "version": "0.5.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/AM232X/library.properties b/libraries/AM232X/library.properties index da1c6a16..cf5e6746 100644 --- a/libraries/AM232X/library.properties +++ b/libraries/AM232X/library.properties @@ -1,9 +1,9 @@ name=AM232X -version=0.5.0 +version=0.5.1 author=Rob Tillaart maintainer=Rob Tillaart -sentence=Arduino library for AM2320 AM2321 and AM2323 I2C temperature and humidity sensor. -paragraph=Supports AM2320, AM3231, AM2322. These sensors are similar to DHT12 with I2C interface. +sentence=Arduino library for AM2320 AM2321 and AM2323 I2C temperature and humidity sensor. +paragraph=Supports AM2320, AM3231, AM2322. These sensors are similar to DHT12 with I2C interface. category=Sensors url=https://github.com/RobTillaart/AM232X architectures=*