0.5.1 AM232X

This commit is contained in:
Rob Tillaart 2024-04-05 10:40:16 +02:00
parent 8fcd95e523
commit 1df73f732a
17 changed files with 176 additions and 57 deletions

View File

@ -1,4 +1,5 @@
# These are supported funding model platforms
github: RobTillaart
github: RobTillaart
custom: "https://www.paypal.me/robtillaart"

View File

@ -5,8 +5,9 @@ on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update

View File

@ -1,4 +1,4 @@
---
name: Arduino CI
on: [push, pull_request]
@ -6,12 +6,13 @@ on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb
arduino_ci.rb

View File

@ -9,10 +9,11 @@ on:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
uses: limitusus/json-syntax-check@v2
with:
pattern: "\\.json$"

View File

@ -1,7 +1,7 @@
//
// FILE: AM232X.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.5.0
// VERSION: 0.5.1
// PURPOSE: AM232X library for AM2320 for Arduino.
// URL: https://github.com/RobTillaart/AM232X
@ -60,7 +60,7 @@ int AM232X::read()
}
_lastRead = millis();
// READ HUMIDITY AND TEMPERATURE REGISTERS
// READ HUMIDITY AND TEMPERATURE REGISTERS
int rv = _readRegister(0x00, 4);
if (rv < 0) return rv;
@ -71,7 +71,7 @@ int AM232X::read()
_humidity = AM232X_INVALID_VALUE;
_temperature = AM232X_INVALID_VALUE;
}
return rv; // propagate error value
return rv; // propagate error value
}
// EXTRACT HUMIDITY AND TEMPERATURE
@ -79,7 +79,7 @@ int AM232X::read()
int16_t t = ((_bits[4] & 0x7F) * 256 + _bits[5]);
if (t == 0)
{
_temperature = 0.0; // prevent -0.0;
_temperature = 0.0; // prevent -0.0;
}
else
{
@ -91,7 +91,7 @@ int AM232X::read()
}
#ifdef AM232X_VALUE_OUT_OF_RANGE
// TEST OUT OF RANGE
// TEST OUT OF RANGE
if (_humidity > 100)
{
return AM232X_HUMIDITY_OUT_OF_RANGE;
@ -127,7 +127,7 @@ void AM232X::setReadDelay(uint16_t readDelay)
_readDelay = readDelay;
if (_readDelay == 0)
{
_readDelay = 2000; // reset
_readDelay = 2000; // reset
}
};
@ -218,17 +218,17 @@ int AM232X::setUserRegisterB(int value)
////////////////////////////////////////////////////////////////////
//
// PROTECTED
// PROTECTED
//
int AM232X::_readRegister(uint8_t reg, uint8_t count)
{
// HANDLE PENDING IRQ
// HANDLE PENDING IRQ
yield();
// WAKE UP the sensor
// WAKE UP the sensor
if (! wakeUp() ) return AM232X_ERROR_CONNECT;
// request the data
// request the data
_wire->beginTransmission(AM232X_ADDRESS);
_wire->write(0x03);
_wire->write(reg);
@ -236,22 +236,22 @@ int AM232X::_readRegister(uint8_t reg, uint8_t count)
int rv = _wire->endTransmission();
if (rv < 0) return rv;
// request 4 extra, 2 for cmd + 2 for CRC
// request 4 extra, 2 for command + 2 for CRC
rv = _getData(count + 4);
return rv;
}
int AM232X::_writeRegister(uint8_t reg, uint8_t cnt, int16_t value)
int AM232X::_writeRegister(uint8_t reg, uint8_t count, int16_t value)
{
if (! wakeUp() ) return AM232X_ERROR_CONNECT;
// prepare data to send
// prepare data to send
_bits[0] = 0x10;
_bits[1] = reg;
_bits[2] = cnt;
_bits[2] = count;
if (cnt == 2)
if (count == 2)
{
_bits[4] = value & 0xFF;
_bits[3] = (value >> 8) & 0xFF;
@ -261,8 +261,8 @@ int AM232X::_writeRegister(uint8_t reg, uint8_t cnt, int16_t value)
_bits[3] = value & 0xFF;
}
// send data
uint8_t length = cnt + 3; // 3 = cmd, startReg, #bytes
// send data
uint8_t length = count + 3; // 3 = command, startReg, #bytes
_wire->beginTransmission(AM232X_ADDRESS);
for (int i = 0; i < length; i++)
{
@ -320,10 +320,10 @@ int AM232X::_getData(uint8_t length)
}
uint16_t AM232X::_crc16(uint8_t *ptr, uint8_t len)
uint16_t AM232X::_crc16(uint8_t *ptr, uint8_t length)
{
uint16_t crc = 0xFFFF;
while(len--)
while(length--)
{
crc ^= *ptr++;
for (uint8_t i = 0; i < 8; i++)

View File

@ -3,7 +3,7 @@
// FILE: AM232X.h
// AUTHOR: Rob Tillaart
// PURPOSE: AM232X Temperature and Humidity sensor library for Arduino
// VERSION: 0.5.0
// VERSION: 0.5.1
// URL: https://github.com/RobTillaart/AM232X
//
// AM232X PIN layout AM2315 COLOR
@ -16,14 +16,14 @@
// |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 "Arduino.h"
#include "Wire.h"
#define AM232X_LIB_VERSION (F("0.5.0"))
#define AM232X_LIB_VERSION (F("0.5.1"))
#define AM232X_OK 0
@ -100,8 +100,8 @@ public:
// might introduce under- or overflow at the ends of the sensor range
void setHumOffset(float offset = 0) { _humOffset = offset; };
void setTempOffset(float offset = 0) { _tempOffset = offset; };
float getHumOffset() { return _humOffset; };
float getTempOffset() { return _tempOffset; };
float getHumOffset() { return _humOffset; };
float getTempOffset() { return _tempOffset; };
// suppress error values of -999 => check return value of read() instead
bool getSuppressError() { return _suppressError; };
@ -109,8 +109,9 @@ public:
bool wakeUp() { return isConnected(); };
protected:
uint8_t _bits[8]; // buffer to hold raw data
uint8_t _bits[8]; // buffer to hold raw data
float _humidity = 0.0;
float _temperature = 0.0;
float _humOffset = 0.0;
@ -120,11 +121,11 @@ protected:
bool _suppressError = false;
int _readRegister(uint8_t reg, uint8_t cnt);
int _writeRegister(uint8_t reg, uint8_t cnt, int16_t value);
int _readRegister(uint8_t reg, uint8_t count);
int _writeRegister(uint8_t reg, uint8_t count, int16_t value);
int _getData(uint8_t length);
uint16_t _crc16(uint8_t *ptr, uint8_t len);
uint16_t _crc16(uint8_t *ptr, uint8_t length);
TwoWire* _wire;
};
@ -132,7 +133,7 @@ protected:
/////////////////////////////////////////////////////////////////////////////
//
// AM232X derived classes
// AM232X derived classes
//
class AM2320 : public AM232X
{
@ -155,8 +156,5 @@ public:
};
// -- END OF FILE --

View File

@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.5.1] - 2024-04-04
- update GitHub actions
- minor edits
## [0.5.0] - 2023-10-15
- simplify begin
- update readme.md

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017-2023 Rob Tillaart
Copyright (c) 2017-2024 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -13,7 +13,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"
@ -44,7 +44,7 @@ void setup()
void loop()
{
// READ DATA
// READ DATA
Serial.print("AM2320, \t");
int status = AM2320.read();
switch (status)
@ -57,7 +57,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);
@ -66,4 +66,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -39,7 +39,7 @@ void setup()
I2C_IMU.begin();
I2C_DHT.begin(pd_sda_dht, pd_scl_dht, 100000ul);
if (! AM2320.begin() )
{
Serial.println("Sensor not found");

View File

@ -13,7 +13,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"
@ -38,7 +38,7 @@ void setup()
AM2320.wakeUp();
delay(2000);
// sensor only returns one decimal.
// sensor only returns one decimal.
Serial.println();
Serial.println("Read:\t");
@ -112,4 +112,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -13,7 +13,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"
@ -44,7 +44,7 @@ void setup()
void loop()
{
// READ DATA
// READ DATA
Serial.print("AM2322, \t");
int status = AM2322.read();
switch (status)
@ -57,7 +57,7 @@ void loop()
Serial.print("\t");
break;
}
// DISPLAY DATA, sensor only returns one decimal.
// DISPLAY DATA, sensor only returns one decimal.
Serial.print(AM2322.getHumidity(), 1);
Serial.print(",\t");
Serial.println(AM2322.getTemperature(), 1);
@ -66,4 +66,4 @@ void loop()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -28,7 +28,7 @@ void setup()
// Serial.print("LIBRARY VERSION: ");
// Serial.println(AM232X_LIB_VERSION);
// Serial.println();
Wire.begin();
if (! AM2322.begin() )
{

View File

@ -0,0 +1,30 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico
libraries:
- "AM232X"
- "TCA9548"

View File

@ -0,0 +1,82 @@
//
// FILE: TCA9548_demo_AM2320.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo TCA9548 I2C multiplexer
// URL: https://github.com/RobTillaart/TCA9548
#include "AM232X.h"
#include "TCA9548.h"
PCA9546 MP(0x70);
uint8_t channels = 0;
AM232X living; // channel 0
AM232X kitchen; // channel 1
AM232X outside; // channel 2
uint32_t lastTime = 0;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("TCA9548_LIB_VERSION: ");
Serial.println(TCA9548_LIB_VERSION);
Serial.print("AM232X_LIB_VERSION: ");
Serial.println(AM232X_LIB_VERSION);
Serial.println();
Wire.begin();
// initialize multiplexer
if (MP.begin() == false)
{
Serial.println("Multiplexer error");
}
channels = MP.channelCount();
// initialize the temperature sensors
MP.selectChannel(0);
if (living.begin() == false)
{
Serial.println("living error");
}
MP.selectChannel(1);
if (kitchen.begin() == false )
{
Serial.println("kitchen error");
}
MP.selectChannel(2);
if (outside.begin() == false )
{
Serial.println("outside error");
}
}
void loop()
{
if ((millis() - lastTime) > 5000)
{
lastTime = millis();
MP.selectChannel(0);
living.read();
Serial.print(living.getTemperature(), 1);
Serial.print("\t");
MP.selectChannel(1);
kitchen.read();
Serial.print(kitchen.getTemperature(), 1);
Serial.print("\t");
MP.selectChannel(2);
outside.read();
Serial.print(outside.getTemperature(), 1);
Serial.print("\n");
}
}
// -- END OF FILE --

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AM232X"
},
"version": "0.5.0",
"version": "0.5.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,9 +1,9 @@
name=AM232X
version=0.5.0
version=0.5.1
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.
paragraph=Supports AM2320, AM3231, AM2322. These sensors are similar to DHT12 with I2C interface.
sentence=Arduino library for AM2320 AM2321 and AM2323 I2C temperature and humidity sensor.
paragraph=Supports AM2320, AM3231, AM2322. These sensors are similar to DHT12 with I2C interface.
category=Sensors
url=https://github.com/RobTillaart/AM232X
architectures=*