From 999991ea2b9d9a9c1d789c37c9a14fc2f1da2b1a Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Sun, 15 Oct 2023 14:17:19 +0200 Subject: [PATCH] 0.2.0 AM2315 --- libraries/AM2315/AM2315.cpp | 23 ++-------------- libraries/AM2315/AM2315.h | 9 +++---- libraries/AM2315/CHANGELOG.md | 11 +++++++- libraries/AM2315/README.md | 26 ++++++++++++------- .../examples/AM2315_offset/AM2315_offset.ino | 16 +++++++++--- .../AM2315_performance/AM2315_performance.ino | 18 ++++++++----- .../examples/AM2315_test/AM2315_test.ino | 15 +++++++---- libraries/AM2315/library.json | 4 +-- libraries/AM2315/library.properties | 2 +- libraries/AM2315/test/unit_test_001.cpp | 5 ++-- 10 files changed, 71 insertions(+), 58 deletions(-) diff --git a/libraries/AM2315/AM2315.cpp b/libraries/AM2315/AM2315.cpp index e362d07e..e3f0a984 100644 --- a/libraries/AM2315/AM2315.cpp +++ b/libraries/AM2315/AM2315.cpp @@ -1,11 +1,9 @@ // // FILE: AM2315.cpp -// AUTHOR: Rob.Tillaart@gmail.com -// VERSION: 0.1.7 +// AUTHOR: Rob Tillaart +// VERSION: 0.2.0 // PURPOSE: AM2315 Temperature and Humidity sensor library for Arduino // URL: https://github.com/RobTillaart/AM2315 -// -// HISTORY: see changelog.md #include "AM2315.h" @@ -35,25 +33,8 @@ AM2315::AM2315(TwoWire *wire) } -#if defined(ESP8266) || defined(ESP32) -bool AM2315::begin(const uint8_t dataPin, const uint8_t clockPin) -{ - if ((dataPin < 255) && (clockPin < 255)) - { - _wire->begin(dataPin, clockPin); - } else { - _wire->begin(); - } - if (! isConnected()) return false; - this->read(); - return true; -} -#endif - - bool AM2315::begin() { - _wire->begin(); if (! isConnected()) return false; this->read(); return true; diff --git a/libraries/AM2315/AM2315.h b/libraries/AM2315/AM2315.h index e158da8f..00fd70c4 100644 --- a/libraries/AM2315/AM2315.h +++ b/libraries/AM2315/AM2315.h @@ -3,7 +3,7 @@ // FILE: AM2315.h // AUTHOR: Rob Tillaart // PURPOSE: AM2315 Temperature and Humidity sensor library for Arduino -// VERSION: 0.1.7 +// VERSION: 0.2.0 // URL: https://github.com/RobTillaart/AM2315 // // AM232X PIN layout AM2315 COLOR @@ -23,7 +23,7 @@ #include "Wire.h" -#define AM2315_LIB_VERSION (F("0.1.7")) +#define AM2315_LIB_VERSION (F("0.2.0")) #define AM2315_OK 0 @@ -51,9 +51,6 @@ public: AM2315(TwoWire *wire = &Wire); -#if defined(ESP8266) || defined(ESP32) - bool begin(const uint8_t dataPin, const uint8_t clockPin); -#endif bool begin(); // datasheet- wake up is min 800 us max 3000 us bool isConnected(uint16_t timeout = 3000); @@ -61,7 +58,7 @@ public: int read(); // lastRead is in MilliSeconds since start sketch - uint32_t lastRead() { return _lastRead; }; + uint32_t lastRead() { return _lastRead; }; // preferred interface float getHumidity(); diff --git a/libraries/AM2315/CHANGELOG.md b/libraries/AM2315/CHANGELOG.md index 125c5f12..e51cbc9c 100644 --- a/libraries/AM2315/CHANGELOG.md +++ b/libraries/AM2315/CHANGELOG.md @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.0] - 2023-10-13 +- simplified **begin()** no more Wire pin setting. +- update examples. +- add **AM2315_Wire1.ino** example +- update readme.md +- update unit test +- minor edits + +---- + ## [0.1.7] - 2023-01-21 - update GitHub actions - update license 2023 @@ -14,7 +24,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - add offset example - minor edit README.md - ## [0.1.6] - 2022-10-27 - Add RP2040 support to build-CI. - Add CHANGELOG.md diff --git a/libraries/AM2315/README.md b/libraries/AM2315/README.md index e5eaf5b2..26a9299b 100644 --- a/libraries/AM2315/README.md +++ b/libraries/AM2315/README.md @@ -2,8 +2,11 @@ [![Arduino CI](https://github.com/RobTillaart/AM2315/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino-lint](https://github.com/RobTillaart/AM2315/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AM2315/actions/workflows/arduino-lint.yml) [![JSON check](https://github.com/RobTillaart/AM2315/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AM2315/actions/workflows/jsoncheck.yml) +[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AM2315.svg)](https://github.com/RobTillaart/AM2315/issues) + [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AM2315/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/AM2315.svg?maxAge=3600)](https://github.com/RobTillaart/AM2315/releases) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AM2315.svg)](https://registry.platformio.org/libraries/robtillaart/AM2315) # AM2315 @@ -13,7 +16,7 @@ Arduino library for an AM2315 I2C temperature and humidity sensor. ## Description -The AM2315 is a sensor similar to the DHT12 with an I2C interface. +The AM2315 is a sensor similar to the DHT12 with an I2C interface. Although in theory this could enable multiple sensors on one bus the AM2315 has a fixed address **0x5C** so one need to implement a @@ -61,7 +64,7 @@ The C-version has a fixed address of **0x38** so easy to detect. The datasheet states the AM2315 should be used on 100 KHz I2C only. When overclocking I got good readings up to 190 KHz in a test with - Arduino UNO -- very short wires (< 1 meter) +- very short wires ( < 1 meter) - not using pull ups. - version 0.1.1 of this library @@ -82,7 +85,6 @@ If robustness is mandatory stick to the default of 100 KHz. If performance is mandatory do not go beyond 170 KHz. - ## Interface ```cpp @@ -93,9 +95,7 @@ If performance is mandatory do not go beyond 170 KHz. #### Constructor - **AM2315(TwoWire \*wire = &Wire)** constructor, default using Wire (I2C bus), optionally set to Wire0 .. WireN. -- **bool begin(uint8_t dataPin, uint8_t clockPin)** begin for ESP32 et al, to set I2C bus pins. -Returns true if device address 0x5C is connected. -- **bool begin()** initializer for non ESP32 e.g. AVR. +- **bool begin()** initializer. Returns true if device address 0x5C is connected. - **bool isConnected(uint16_t timeout = 3000)** returns true if the device address 0x5C is found on I2C bus. As the device can be in sleep modus it will retry for the defined timeout (in micros) with a minimum of 1 try. @@ -200,17 +200,25 @@ Which method fit your application depends on your requirements and constraints. - keep in sync with AM232X class - merge in a far future. -- update unit test -- add examples + #### Could - move code from .h to .cpp -#### Won't +#### Wont - add calls for meta information (no description yet) - 0x07 status register - 0x08-0x0B user register HIGH LOW HIGH2 LOW2 (use AM232x library to access those) + +## Support + +If you appreciate my libraries, you can support the development and maintenance. +Improve the quality of the libraries by providing issues and Pull Requests, or +donate through PayPal or GitHub sponsors. + +Thank you, + diff --git a/libraries/AM2315/examples/AM2315_offset/AM2315_offset.ino b/libraries/AM2315/examples/AM2315_offset/AM2315_offset.ino index fcfea0a7..dd6f4959 100644 --- a/libraries/AM2315/examples/AM2315_offset/AM2315_offset.ino +++ b/libraries/AM2315/examples/AM2315_offset/AM2315_offset.ino @@ -2,7 +2,6 @@ // FILE: AM2315_offset.ino // AUTHOR: Rob Tillaart // PURPOSE: Demo for AM2315 I2C humidity & temperature sensor -// #include "AM2315.h" @@ -14,13 +13,23 @@ AM2315 sensor(&Wire); void setup() { Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); Serial.print("AM2315_LIB_VERSION: "); Serial.println(AM2315_LIB_VERSION); Serial.println(); - sensor.begin(); - // adjust your offsets if needed + Wire.begin(); + // Wire.setClock(100000); + + while (sensor.begin() == false) + { + Serial.print(millis()); + Serial.println("\tCould not connect to sensor."); + delay(1000); + } + + // adjust your offsets if needed sensor.setTempOffset(-0.8); sensor.setHumOffset(1.2); @@ -32,7 +41,6 @@ void setup() delay(2000); - Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)"); delay(100); } diff --git a/libraries/AM2315/examples/AM2315_performance/AM2315_performance.ino b/libraries/AM2315/examples/AM2315_performance/AM2315_performance.ino index 4e09a504..0e5f1b1c 100644 --- a/libraries/AM2315/examples/AM2315_performance/AM2315_performance.ino +++ b/libraries/AM2315/examples/AM2315_performance/AM2315_performance.ino @@ -13,19 +13,23 @@ AM2315 sensor; void setup() { - sensor.begin(); - // adjust your offsets if needed - // sensor.setTempOffset(-0.8); - // sensor.setHumOffset(1.2); - - // Wire.setClock(100000); - Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); Serial.print("AM2315_LIB_VERSION: "); Serial.println(AM2315_LIB_VERSION); Serial.println(); + Wire.begin(); + // Wire.setClock(100000); + + while (sensor.begin() == false) + { + Serial.print(millis()); + Serial.println("\tCould not connect to sensor."); + delay(1000); + } + delay(2000); Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C), \t micros"); diff --git a/libraries/AM2315/examples/AM2315_test/AM2315_test.ino b/libraries/AM2315/examples/AM2315_test/AM2315_test.ino index 2bd58f13..95b8860a 100644 --- a/libraries/AM2315/examples/AM2315_test/AM2315_test.ino +++ b/libraries/AM2315/examples/AM2315_test/AM2315_test.ino @@ -13,17 +13,22 @@ AM2315 sensor(&Wire); void setup() { - sensor.begin(); - // adjust your offsets if needed - // sensor.setTempOffset(-0.8); - // sensor.setHumOffset(1.2); - Serial.begin(115200); + Serial.println(); Serial.println(__FILE__); Serial.print("AM2315_LIB_VERSION: "); Serial.println(AM2315_LIB_VERSION); Serial.println(); + Wire.begin(); + + while (sensor.begin() == false) + { + Serial.print(millis()); + Serial.println("\tCould not connect to sensor."); + delay(1000); + } + delay(2000); Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)"); diff --git a/libraries/AM2315/library.json b/libraries/AM2315/library.json index 1603c009..3245bedc 100644 --- a/libraries/AM2315/library.json +++ b/libraries/AM2315/library.json @@ -15,9 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/AM2315.git" }, - "version": "0.1.7", + "version": "0.2.0", "license": "MIT", - "frameworks": "arduino", + "frameworks": "*", "platforms": "*", "headers": "AM2315.h" } diff --git a/libraries/AM2315/library.properties b/libraries/AM2315/library.properties index 66ba04fe..3e6d1618 100644 --- a/libraries/AM2315/library.properties +++ b/libraries/AM2315/library.properties @@ -1,5 +1,5 @@ name=AM2315 -version=0.1.7 +version=0.2.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for I2C AM2315 temperature and humidity sensor. diff --git a/libraries/AM2315/test/unit_test_001.cpp b/libraries/AM2315/test/unit_test_001.cpp index b2df568f..fa90d6ba 100644 --- a/libraries/AM2315/test/unit_test_001.cpp +++ b/libraries/AM2315/test/unit_test_001.cpp @@ -63,7 +63,9 @@ unittest(test_constructor) assertEqualFloat(0, sensor.getTempOffset(), 0.001); assertEqualFloat(0, sensor.getHumOffset(), 0.001); + Wire.begin(); sensor.begin(); + assertEqual(AM2315_WAITING_FOR_READ, sensor.read()); assertEqualFloat(0, sensor.getTemperature(), 0.001); @@ -75,8 +77,7 @@ unittest(test_constructor) unittest(test_offset) { - AM2315 sensor(&Wire); - sensor.begin(); + AM2315 sensor; // default Wire assertEqualFloat(0, sensor.getTempOffset(), 0.001); assertEqualFloat(0, sensor.getHumOffset(), 0.001);