0.5.0 AM232X

This commit is contained in:
Rob Tillaart 2023-10-16 15:42:56 +02:00
parent d2ea84004d
commit 3e39d77414
13 changed files with 88 additions and 64 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: AM232X.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.4.5
// VERSION: 0.5.0
// PURPOSE: AM232X library for AM2320 for Arduino.
// URL: https://github.com/RobTillaart/AM232X
@ -30,25 +30,8 @@ AM232X::AM232X(TwoWire *wire)
}
#if defined (ESP8266) || defined(ESP32)
bool AM232X::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 AM232X::begin()
{
_wire->begin();
if (! isConnected()) return false;
this->read();
return true;
@ -139,9 +122,9 @@ float AM232X::getTemperature()
}
void AM232X::setReadDelay(uint16_t rd)
void AM232X::setReadDelay(uint16_t readDelay)
{
_readDelay = rd;
_readDelay = readDelay;
if (_readDelay == 0)
{
_readDelay = 2000; // reset

View File

@ -3,7 +3,7 @@
// FILE: AM232X.h
// AUTHOR: Rob Tillaart
// PURPOSE: AM232X Temperature and Humidity sensor library for Arduino
// VERSION: 0.4.5
// VERSION: 0.5.0
// URL: https://github.com/RobTillaart/AM232X
//
// AM232X PIN layout AM2315 COLOR
@ -23,7 +23,7 @@
#include "Wire.h"
#define AM232X_LIB_VERSION (F("0.4.5"))
#define AM232X_LIB_VERSION (F("0.5.0"))
#define AM232X_OK 0
@ -68,9 +68,6 @@ class AM232X
public:
explicit AM232X(TwoWire *wire = &Wire);
#if defined(ESP8266) || defined(ESP32)
bool begin(const uint8_t dataPin, const uint8_t clockPin);
#endif
bool begin();
// datasheet 8.2 - wake up is min 800 us max 3000 us
bool isConnected(uint16_t timeout = 3000);
@ -81,7 +78,7 @@ public:
// set readDelay to 0 will reset to datasheet values
uint16_t getReadDelay() { return _readDelay; };
void setReadDelay(uint16_t rd = 0);
void setReadDelay(uint16_t readDelay = 0);
// negative return values are errors
int getModel();

View File

@ -6,13 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.5.0] - 2023-10-15
- simplify begin
- update readme.md
- update keywords.txt (align .h file)
- minor edits
----
## [0.4.5] - 2023-01-12
- update GitHub actions
- update license
- update readme.md (oneWire section)
- fix version in AM232X.cpp
## [0.4.4] - 2022-10-12
- Add RP2040 support to build-CI.
- Add CHANGELOG.md

View File

@ -2,8 +2,11 @@
[![Arduino CI](https://github.com/RobTillaart/AM232X/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/AM232X/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AM232X/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/AM232X/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AM232X/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AM232X.svg)](https://github.com/RobTillaart/AM232X/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AM232X/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AM232X.svg?maxAge=3600)](https://github.com/RobTillaart/AM232X/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AM232X.svg)](https://registry.platformio.org/libraries/robtillaart/AM232X)
# AM232X
@ -70,17 +73,20 @@ file the issues under DHTNew.
## Interface
```cpp
#include "AM232X.h"
```
Since 0.4.2 the library provides specific classes for the AM2320, AM2321 and AM2322 which have the same interface.
#### Constructor
- **AM232X(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.
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.
- **AM232X(TwoWire \*wire = &Wire)** constructor, default using Wire (I2C bus),
optionally set to Wire0 .. WireN.
- **bool begin()** initializer for class.
Returns true if fixed device address 0x5C is connected.
- **bool isConnected(uint16_t timeout = 3000)** returns true if the fixed 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.
minimum = 800 us and maximum = 3000 us according to datasheet.
@ -101,26 +107,27 @@ This error can be suppressed, see below.
#### Offset
- **void setHumOffset(float offset = 0)** set an offset for humidity to calibrate (1st order) the sensor.
Default offset = 0, so no parameter will reset the offset.
- **float getHumOffset()** return current humidity offset, default 0.
Default offset = 0, so no parameter will reset the offset to 0.
- **float getHumOffset()** return the current humidity offset, default 0.
- **void setTempOffset(float offset = 0)** set an offset for temperature to calibrate (1st order) the sensor.
Default offset = 0, so no parameter will reset the offset.
- **float getTempOffset()** return current temperature offset, default 0.
Default offset = 0, so no parameter will reset the offset to 0.
- **float getTempOffset()** return the current temperature offset, default 0.
#### Control
Functions to adjust the communication with the sensor.
- **void setReadDelay(uint16_t rd = 0)** Tunes the time it waits before actual read can be done.
- **void setReadDelay(uint16_t readDelay = 0)** Tunes the time it waits before actual read can be done.
Set readDelay to 0 will reset it to 2000 ms effective the next **read()**.
- **uint16_t getReadDelay()** returns the above setting.
- **uint16_t getReadDelay()** returns the current readDelay in milliseconds.
Note that a value of zero (reset) will return 0 before the call and 2000 after the call to **read()**.
- **bool wakeUp()** function that will try for 3 milliseconds to wake up the sensor.
This can be done before an actual read to minimize the **read()** call.
- **void setSuppressError(bool b)** suppress error values of **AM232X_INVALID_VALUE** == -999 => you need to check the return value of read() instead.
- **void setSuppressError(bool b)** suppress error values of **AM232X_INVALID_VALUE** == -999.
=> you need to check the return value of read() instead.
This can be used to keep spikes out of your graphs / logs.
- **bool getSuppressError()** returns the above setting.
- **bool getSuppressError()** returns the current suppression setting.
#### Metadata
@ -217,3 +224,15 @@ Which method fit your application depends on your requirements and constraints.
- clock speed > 170 - see AM2315
#### Wont
## 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,

View File

@ -29,6 +29,7 @@ void setup()
Serial.println(AM232X_LIB_VERSION);
Serial.println();
Wire.begin();
if (! AM2320.begin() )
{
Serial.println("Sensor not found");

View File

@ -14,7 +14,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"
@ -22,11 +22,11 @@
#define pd_scl_dht 14
#define pd_sda_dht 27
TwoWire I2CIMU = TwoWire(0); // I2C1 bus
TwoWire I2CDHT = TwoWire(1); // I2C2 bus
TwoWire I2C_IMU = TwoWire(0); // I2C1 bus
TwoWire I2C_DHT = TwoWire(1); // I2C2 bus
AM232X AM2320(&I2CDHT);
AM232X AM2320(&I2C_DHT);
void setup()
@ -37,7 +37,9 @@ void setup()
Serial.println(AM232X_LIB_VERSION);
Serial.println();
I2CDHT.begin(pd_sda_dht, pd_scl_dht, 100000ul);
I2C_IMU.begin();
I2C_DHT.begin(pd_sda_dht, pd_scl_dht, 100000ul);
if (! AM2320.begin() )
{
Serial.println("Sensor not found");
@ -52,7 +54,7 @@ void setup()
void loop()
{
// READ DATA
// READ DATA
Serial.print("AM2320, \t");
int status = AM2320.read();
switch (status)
@ -65,7 +67,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);
@ -74,4 +76,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -29,6 +29,7 @@ void setup()
Serial.println(AM232X_LIB_VERSION);
Serial.println();
Wire.begin();
if (! AM2320.begin() )
{
Serial.println("Sensor not found");

View File

@ -29,6 +29,7 @@ void setup()
Serial.println(AM232X_LIB_VERSION);
Serial.println();
Wire.begin();
if (! AM2322.begin() )
{
Serial.println("Sensor not found");

View File

@ -24,7 +24,12 @@ AM232X AM2322;
void setup()
{
Serial.begin(115200);
// Serial.println(__FILE__);
// Serial.print("LIBRARY VERSION: ");
// Serial.println(AM232X_LIB_VERSION);
// Serial.println();
Wire.begin();
if (! AM2322.begin() )
{
Serial.println("Sensor not found");

View File

@ -3,6 +3,9 @@
# Data types (KEYWORD1)
AM232X KEYWORD1
AM2320 KEYWORD1
AM2321 KEYWORD1
AM2322 KEYWORD1
# Methods and Functions (KEYWORD2)
@ -10,6 +13,11 @@ begin KEYWORD2
isConnected KEYWORD2
read KEYWORD2
lastRead KEYWORD2
getReadDelay KEYWORD2
setReadDelay KEYWORD2
getModel KEYWORD2
getVersion KEYWORD2
getDeviceID KEYWORD2
@ -24,20 +32,18 @@ setUserRegisterB KEYWORD2
getHumidity KEYWORD2
getTemperature KEYWORD2
wakeUp KEYWORD2
setHumOffset KEYWORD2
setTempOffset KEYWORD2
getHumOffset KEYWORD2
getTempOffset KEYWORD2
getReadDelay KEYWORD2
setReadDelay KEYWORD2
lastRead KEYWORD2
getSuppressError KEYWORD2
setSuppressError KEYWORD2
wakeUp KEYWORD2
# Constants (LITERAL1)
AM232X_LIB_VERSION LITERAL1

View File

@ -15,9 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/AM232X"
},
"version": "0.4.5",
"version": "0.5.0",
"license": "MIT",
"frameworks": "arduino",
"frameworks": "*",
"platforms": "*",
"headers": "AM232X.h"
}

View File

@ -1,5 +1,5 @@
name=AM232X
version=0.4.5
version=0.5.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for AM2320 AM2321 and AM2323 I2C temperature and humidity sensor.

View File

@ -65,7 +65,7 @@ unittest(test_AM232X_constructor)
assertTrue(AM.isConnected()); // TODO - GODMODE
assertEqual(0, AM.lastRead());
// assertEqual(-10, AM.read());
// assertEqual(-10, AM.read());
}
@ -98,7 +98,7 @@ unittest(test_AM232X_hum_temp)
assertEqualFloat(0, AM.getHumOffset(), 0.001);
AM.setHumOffset(1.5);
assertEqualFloat(1.5, AM.getHumOffset(), 0.001);
assertEqualFloat(0, AM.getTemperature(), 0.001);
assertEqualFloat(0, AM.getTempOffset(), 0.001);
AM.setTempOffset(-1.5);
@ -114,7 +114,7 @@ unittest(test_hum_AM2320_temp)
assertEqualFloat(0, AM.getHumOffset(), 0.001);
AM.setHumOffset(1.5);
assertEqualFloat(1.5, AM.getHumOffset(), 0.001);
assertEqualFloat(0, AM.getTemperature(), 0.001);
assertEqualFloat(0, AM.getTempOffset(), 0.001);
AM.setTempOffset(-1.5);
@ -130,7 +130,7 @@ unittest(test_hum_AM2321_temp)
assertEqualFloat(0, AM.getHumOffset(), 0.001);
AM.setHumOffset(1.5);
assertEqualFloat(1.5, AM.getHumOffset(), 0.001);
assertEqualFloat(0, AM.getTemperature(), 0.001);
assertEqualFloat(0, AM.getTempOffset(), 0.001);
AM.setTempOffset(-1.5);
@ -146,7 +146,7 @@ unittest(test_AM2322_hum_temp)
assertEqualFloat(0, AM.getHumOffset(), 0.001);
AM.setHumOffset(1.5);
assertEqualFloat(1.5, AM.getHumOffset(), 0.001);
assertEqualFloat(0, AM.getTemperature(), 0.001);
assertEqualFloat(0, AM.getTempOffset(), 0.001);
AM.setTempOffset(-1.5);
@ -173,4 +173,6 @@ unittest(test_AM232X_surpress_error)
unittest_main()
// --------
// -- END OF FILE --