0.2.0 AM2315

This commit is contained in:
Rob Tillaart 2023-10-15 14:17:19 +02:00
parent 5260829a02
commit 999991ea2b
10 changed files with 71 additions and 58 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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

View File

@ -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,

View File

@ -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);
}

View File

@ -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");

View File

@ -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)");

View File

@ -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"
}

View File

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

View File

@ -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);