Add support for AM2320 Temperature and Humidity Sensor by Lars Wessels (#12485)

This commit is contained in:
Theo Arends 2021-06-27 13:53:19 +02:00
parent cf7da3dab2
commit 464ab2cb6b
8 changed files with 31 additions and 24 deletions

View File

@ -157,6 +157,7 @@ m = minimal, l = lite, t = tasmota, k = knx, s = sensors, i = ir, d = display
| USE_EZORTD | - | - | - / - | - | - | - | - |
| USE_SEESAW_SOIL | - | - | - / - | - | - | - | - |
| USE_TOF10120 | - | - | - / - | - | - | - | - |
| USE_AM2320 | - | - | - / - | - | - | - | - |
| | | | | | | | |
| Feature or Sensor | m | l | t | k | s | i | d | Remarks
| USE_SPI | - | - | - / - | - | - | - | x |

View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
## [9.5.0.1]
### Added
- Enable UFILESYS, GUI_TRASH_FILE and GUI_EDIT_FILE for any device compiled with more than 1M flash size
- Support for AM2320 Temperature and Humidity Sensor by Lars Wessels (#12485)
### Changed
- ESP32 core library from v1.0.6 to v1.0.7

View File

@ -92,4 +92,5 @@ Index | Define | Driver | Device | Address(es) | Description
56 | USE_SEESAW_SOIL | xsns_81 | SEESOIL | 0x36 - 0x39 | Adafruit seesaw soil moisture sensor
57 | USE_TOF10120 | xsns_84 | TOF10120 | 0x52 | Time-of-flight (ToF) distance sensor
58 | USE_MPU_ACCEL | xsns_85 | MPU_ACCEL| 0x68 | MPU6886/MPU9250 6-axis MotionTracking sensor from M5Stack
59 | USE_BM8563 | xdrv_56 | BM8563 | 0x51 | BM8563 RTC from M5Stack
59 | USE_BM8563 | xdrv_56 | BM8563 | 0x51 | BM8563 RTC from M5Stack
60 | USE_AM2320 | xsns_88 | AM2320 | 0x5C | Temperature and Humidity sensor

View File

@ -98,6 +98,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
## Changelog v9.5.0.1
### Added
- Enable UFILESYS, GUI_TRASH_FILE and GUI_EDIT_FILE for any device compiled with more than 1M flash size
- Support for AM2320 Temperature and Humidity Sensor by Lars Wessels [#12485](https://github.com/arendst/Tasmota/issues/12485)
### Changed
- ESP32 core library from v1.0.6 to v1.0.7

View File

@ -632,7 +632,7 @@
// #define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code)
// #define USE_MPU_ACCEL // [I2cDriver58] Enable MPU6886/MPU9250 - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x68) (+2k code)
// #define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2.5k code)
// #define USE_AM2320 // [I2cDriver60] Enable AM2320 temperature and humidity Sensor (I2C address 0x5C)()
// #define USE_AM2320 // [I2cDriver60] Enable AM2320 temperature and humidity Sensor (I2C address 0x5C) (+1k code)
// #define USE_DISPLAY // Add I2C Display Support (+2k code)
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0
#define USE_DISPLAY_LCD // [DisplayModel 1] [I2cDriver3] Enable Lcd display (I2C addresses 0x27 and 0x3F) (+6k code)
@ -778,7 +778,7 @@
// -- IR Remote features - all protocols from IRremoteESP8266 --------------------------
// IR Full Protocols mode is now activated through USE_IR_REMOTE_FULL
//
//
// Code impact of IR full protocols is +90k code, 3k mem
// -- IR Remote features - subset of IR protocols --------------------------

View File

@ -725,7 +725,7 @@ void ResponseAppendFeatures(void)
static uint32_t feature8 = 0x00000000;
if (!feature8) { // Only fill this once
#if defined(USE_I2C) && defined(USE_MPU6886)
#if defined(USE_I2C) && defined(USE_MPU_ACCEL)
feature8 |= 0x00000001; // xsns_85_mpu6886.ino
#endif
#ifdef USE_TFMINIPLUS
@ -737,11 +737,15 @@ void ResponseAppendFeatures(void)
#ifdef USE_BERRY
feature8 |= 0x00000008; // xdrv_52_9_berry.ino
#endif
// feature8 |= 0x00000010;
#if defined(USE_I2C) && defined(USE_BM8563)
feature8 |= 0x00000010;
#endif
#if defined(USE_ENERGY_SENSOR) && defined(USE_ENERGY_DUMMY)
feature8 |= 0x00000020;
#endif
// feature8 |= 0x00000040;
#if defined(USE_I2C) && defined(USE_AM2320)
feature8 |= 0x00000040;
#endif
// feature8 |= 0x00000080;
// feature8 |= 0x00000100;

View File

@ -1,7 +1,7 @@
/*
xsns_88_am2320.ino - Tasmota driver for I2C AM2320 Temp/Hum Sensor
xsns_88_am2320.ino - I2C AM2320 Temp/Hum Sensor for Tasmota
Copyright (C) 2019 Lars Wessels
Copyright (C) 2021 Lars Wessels
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -19,7 +19,6 @@
#ifdef USE_I2C
#ifdef USE_AM2320
/*********************************************************************************************\
* AM2320 - Digital Temperature and Humidity Sensor
* https://akizukidenshi.com/download/ds/aosong/AM2320.pdf
@ -33,7 +32,7 @@
#define XI2C_60 60 // See I2CDEVICES.md
#define AM2320_ADDR 0x5C // use 7bit address: 0xB8 >> 1
#define INIT_MAX_RETRIES 5
#define INIT_MAX_RETRIES 5
char AM2320_types[] = "AM2320";
@ -47,7 +46,7 @@ struct AM2320_Readings {
bool Am2320Init(void)
{
// wake AM2320 up, goes to sleep to not warm up and affect the humidity sensor
// wake AM2320 up, goes to sleep to not warm up and affect the humidity sensor
Wire.beginTransmission(AM2320_ADDR);
Wire.write(0x02);
Wire.endTransmission();
@ -95,9 +94,9 @@ bool Am2320Read(void)
if (Wire.available() != 8) { return false; }
// read 8 bytes: preamble(2) + data(2) + crc(2)
memset(buf, 0, 8);
for (uint8_t i = 0; i < 8; i++) {
buf[i] = Wire.read();
memset(buf, 0, 8);
for (uint8_t i = 0; i < 8; i++) {
buf[i] = Wire.read();
}
if (buf[0] != 0x03) { return false; } // must be 0x03 function code reply
@ -109,14 +108,14 @@ bool Am2320Read(void)
int temperature = ((buf[4] & 0x7F) << 8) | buf[5];
AM2320.t = temperature / 10.0;
// check for negative temp reading
AM2320.t = ((buf[4] & 0x80) >> 7) == 1 ? AM2320.t * (-1) : AM2320.t;
AM2320.t = ((buf[4] & 0x80) >> 7) == 1 ? AM2320.t * (-1) : AM2320.t;
int humidity = (buf[2] << 8) | buf[3];
AM2320.h = humidity / 10.0;
AM2320.valid = SENSOR_MAX_MISS; // reset error counter
return true;
} else {
AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_I2C "Am2320Read() checksum failed"));
return false;
@ -125,7 +124,7 @@ bool Am2320Read(void)
void Am2320Detect(void)
{
{
if (Am2320Init()) {
if (!am2320_found) {
AddLog(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, AM2320_types, AM2320_ADDR);
@ -140,8 +139,8 @@ void Am2320Detect(void)
void Am2320EverySecond(void)
{
// if (!(uptime%10)) {
{
// if (!(uptime%10)) {
// Am2320Detect(); // look for sensor every 10 seconds, after three misses it's set to not found
// } else if (uptime & 1 && am2320_found) { // read from sensor every 2 seconds
if (TasmotaGlobal.uptime &1) {
@ -194,7 +193,7 @@ void Am2320Show(bool json)
* Interface
\*********************************************************************************************/
bool Xsns92(uint8_t function)
bool Xsns88(uint8_t function)
{
if (!I2cEnabled(XI2C_60)) { return false; }

View File

@ -252,8 +252,8 @@ a_features = [[
"USE_BS814A2","USE_SEESAW_SOIL","USE_WIEGAND","USE_NEOPOOL",
"USE_TOF10120","USE_SDM72","USE_DISPLAY_TM1637","USE_PROJECTOR_CTRL"
],[
"USE_MPU6886","USE_TFMINIPLUS","USE_CSE7761","USE_BERRY",
"USE_HALLEFFECT","USE_ENERGY_DUMMY","","",
"USE_MPU_ACCEL","USE_TFMINIPLUS","USE_CSE7761","USE_BERRY",
"USE_BM8563","USE_ENERGY_DUMMY","USE_AM2320","",
"","","","",
"","","","",
"","","","",
@ -287,7 +287,7 @@ else:
obj = json.load(fp)
def StartDecode():
print ("\n*** decode-status.py v20210406 by Theo Arends and Jacek Ziolkowski ***")
print ("\n*** decode-status.py v20210627 by Theo Arends and Jacek Ziolkowski ***")
# print("Decoding\n{}".format(obj))