0.1.5 AM2315

This commit is contained in:
rob tillaart 2022-08-31 09:24:41 +02:00
parent 535e6db838
commit a409622a75
7 changed files with 23 additions and 17 deletions

View File

@ -7,5 +7,5 @@ compile:
# - leonardo
- m4
- esp32
# - esp8266
- esp8266
# - mega2560

View File

@ -1,7 +1,7 @@
//
// FILE: AM2315.cpp
// AUTHOR: Rob.Tillaart@gmail.com
// VERSION: 0.1.4
// VERSION: 0.1.5
// PURPOSE: AM2315 Temperature and Humidity sensor library for Arduino
// URL: https://github.com/RobTillaart/AM2315
//
@ -11,6 +11,7 @@
// 0.1.2 2022-01-13 fix wake-up in read() for ESP32.
// 0.1.3 2022-06-17 sync with AM232X
// 0.1.4 2022-06-18 sync with AM232X (readme)
// 0.1.5 2022-08-31 fix #11 Warning requestFrom for ESP32
#include "AM2315.h"
@ -196,7 +197,7 @@ int AM2315::_readSensor()
// REQUEST DATA
const int length = 8;
int bytes = _wire->requestFrom(AM2315_ADDRESS, length);
int bytes = _wire->requestFrom((int)AM2315_ADDRESS, length);
if (bytes == 0) return AM2315_ERROR_CONNECT;
if (bytes < length) return AM2315_MISSING_BYTES;

View File

@ -3,7 +3,7 @@
// FILE: AM2315.h
// AUTHOR: Rob Tillaart
// PURPOSE: AM2315 Temperature and Humidity sensor library for Arduino
// VERSION: 0.1.4
// VERSION: 0.1.5
// 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.4"))
#define AM2315_LIB_VERSION (F("0.1.5"))
#define AM2315_OK 0

View File

@ -19,7 +19,8 @@ the AM2315 has a fixed address **0x5C** so one need to implement a
multiplexing strategy to have multiple sensors in practice.
See multiplexing below.
The AM2315 can also be read with the https://github.com/RobTillaart/AM232X library as it uses the same protocol. The AM232X library allows to read some internal registers.
The AM2315 can also be read with the https://github.com/RobTillaart/AM232X library as it uses the same protocol.
The AM232X library allows to read some internal registers.
#### Typical parameters
@ -121,7 +122,8 @@ Functions to adjust the communication with the sensor.
- **bool getWaitForReading()** returns the above setting.
- **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 **AM2315_INVALID_VALUE** == -999 => you need to check the return value of read() instead.
- **void setSuppressError(bool b)** suppress error values of **AM2315_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.
@ -140,23 +142,27 @@ This can be used to keep spikes out of your graphs / logs.
| AM2315_TEMPERATURE_OUT_OF_RANGE | -101 | not used by default.
| AM2315_INVALID_VALUE | -999 | can be suppressed.
Note: The OUT_OT_RANGE errors are tested on the "raw" readings, excluding the offset.
So if the "raw" humidity is 99% and you use an offset of 3% you will get 102%
without the error.
## Operation
See examples
In **setup()** you have to call the **begin()** to initialize
the Wire library and do an initial **read()** to fill the variables temperature and humidity.
To access these values one must use **getTemperature()** and **getHumidity()**.
In **setup()** you must call the **begin()** to initialize the Wire library used
and do an initial **read()** to fill the variables temperature and humidity.
To access these values use **getTemperature()** and **getHumidity()**.
Multiple calls will give the same values until **read()** is called again.
Note that the sensor can go into sleep mode after 3 seconds after last read,
Note that the AM2315 can go into sleep mode after 3 seconds after last read,
so one might need to call **wakeUp()** before the **read()**.
## Multiplexing
Multiplexing the **AM232X** can be done in several ways.
Multiplexing the **AM2315** can be done in several ways.
This is not a complete list or tutorial but should get you started.
1. Control the power line by means of an extra pin (+ transistor).
@ -166,7 +172,7 @@ the sensor takes to boot and to be ready for the first measurement.
pin of the sensors. This way one can enable / disable communication
per sensor. This will still need an IO pin per sensor but does not
have the "boot time" constraint mentioned above.
you may use a **PCF8574** to control the AND gates.
You may use a **PCF8574** to control the AND gates.
https://github.com/RobTillaart/PCF8574
3. Use a **TCA9548A** I2C Multiplexer, or similar. https://github.com/RobTillaart/TCA9548
@ -177,7 +183,7 @@ Which method fit your application depends on your requirements and constraints.
- update documentation
- test more (other platforms)
- keep in sync with AM2315 class
- keep in sync with AM232X class
- merge in a far future.
- update unit test
- add examples

View File

@ -38,7 +38,6 @@ void loop()
if (millis() - sensor.lastRead() >= 2000)
{
// READ DATA
uint32_t start = micros();
int status = sensor.read();
uint32_t stop = micros();

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AM2315.git"
},
"version": "0.1.4",
"version": "0.1.5",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=AM2315
version=0.1.4
version=0.1.5
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for I2C AM2315 temperature and humidity sensor.