mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.5.0 AM232X
This commit is contained in:
parent
d2ea84004d
commit
3e39d77414
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@ void setup()
|
||||
Serial.println(AM232X_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
if (! AM2320.begin() )
|
||||
{
|
||||
Serial.println("Sensor not found");
|
||||
|
@ -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");
|
||||
|
@ -29,6 +29,7 @@ void setup()
|
||||
Serial.println(AM232X_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
if (! AM2320.begin() )
|
||||
{
|
||||
Serial.println("Sensor not found");
|
||||
|
@ -29,6 +29,7 @@ void setup()
|
||||
Serial.println(AM232X_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
if (! AM2322.begin() )
|
||||
{
|
||||
Serial.println("Sensor not found");
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -173,4 +173,6 @@ unittest(test_AM232X_surpress_error)
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user