diff --git a/CODE_OWNERS.md b/CODE_OWNERS.md index 49d7f6f53668..796f9e58ea70 100644 --- a/CODE_OWNERS.md +++ b/CODE_OWNERS.md @@ -208,6 +208,7 @@ In addition to @arendst the following code is mainly owned by: | xsns_106_gdk101 | @Szewcson | xsns_107_gm861 | @arendst | xsns_108_tc74 | Michael Loftis +| xsns_110_max17043 | Vincent de Groot | | | Libraries | | | diff --git a/I2CDEVICES.md b/I2CDEVICES.md index 2a51ad36c9fd..040c25469cf6 100644 --- a/I2CDEVICES.md +++ b/I2CDEVICES.md @@ -118,3 +118,4 @@ Index | Define | Driver | Device | Address(es) | Description 80 | USE_TC74 | xsns_108 | TC74 | 0x48 - 0x4F | Temperature sensor 81 | USE_PCA9557 | xdrv_69 | PCA95xx | 0x18 - 0x1F | 8-bit I/O expander as virtual button/switch/relay 82 | USE_SGP4X | xsns_109 | SGP4X | 0x59 | Gas (TVOC/NOx index) + 83 | USE_MAX17043 | xsns_110 | MAX17043 | 0x36 | Fuel-gauge for 3.7 Volt Lipo battery diff --git a/lib/lib_i2c/DFRobot_MAX17043/DFRobot_MAX17043.cpp b/lib/lib_i2c/DFRobot_MAX17043/DFRobot_MAX17043.cpp new file mode 100644 index 000000000000..b24f686af68c --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/DFRobot_MAX17043.cpp @@ -0,0 +1,68 @@ +/*! + * @file DFRobot_MAX17043.cpp + * + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @license The MIT License (MIT) + * @author [ouki.wang](ouki.wang@dfrobot.com) + * @version V1.0 + * @date 2018-4-14 + * @url https://github.com/DFRobot/DFRobot_MAX17043 + */ + +#include "DFRobot_MAX17043.h" + +DFRobot_MAX17043::DFRobot_MAX17043() {} + +int DFRobot_MAX17043::begin() +{ + // write16(MAX17043_COMMAND, 0x0054); //power on reset + write16(MAX17043_COMMAND, 0x5400); //power on reset + delay(10); + _DBG_CODE(Serial.print("\nbegin: ")); + _DBG_CODE(Serial.println(read16(MAX17043_CONFIG), HEX)); + if(read16(MAX17043_CONFIG) == 0x971c) { //default 0x971c + write16(MAX17043_MODE, 0x4000); //quick start + write16(MAX17043_CONFIG, 0x9700); + _DBG_CODE(Serial.println(read16(MAX17043_CONFIG), HEX)); + delay(10); + return 0; + } + return -1; +} + +float DFRobot_MAX17043::readVoltage() +{ + return (1.25f * (float)(read16(MAX17043_VCELL) >> 4)); +} + +float DFRobot_MAX17043::readPercentage() +{ + uint16_t per = read16(MAX17043_SOC); + return (float)((per >> 8) + 0.003906f * (per & 0x00ff)); +} + +void DFRobot_MAX17043::setInterrupt(uint8_t per) +{ + uint16_t temp; + if(per > 32) + temp = 32; + else if(per < 1) + temp = 1; + temp = 32 - temp; + writeRegBits(MAX17043_CONFIG, temp, 0x01f, 0); +} + +void DFRobot_MAX17043::clearInterrupt() +{ + writeRegBits(MAX17043_CONFIG, 0, 0x01, 5); +} + +void DFRobot_MAX17043::setSleep() +{ + writeRegBits(MAX17043_CONFIG, 1, 0x01, 7); +} + +void DFRobot_MAX17043::setWakeUp() +{ + writeRegBits(MAX17043_CONFIG, 0, 0x01, 7); +} diff --git a/lib/lib_i2c/DFRobot_MAX17043/DFRobot_MAX17043.h b/lib/lib_i2c/DFRobot_MAX17043/DFRobot_MAX17043.h new file mode 100644 index 000000000000..f4147ba6988c --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/DFRobot_MAX17043.h @@ -0,0 +1,121 @@ +/*! + * @file DFRobot_MAX17043.h + * + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @license The MIT License (MIT) + * @author [ouki.wang](ouki.wang@dfrobot.com) + * @version V1.0 + * @date 2018-4-14 + * @url https://github.com/DFRobot/DFRobot_MAX17043 + */ + +#ifndef __DFROBOT_MAX17043_H +#define __DFROBOT_MAX17043_H + +#include "Arduino.h" +#include "Wire.h" + +#define _DBG 0 + +#if(_DBG) + #define _DBG_CODE(x) x +#else + #define _DBG_CODE(x) +#endif + +#define MAX17043_ADDRESS 0x36 + +#define MAX17043_VCELL 0x02 +#define MAX17043_SOC 0x04 +#define MAX17043_MODE 0x06 +#define MAX17043_VERSION 0x08 +#define MAX17043_CONFIG 0x0c +#define MAX17043_COMMAND 0xfe + +class DFRobot_MAX17043 { +public: + /** + * @fn DFRobot_MAX17043 + * @brief create MAX17043 object + * @return MAX17043 object + */ + DFRobot_MAX17043(); + /** + * @fn begin + * @brief MAX17043 begin and test moudle + * + * @return initialization result + * @retval 0 successful + * @retval -1 faild + */ + int begin(); + /** + * @fn readVoltage + * @brief read battery voltage in mV + * @return voltage in mV + */ + float readVoltage(); + /** + * @fn readPercentage + * @brief read battery remaining capacity in percentage + * + * @return battery remaining capacity in percentage + */ + float readPercentage(); + /** + * @fn setInterrupt + * @brief set MAX17043 interrput threshold + * + * @param per interrupt threshold as %1 - 32% (integer) + */ + void setInterrupt(uint8_t per); + /** + * @fn clearInterrupt + * @brief clear MAX17043 interrupt + */ + void clearInterrupt(); + /** + * @fn setSleep + * @brief set MAX17043 in sleep mode + * + */ + void setSleep(); + /** + * @fn setWakeUp + * @brief weak up MAX17043 + * + */ + void setWakeUp(); + + private: + void write16(uint8_t reg, uint16_t dat) { + Wire.begin(); + Wire.beginTransmission(MAX17043_ADDRESS); + Wire.write(reg); + Wire.write(dat >> 8); + Wire.write(dat); + Wire.endTransmission(); + } + + uint16_t read16(uint8_t reg) { + uint16_t temp; + Wire.begin(); + Wire.beginTransmission(MAX17043_ADDRESS); + Wire.write(reg); + Wire.endTransmission(); + Wire.requestFrom(MAX17043_ADDRESS, 2); + temp = (uint16_t)Wire.read() << 8; + temp |= (uint16_t)Wire.read(); + Wire.endTransmission(); + return temp; + } + + void writeRegBits(uint8_t reg, uint16_t dat, uint16_t bits, uint8_t offset) { + uint16_t temp; + temp = read16(reg); + temp = (temp & (~(bits << offset))) | (dat << offset); + write16(reg, temp); + } +}; + +#endif diff --git a/lib/lib_i2c/DFRobot_MAX17043/LICENSE b/lib/lib_i2c/DFRobot_MAX17043/LICENSE new file mode 100644 index 000000000000..79f310082f42 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/LICENSE @@ -0,0 +1,7 @@ +Copyright 2010 DFRobot Co.Ltd + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/lib/lib_i2c/DFRobot_MAX17043/README_CN.md b/lib/lib_i2c/DFRobot_MAX17043/README_CN.md new file mode 100644 index 000000000000..85d1f9c878bf --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/README_CN.md @@ -0,0 +1,121 @@ +# DFRobot_MAX17043 + +* [English Version](./README.md) + +Gravity 3.7V锂电池电量计使用Gravity I2C接口,超低工作电流,通过Maxim专利算法,实时跟踪电池的相对充电状态(SOC,State-Of-Charge),无需充放电学习过程,无积累误差,即插即用,准确地测量锂电池的当前电压和剩余电量。模块预留低电量报警中断引脚,当电池电量低于指定电量时,该引脚产生一个下跳脉冲,触发主控的外部中断。 + +![产品效果图](./resources/images/DFR0563.jpg) + + +## 产品链接([https://www.dfrobot.com.cn/goods-1743.html](https://www.dfrobot.com.cn/goods-1743.html)) + SKU: DFR0563 + +## 目录 + +* [概述](#概述) +* [连接](连接) +* [库安装](#库安装) +* [方法](#方法) +* [兼容性](#兼容性) +* [历史](#历史) +* [创作者](#创作者) + +## 概述 + +提供 Arduino 库,用于通过 I2C 读取和解释 MAX17043 数据。 + +## 连接 +相同颜色的线连接在一起,我们只举例说明主板是如何连接到电量计的。接线时要注意管脚的对应关系,接线图如下: + +* Arduino UNO +
+ +
+ +* ESP32 +
+ +
+ + +## 库安装 + +这里有2种安装方法: +1. 使用此库前,请首先下载库文件,将其粘贴到\Arduino\libraries目录中,然后打开examples文件夹并在该文件夹中运行演示。 +2. 直接在Arduino软件库管理中搜索下载 DFRobot_MAX17043 库 + +## 方法 + +```C++ + /** + * @fn DFRobot_MAX17043 + * @brief 构造MAX17043对象 + * @return MAX17043 类对象 + */ + DFRobot_MAX17043(); + /** + * @fn begin + * @brief MAX17043 初始化 + * + * @return 初始化结果 + * @retval 0 成功 + * @retval -1 失败 + */ + int begin(); + /** + * @fn readVoltage + * @brief 读电池电压,单位: mV + * @return 电池电压,单位:mV + */ + float readVoltage(); + /** + * @fn readPercentage + * @brief 读取剩余电池容量的百分比 + * + * @return 剩余电池容量的百分比 + */ + float readPercentage(); + /** + * @fn setInterrupt + * @brief 设置 MAX17043 中断阈值 + * + * @param per 中断阈值范围: %1 - 32% (整数) + */ + void setInterrupt(uint8_t per); + /** + * @fn clearInterrupt + * @brief 清除 MAX17043 中断 + */ + void clearInterrupt(); + /** + * @fn setSleep + * @brief 设置 MAX17043 进入睡眠模式 + * + */ + void setSleep(); + /** + * @fn setWakeUp + * @brief 唤醒 MAX17043 + */ + void setWakeUp(); +``` + +## 兼容性 + +| MCU | Work Well | Work Wrong | Untested | Remarks | +| ------------------ | :-------: | :--------: | :------: | ------- | +| FireBeetle-ESP32 | √ | | | +| FireBeetle-ESP8266 | √ | | | +| Arduino uno | √ | | | + +## 历史 + +- 2018/04/14 - 1.0.0 版本 + +## 创作者 + +Written by ouki.wang(ouki.wang@dfrobot.com), 2018. (Welcome to our [website](https://www.dfrobot.com/)) + + + + diff --git a/lib/lib_i2c/DFRobot_MAX17043/examples/DFRobot_MAX17043/DFRobot_MAX17043.ino b/lib/lib_i2c/DFRobot_MAX17043/examples/DFRobot_MAX17043/DFRobot_MAX17043.ino new file mode 100644 index 000000000000..746f166fe1c9 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/examples/DFRobot_MAX17043/DFRobot_MAX17043.ino @@ -0,0 +1,74 @@ +/*! + * @file DFRobot_MAX17043.ino + * @brief connect gauge I2C interface with your board (please reference board compatibility) + * @n Voltage, percentage will be printed via serial. + * @n Use API to config alaram and sleep (please reference to the readme in lib) + * + * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + * @license The MIT License (MIT) + * @author [ouki.wang](ouki.wang@dfrobot.com) + * @version V1.0 + * @date 2018-4-14 + * @url https://github.com/DFRobot/DFRobot_MAX17043 + */ + +#include "DFRobot_MAX17043.h" +#include "Wire.h" + +#ifdef __AVR__ + #define ALR_PIN 2 +#else + #define ALR_PIN D2 +#endif + +#define PRINT_INTERVAL 2000 + +DFRobot_MAX17043 gauge; +uint8_t intFlag = 0; + +void interruptCallBack() +{ + intFlag = 1; +} + +void setup() +{ + Serial.begin(115200); + while(!Serial); + Serial.println(); + Serial.println(); + pinMode(ALR_PIN, INPUT_PULLUP); + attachInterrupt(ALR_PIN, interruptCallBack, FALLING); //default alert is 32% + + while(gauge.begin() != 0) { + Serial.println("gauge begin faild!"); + delay(2000); + } + delay(2); + Serial.println("gauge begin successful!"); + //gauge.setInterrupt(32); //use this to modify alert threshold as 1% - 32% (integer) +} + +void loop() +{ + static unsigned long lastMillis = 0; + if((millis() - lastMillis) > PRINT_INTERVAL) { + lastMillis = millis(); + Serial.println(); + + Serial.print("voltage: "); + Serial.print(gauge.readVoltage()); + Serial.println(" mV"); + + Serial.print("precentage: "); + Serial.print(gauge.readPercentage()); + Serial.println(" %"); + } + + if(intFlag == 1) { + intFlag = 0; + gauge.clearInterrupt(); + Serial.println("Low power alert interrupt!"); + //put your battery low power alert interrupt service routine here + } +} diff --git a/lib/lib_i2c/DFRobot_MAX17043/keywords.txt b/lib/lib_i2c/DFRobot_MAX17043/keywords.txt new file mode 100644 index 000000000000..bcb479a57948 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/keywords.txt @@ -0,0 +1,9 @@ +DFRobot_MAX17043 KEYWORD1 + +begin KEYWORD2 +readVoltage KEYWORD2 +readPercentage KEYWORD2 +setInterrupt KEYWORD2 +clearInterrupt KEYWORD2 +setSleep KEYWORD2 +setWakeUp KEYWORD2 \ No newline at end of file diff --git a/lib/lib_i2c/DFRobot_MAX17043/library.properties b/lib/lib_i2c/DFRobot_MAX17043/library.properties new file mode 100644 index 000000000000..c769e3bef282 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/library.properties @@ -0,0 +1,9 @@ +name=DFRobot_MAX17043 +version=1.0.0 +author=DFRobot +maintainer=ouki.wang +sentence=DFRobot Standard library(SKU:DFR0563). +paragraph=Gravity: I2C 3.7V Li Battery Fuel Gauge. +category=Sensors +url=https://github.com/DFRobot/DFRobot_MAX17043 +architectures=* diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/micropython/DFRobot_MAX17043.py b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/DFRobot_MAX17043.py new file mode 100644 index 000000000000..b7ac8b9e8ba0 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/DFRobot_MAX17043.py @@ -0,0 +1,111 @@ +'''! + @file DFRobot_MAX17043.py + @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + @license The MIT License (MIT) + @author [ouki.wang](ouki.wang@dfrobot.com) + @version V1.0 + @date 2018-4-14 + @url https://github.com/DFRobot/DFRobot_MAX17043 +''' + +import time + +from machine import I2C, Pin + +## Get I2C bus +i2c = I2C(scl = Pin(22), sda = Pin(21), freq=400000) + +MAX17043_ADDR = 0x36 +MAX17043_VCELL = 0x02 +MAX17043_SOC = 0x04 +MAX17043_MODE = 0x06 +MAX17043_VERSION = 0x08 +MAX17043_CONFIG = 0x0c +MAX17043_COMMAND = 0xfe + +class DFRobot_MAX17043(): + + def __init__(self): + '''! + @brief create MAX17043 object + @return MAX17043 object + ''' + pass + + def begin(self): + '''! + @brief MAX17043 begin and test moudle + @return initialization result: + @retval 0 successful + @retval -1 faild + ''' + self._write16(MAX17043_COMMAND, 0x5400) + time.sleep(0.01) + if self._read16(MAX17043_CONFIG) == 0x971c: + self._write16(MAX17043_MODE, 0x4000) + time.sleep(0.01) + self._write16(MAX17043_CONFIG, 0x9700) + return 0 + else: + return -1 + + def read_voltage(self): + '''! + @brief read battery voltage in mV + @return voltage in mV + ''' + return (1.25 * (self._read16(MAX17043_VCELL) >> 4)) + + def read_percentage(self): + '''! + @brief read battery remaining capacity in percentage + @return battery remaining capacity in percentage + ''' + tmp = self._read16(MAX17043_SOC) + return ((tmp >> 8) + 0.003906 * (tmp & 0x00ff)) + + def set_Interrupt(self, per): + '''! + @brief set MAX17043 interrput threshold + @param per interrupt threshold as %1 - 32% (integer) + ''' + if per > 32: + per = 32 + elif per < 1: + per = 1 + per = 32 - int(per) + self._write_reg_bits(MAX17043_CONFIG, per, 0x01f, 0) + + def clear_interrupt(self): + '''! + @brief clear MAX17043 interrupt. + ''' + self._write_reg_bits(MAX17043_CONFIG, 0, 0x01, 5) + + def set_sleep(self): + '''! + @brief set MAX17043 in sleep mode. + ''' + self._write_reg_bits(MAX17043_CONFIG, 1, 0x01, 7) + + def set_wakeup(self): + '''! + @brief wake up MAX17043. + ''' + self._write_reg_bits(MAX17043_CONFIG, 0, 0x01, 7) + + def _write16(self, reg, dat): + buf = bytearray(2) + buf[0] = dat >> 8 + buf[1] = dat & 0x00ff + i2c.writeto_mem(MAX17043_ADDR, reg, buf) + + def _read16(self, reg): + buf = i2c.readfrom_mem(MAX17043_ADDR, reg, 2) + return ((buf[0] << 8) | buf[1]) + + def _write_reg_bits(self, reg, dat, bits, offset): + tmp = self._read16(reg) + tmp = (tmp & (~(bits << offset))) | (dat << offset) + self._write16(reg, tmp) + diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/micropython/README.md b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/README.md new file mode 100644 index 000000000000..106363df48c9 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/README.md @@ -0,0 +1,100 @@ +# DFRobot_MAX17043 + +* [中文版](./README_CN.md) + +The MAX17043 is ultra-compact, low-cost,host-side fuel-gauge systems for lithium-ion (Li+) batter-ies in handheld and portable +equpiment.It employs Gravity I2C interface,ultra-low opearting current, and real-time tracking of the relative state of charge +(SOC) of the battery through Maxim's patented algorithm,eliminating the need for full-to-empty relearning and offset accumualtion +errors.Plug and play to accurately measure the voltage and remaining power of the battery. The module also features as a low +battery power alert interrupt function. When the battery power falls below specified threshold, the ALR pin generates a falling +pluse to trigger the external interrupt of the controller.One thing should mention that the default value of the battery low power +interrupt alert threshold is 32%, this threshold can be set by the function set_interrupt(). + +![产品效果图](../../resources/images/DFR0563.jpg) + +## Product Link([https://www.dfrobot.com/product-1734.html](https://www.dfrobot.com/product-1734.html)) + SKU: DFR0563 + +## Table of Contents +* [Summary](#summary) +* [connection](connection) +* [Installation](#installation) +* [Methods](#methods) +* [Compatibility](#compatibility) +* [History](#history) +* [Credits](#credits) + +## Summary +Provides a microPython library for reading and interperting MAX17043 data over I2C. + +## Connection +Wires of the same color are linked together,and We only exemplify how this board is connected to the Fuel Gauge. +When connecting , it is necessary to pay attention to the correspondence among pins, the connection diagram is as fellows. + +* ESP32 + +
+ +
+ + +## Installation + +To use this library download the zip file, uncomperss it to a folder named DFRobot_MAX17043 in your upyCraft workspace. + +## Methods + +```python + '''! + @brief MAX17043 begin and test moudle + @return initialization result: + @retval 0 successful + @retval -1 faild + ''' + def begin(self): + + '''! + @brief read battery voltage in mV + @return voltage in mV + ''' + def read_voltage(self): + + '''! + @brief read battery remaining capacity in percentage + @return battery remaining capacity in percentage + ''' + def read_percentage(self): + '''! + @brief set MAX17043 interrput threshold + @param per interrupt threshold as %1 - 32% (integer) + ''' + def set_interrupt(self, per): + + '''! + @brief clear MAX17043 interrupt. + ''' + def clear_interrupt(self): + + '''! + @brief set MAX17043 in sleep mode. + ''' + def set_sleep(self): + + '''! + @brief wake up MAX17043. + ''' + +``` +## Compatibility + +| MCU | Work Well | Work Wrong | Untested | Remarks | +| ------------------ | :-------: | :--------: | :------: | ------- | +| ESP32 | √ | | | + +## History + +- 2018/04/14 - Version 1.0.0 released. + +## Credits + +Written by ouki.wang(ouki.wang@dfrobot.com), 2018. (Welcome to our [website](https://www.dfrobot.com/)) diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/micropython/README_CN.md b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/README_CN.md new file mode 100644 index 000000000000..48af8058c065 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/README_CN.md @@ -0,0 +1,97 @@ +# DFRobot_MAX17043 + +* [English Version](./README.md) + +Gravity 3.7V锂电池电量计使用Gravity I2C接口,超低工作电流,通过Maxim专利算法,实时跟踪电池的相对充电状态(SOC,State-Of-Charge),无需充放电学习过程,无积累误差,即插即用,准确地测量锂电池的当前电压和剩余电量。模块预留低电量报警中断引脚,当电池电量低于指定电量时,该引脚产生一个下跳脉冲,触发主控的外部中断。 + +![产品效果图](../../resources/images/DFR0563.jpg) + + +## 产品链接([https://www.dfrobot.com.cn/goods-1743.html](https://www.dfrobot.com.cn/goods-1743.html)) + SKU: DFR0563 + +## 目录 + +* [概述](#概述) +* [连接](连接) +* [库安装](#库安装) +* [方法](#方法) +* [兼容性](#兼容性) +* [历史](#历史) +* [创作者](#创作者) + +## 概述 +提供 microPython 库,用于通过 I2C 读取和解释 MAX17043 数据 + +## 连接 +相同颜色的线连接在一起,我们只举例说明主板是如何连接到电量计的。接线时要注意管脚的对应关系,接线图如下: + +* ESP32 + +
+ +
+ + +## 库安装 + +要使用此库,请下载 zip 文件,将其解压缩到 upyCraft 工作区中名为 DFRobot_MAX17043 的文件夹中。 + +## 方法 + +```python + '''! + @brief 构造MAX17043对象 + @return MAX17043 初始化 + @retval 0 成功 + @retval -1 失败 + ''' + def begin(self): + + '''! + @brief 读电池电压,单位: mV + @return 电池电压,单位:mV + ''' + def read_voltage(self): + + '''! + @brief 读取剩余电池容量的百分比 + @return 剩余电池容量的百分比 + ''' + def read_percentage(self): + '''! + @brief 设置 MAX17043 中断阈值 + @param per 中断阈值范围: %1 - 32% (整数) + ''' + def set_interrupt(self, per): + + '''! + @brief 清除 MAX17043 中断. + ''' + def clear_interrupt(self): + + '''! + @brief 设置 MAX17043 进入睡眠模式 + ''' + def set_sleep(self): + + '''! + @brief 唤醒 MAX17043 + ''' + def set_wakeup(self): +``` + +## 兼容性 + +| MCU | Work Well | Work Wrong | Untested | Remarks | +| ------------------ | :-------: | :--------: | :------: | ------- | +| ESP32 | √ | | | + +## 历史 + +- 2018/04/14 - 1.0.0 版本 + +## 创作者 + +Written by ouki.wang(ouki.wang@dfrobot.com), 2018. (Welcome to our [website](https://www.dfrobot.com/)) + diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/micropython/demo_MAX17043.py b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/demo_MAX17043.py new file mode 100644 index 000000000000..d6d5e2f549a5 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/micropython/demo_MAX17043.py @@ -0,0 +1,38 @@ +'''! + @file demo_MAX17043.py + @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + @license The MIT License (MIT) + @author [ouki.wang](ouki.wang@dfrobot.com) + @version V1.0 + @date 2018-4-14 + @url https://github.com/DFRobot/DFRobot_MAX17043 +''' + +import time +from machine import Pin +from DFRobot_MAX17043 import DFRobot_MAX17043 + +gauge = DFRobot_MAX17043() + +def interruptCallBack(channel): + gauge.clear_interrupt() + print('Low power alert interrupt!') + #put your battery low power alert interrupt service routine here + +pin_irq = Pin(25, Pin.IN) +pin_irq.irq(trigger = Pin.IRQ_FALLING, handler = interruptCallBack) + +rslt = gauge.begin() + +while rslt != 0: + print('gauge begin faild') + time.sleep(2) + rslt = gauge.begin() + +#gauge.set_Interrupt(32) #use this to modify alert threshold as 1% - 32% (integer) +print('gauge begin successful') + +while True: + time.sleep(2) + print('voltage: ' + str(gauge.read_voltage()) + 'mV') + print('percentage: ' + str(round(gauge.read_percentage(), 2)) + '%') diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/DFRobot_MAX17043.py b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/DFRobot_MAX17043.py new file mode 100644 index 000000000000..1ddc751caf7e --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/DFRobot_MAX17043.py @@ -0,0 +1,109 @@ +'''! + @file DFRobot_MAX17043.py + @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + @license The MIT License (MIT) + @author [ouki.wang](ouki.wang@dfrobot.com) + @version V1.0 + @date 2018-4-14 + @url https://github.com/DFRobot/DFRobot_MAX17043 +''' + +import smbus +import time +import datetime + +# Get I2C bus +bus = smbus.SMBus(1) + +MAX17043_ADDR = 0x36 +MAX17043_VCELL = 0x02 +MAX17043_SOC = 0x04 +MAX17043_MODE = 0x06 +MAX17043_VERSION = 0x08 +MAX17043_CONFIG = 0x0c +MAX17043_COMMAND = 0xfe + +class DFRobot_MAX17043(): + + def __init__(self): + '''! + @brief create MAX17043 object + @return MAX17043 object + ''' + pass + + def begin(self): + '''! + @brief MAX17043 begin and test moudle + @return initialization result: + @retval 0 successful + @retval -1 faild + ''' + self._write16(MAX17043_COMMAND, 0x5400) + time.sleep(0.01) + if self._read16(MAX17043_CONFIG) == 0x971c: + self._write16(MAX17043_MODE, 0x4000) + time.sleep(0.01) + self._write16(MAX17043_CONFIG, 0x9700) + return 0 + else: + return -1 + + def read_voltage(self): + '''! + @brief read battery voltage in mV + @return voltage in mV + ''' + return (1.25 * (self._read16(MAX17043_VCELL) >> 4)) + + def read_percentage(self): + '''! + @brief read battery remaining capacity in percentage + @return battery remaining capacity in percentage + ''' + tmp = self._read16(MAX17043_SOC) + return ((tmp >> 8) + 0.003906 * (tmp & 0x00ff)) + + def set_interrupt(self, per): + '''! + @brief set MAX17043 interrput threshold + @param per interrupt threshold as %1 - 32% (integer) + ''' + if per > 32: + per = 32 + elif per < 1: + per = 1 + per = 32 - int(per) + self._write_reg_bits(MAX17043_CONFIG, per, 0x01f, 0) + + def clear_interrupt(self): + '''! + @brief clear MAX17043 interrupt. + ''' + self._write_reg_bits(MAX17043_CONFIG, 0, 0x01, 5) + + def set_sleep(self): + '''! + @brief set MAX17043 in sleep mode. + ''' + self._write_reg_bits(MAX17043_CONFIG, 1, 0x01, 7) + + def set_wakeup(self): + '''! + @brief wake up MAX17043. + ''' + self._write_reg_bits(MAX17043_CONFIG, 0, 0x01, 7) + + def _write16(self, reg, dat): + buf = [dat >> 8, dat & 0x00ff] + bus.write_i2c_block_data(MAX17043_ADDR, reg, buf) + + def _read16(self, reg): + buf = bus.read_i2c_block_data(MAX17043_ADDR, reg, 2) + return ((buf[0] << 8) | buf[1]) + + def _write_reg_bits(self, reg, dat, bits, offset): + tmp = self._read16(reg) + tmp = (tmp & (~(bits << offset))) | (dat << offset) + self._write16(reg, tmp) + diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/README.md b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/README.md new file mode 100644 index 000000000000..47bd4267868e --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/README.md @@ -0,0 +1,128 @@ +# DFRobot_MAX17043 + +* [中文版](./README_CN.md) + +The MAX17043 is ultra-compact, low-cost,host-side fuel-gauge systems for lithium-ion (Li+) batter-ies in handheld and portable +equpiment.It employs Gravity I2C interface,ultra-low opearting current, and real-time tracking of the relative state of charge +(SOC) of the battery through Maxim's patented algorithm,eliminating the need for full-to-empty relearning and offset accumualtion +errors.Plug and play to accurately measure the voltage and remaining power of the battery. The module also features as a low +battery power alert interrupt function. When the battery power falls below specified threshold, the ALR pin generates a falling +pluse to trigger the external interrupt of the controller.One thing should mention that the default value of the battery low power +interrupt alert threshold is 32%, this threshold can be set by the function set_interrupt(). + +![产品效果图](../../resources/images/DFR0563.jpg) + +## Product Link([https://www.dfrobot.com/product-1734.html](https://www.dfrobot.com/product-1734.html)) + SKU: DFR0563 + +## Table of Contents +* [Summary](#summary) +* [connection](connection) +* [Installation](#installation) +* [Methods](#methods) +* [Compatibility](#compatibility) +* [History](#history) +* [Credits](#credits) + +## Summary + +Provides an Raspberry pi library for reading and interperting MAX17043 data over I2C. + +## Connection +Wires of the same color are linked together,and We only exemplify how these three boards are connected to the Fuel Gauge. +When connecting , it is necessary to pay attention to the correspondence among pins, the connection diagram is as fellows. + +* Raspberry Pi +
+ +
+ +## Installation + +Download and install smbus library on Raspberry pi. Steps to install smbus are provided at: + +```python +$> sudo apt-get install -y python-smbus +$> sudo apt-get install -y i2c-tools +``` + +1. To use this library, first download the library file
+```python +sudo git clone https://github.com/DFRobot/DFRobot_MAX17043 +``` +2. Open and run the routine. To execute a routine demo_x.py, enter python demo_x.py in the command line. For example, to execute the demo_read_and_int.py.py routine, you need to enter :
+ +```python +python demo_read_and_int.py.py +or +python2 demo_read_and_int.py.py +``` + +## Methods + +```python + '''! + @brief MAX17043 begin and test moudle + @return initialization result: + @retval 0 successful + @retval -1 faild + ''' + def begin(self): + + '''! + @brief read battery voltage in mV + @return voltage in mV + ''' + def read_voltage(self): + + '''! + @brief read battery remaining capacity in percentage + @return battery remaining capacity in percentage + ''' + def read_percentage(self): + '''! + @brief set MAX17043 interrput threshold + @param per interrupt threshold as %1 - 32% (integer) + ''' + def set_interrupt(self, per): + + '''! + @brief clear MAX17043 interrupt. + ''' + def clear_interrupt(self): + + '''! + @brief set MAX17043 in sleep mode. + ''' + def set_sleep(self): + + '''! + @brief wake up MAX17043. + ''' + def set_wakeup(self): + + +``` + +## Compatibility + +| 主板 | 通过 | 未通过 | 未测试 | 备注 | +| ------------ | :--: | :----: | :----: | :--: | +| RaspberryPi2 | | | √ | | +| RaspberryPi3 | | | √ | | +| RaspberryPi4 | √ | | | | + +* Python 版本 + +| Python | 通过 | 未通过 | 未测试 | 备注 | +| ------- | :--: | :----: | :----: | ---- | +| Python2 | √ | | | | +| Python3 | | | √ | | + +## History + +- 2018/04/14 - Version 1.0.0 released. + +## Credits + +Written by ouki.wang(ouki.wang@dfrobot.com), 2018. (Welcome to our [website](https://www.dfrobot.com/)) diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/README_CN.md b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/README_CN.md new file mode 100644 index 000000000000..00894b09a262 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/README_CN.md @@ -0,0 +1,119 @@ +# DFRobot_MAX17043 + +* [English Version](./README.md) + +Gravity 3.7V锂电池电量计使用Gravity I2C接口,超低工作电流,通过Maxim专利算法,实时跟踪电池的相对充电状态(SOC,State-Of-Charge),无需充放电学习过程,无积累误差,即插即用,准确地测量锂电池的当前电压和剩余电量。模块预留低电量报警中断引脚,当电池电量低于指定电量时,该引脚产生一个下跳脉冲,触发主控的外部中断。 + +![产品效果图](../../resources/images/DFR0563.jpg) + + +## 产品链接([https://www.dfrobot.com.cn/goods-1743.html](https://www.dfrobot.com.cn/goods-1743.html)) + SKU: DFR0563 + +## 目录 + +* [概述](#概述) +* [连接](连接) +* [库安装](#库安装) +* [方法](#方法) +* [兼容性](#兼容性) +* [历史](#历史) +* [创作者](#创作者) + +## 概述 + +提供 python 库,用于通过 I2C 读取和解释 MAX17043 数据。 + +## 连接 +相同颜色的线连接在一起,我们只举例说明主板是如何连接到电量计的。接线时要注意管脚的对应关系,接线图如下: + +* Raspberry Pi +
+ +
+ +## 库安装 +1. 下载库至树莓派,要使用这个库,首先要将库下载到Raspberry Pi,命令下载方法如下:
+```python +sudo git clone https://github.com/DFRobot/DFRobot_MAX17043 +``` +2. 打开并运行例程,要执行一个例程demo_x.py,请在命令行中输入python demo_x.py。例如,要执行 demo_read_and_int.py例程,你需要输入:
+ +```python +python demo_read_and_int.py +或 +python2 demo_read_and_int.py +``` + +## 方法 + +```python + '''! + @brief 构造MAX17043对象 + @return MAX17043 初始化 + @retval 0 成功 + @retval -1 失败 + ''' + def begin(self): + + '''! + @brief 读电池电压,单位: mV + @return 电池电压,单位:mV + ''' + def read_voltage(self): + + '''! + @brief 读取剩余电池容量的百分比 + @return 剩余电池容量的百分比 + ''' + def read_percentage(self): + '''! + @brief 设置 MAX17043 中断阈值 + @param per 中断阈值范围: %1 - 32% (整数) + ''' + def set_interrupt(self, per): + + '''! + @brief 清除 MAX17043 中断. + ''' + def clear_interrupt(self): + + '''! + @brief 设置 MAX17043 进入睡眠模式 + ''' + def set_sleep(self): + + '''! + @brief 唤醒 MAX17043 + ''' + def set_wakeup(self): +``` + +## 兼容性 + +| 主板 | 通过 | 未通过 | 未测试 | 备注 | +| ------------ | :--: | :----: | :----: | :--: | +| RaspberryPi2 | | | √ | | +| RaspberryPi3 | | | √ | | +| RaspberryPi4 | √ | | | | + +* Python 版本 + +| Python | 通过 | 未通过 | 未测试 | 备注 | +| ------- | :--: | :----: | :----: | ---- | +| Python2 | √ | | | | +| Python3 | | | √ | | + +## 历史 + +- 2018/04/14 - 1.0.0 版本 + +## 创作者 + +Written by ouki.wang(ouki.wang@dfrobot.com), 2018. (Welcome to our [website](https://www.dfrobot.com/)) + + + + + + diff --git a/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/examples/demo_read_and_int.py b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/examples/demo_read_and_int.py new file mode 100644 index 000000000000..dd328c6402d6 --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/python/raspberry/examples/demo_read_and_int.py @@ -0,0 +1,44 @@ +'''! + @file demo_read_and_int.py + @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) + @license The MIT License (MIT) + @author [ouki.wang](ouki.wang@dfrobot.com) + @version V1.0 + @date 2018-4-14 + @url https://github.com/DFRobot/DFRobot_MAX17043 +''' + +import sys +sys.path.append('../') +import time + +sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) +from DFRobot_MAX17043 import DFRobot_MAX17043 +import RPi.GPIO as GPIO + +gauge = DFRobot_MAX17043() + +GPIO.setmode(GPIO.BOARD) +GPIO.setup(7, GPIO.IN) + +def interruptCallBack(channel): + gauge.clear_interrupt() + print('Low power alert interrupt!') + #put your battery low power alert interrupt service routine here + +GPIO.add_event_detect(7, GPIO.FALLING, callback = interruptCallBack, bouncetime = 5) + +rslt = gauge.begin() + +while rslt != 0: + print('gauge begin faild') + time.sleep(2) + rslt = gauge.begin() + +gauge.set_interrupt(32) #use this to modify alert threshold as 1% - 32% (integer) +print('gauge begin successful') + +while True: + time.sleep(2) + print('voltage: ' + str(gauge.read_voltage()) + 'mV') + print('percentage: ' + str(round(gauge.read_percentage(), 2)) + '%') diff --git a/lib/lib_i2c/DFRobot_MAX17043/readme.md b/lib/lib_i2c/DFRobot_MAX17043/readme.md new file mode 100644 index 000000000000..fdc79ac77b4f --- /dev/null +++ b/lib/lib_i2c/DFRobot_MAX17043/readme.md @@ -0,0 +1,122 @@ +# DFRobot_MAX17043 + +* [中文版](./README_CN.md) + + The MAX17043 is ultra-compact, low-cost,host-side fuel-gauge systems for lithium-ion (Li+) batter-ies in handheld and portable +equipment.It employs Gravity I2C interface,ultra-low opearting current, and real-time tracking of the relative state of charge (SOC) +of the battery through Maxim's patented algorithm,eliminating the need for full-to-empty relearning and offset accumualtion errors. +Plug and play to accurately measure the voltage and remaining power of the battery. The module also features as a low battery power +alert interrupt function. When the battery power falls below specified threshold, the ALR pin generates a falling pluse to trigger +the external interrupt of the controller.One thing should mention that the default value of the battery low power interrupt alert +threshold is 32%, this threshold can be set by the function setInterrupt(). + +![产品效果图](./resources/images/DFR0563.jpg) + +## Product Link([https://www.dfrobot.com/product-1734.html](https://www.dfrobot.com/product-1734.html)) + SKU: DFR0563 + +## Table of Contents +* [Summary](#summary) +* [connection](connection) +* [Installation](#installation) +* [Methods](#methods) +* [Compatibility](#compatibility) +* [History](#history) +* [Credits](#credits) + +## Summary + +Provides an Arduino library for reading and interperting MAX17043 data over I2C. + +## Connection +Wires of the same color are linked together,and We only exemplify how these the boards are connected to the Fuel Gauge. +When connecting , it is necessary to pay attention to the correspondence among pins, the connection diagram is as fellows. + +* Arduino UNO +
+ +
+ +* ESP32 +
+ +
+ + +## Installation + +To use this library download the zip file, uncomperss it to a folder named DFRobot_MAX17043 in Arduino library. +## Methods + +```C++ + /** + * @fn DFRobot_MAX17043 + * @brief create MAX17043 object + * @return MAX17043 object + */ + DFRobot_MAX17043(); + /** + * @fn begin + * @brief MAX17043 begin and test moudle + * + * @return initialization result + * @retval 0 successful + * @retval -1 faild + */ + int begin(); + /** + * @fn readVoltage + * @brief read battery voltage in mV + * @return voltage in mV + */ + float readVoltage(); + /** + * @fn readPercentage + * @brief read battery remaining capacity in percentage + * + * @return battery remaining capacity in percentage + */ + float readPercentage(); + /** + * @fn setInterrupt + * @brief set MAX17043 interrput threshold + * + * @param per interrupt threshold as %1 - 32% (integer) + */ + void setInterrupt(uint8_t per); + /** + * @fn clearInterrupt + * @brief clear MAX17043 interrupt + */ + void clearInterrupt(); + /** + * @fn setSleep + * @brief set MAX17043 in sleep mode + * + */ + void setSleep(); + /** + * @fn setWakeUp + * @brief wake up MAX17043 + * + */ + void setWakeUp(); + +``` + +## Compatibility + +| MCU | Work Well | Work Wrong | Untested | Remarks | +| ------------------ | :-------: | :--------: | :------: | ------- | +| FireBeetle-ESP32 | √ | | | +| FireBeetle-ESP8266 | √ | | | +| Arduino uno | √ | | | + +## History + +- 2018/04/14 - Version 1.0.0 released. + +## Credits + +Written by ouki.wang(ouki.wang@dfrobot.com), 2018. (Welcome to our [website](https://www.dfrobot.com/)) + diff --git a/lib/lib_i2c/DFRobot_MAX17043/resources/images/DFR0563.jpg b/lib/lib_i2c/DFRobot_MAX17043/resources/images/DFR0563.jpg new file mode 100644 index 000000000000..eb0370a56c7a Binary files /dev/null and b/lib/lib_i2c/DFRobot_MAX17043/resources/images/DFR0563.jpg differ diff --git a/lib/lib_i2c/DFRobot_MAX17043/resources/images/Raspberry Pi.jpg b/lib/lib_i2c/DFRobot_MAX17043/resources/images/Raspberry Pi.jpg new file mode 100644 index 000000000000..3ab96c2cde7f Binary files /dev/null and b/lib/lib_i2c/DFRobot_MAX17043/resources/images/Raspberry Pi.jpg differ diff --git a/lib/lib_i2c/DFRobot_MAX17043/resources/images/UNO.jpg b/lib/lib_i2c/DFRobot_MAX17043/resources/images/UNO.jpg new file mode 100644 index 000000000000..8c3d66b65330 Binary files /dev/null and b/lib/lib_i2c/DFRobot_MAX17043/resources/images/UNO.jpg differ diff --git a/lib/lib_i2c/DFRobot_MAX17043/resources/images/esp32.jpg b/lib/lib_i2c/DFRobot_MAX17043/resources/images/esp32.jpg new file mode 100644 index 000000000000..41b163cfd552 Binary files /dev/null and b/lib/lib_i2c/DFRobot_MAX17043/resources/images/esp32.jpg differ diff --git a/tasmota/include/i18n.h b/tasmota/include/i18n.h index 1cbb6ffd4384..9daf1e90c653 100644 --- a/tasmota/include/i18n.h +++ b/tasmota/include/i18n.h @@ -238,6 +238,7 @@ #define D_JSON_MY "YaxisInduction" #define D_JSON_MZ "ZaxisInduction" #define D_JSON_MAGNETICFLD "MagneticInduction" +#define D_JSON_BATTPERCENT "BatteryPercentage" #define D_RSLT_ENERGY "ENERGY" #define D_RSLT_HASS_STATE "HASS_STATE" #define D_RSLT_INFO "INFO" diff --git a/tasmota/language/af_AF.h b/tasmota/language/af_AF.h index f3df5343fd90..7e4a8266cc60 100644 --- a/tasmota/language/af_AF.h +++ b/tasmota/language/af_AF.h @@ -58,6 +58,7 @@ #define D_AS "as" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Lading" // Battery charge in % #define D_BLINK "Flits" #define D_BLINKOFF "FlitsAf" #define D_BOOT_COUNT "Opstarttelling" diff --git a/tasmota/language/bg_BG.h b/tasmota/language/bg_BG.h index 88077766938a..b88b41a1dc55 100644 --- a/tasmota/language/bg_BG.h +++ b/tasmota/language/bg_BG.h @@ -58,6 +58,7 @@ #define D_AS "като" #define D_AUTO "АВТОМАТИЧНО" #define D_BATT "Бат." // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Мигане вкл." #define D_BLINKOFF "Мигане изкл." #define D_BOOT_COUNT "Брой стартирания" diff --git a/tasmota/language/ca_AD.h b/tasmota/language/ca_AD.h index ef786b86872f..9236ad1d4278 100644 --- a/tasmota/language/ca_AD.h +++ b/tasmota/language/ca_AD.h @@ -58,6 +58,7 @@ #define D_AS "com" #define D_AUTO "AUTO" #define D_BATT "Bat" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Espurna" #define D_BLINKOFF "Espurna Fora" #define D_BOOT_COUNT "Compte Arrencs" diff --git a/tasmota/language/cs_CZ.h b/tasmota/language/cs_CZ.h index 863ab0786b05..29be007fef22 100644 --- a/tasmota/language/cs_CZ.h +++ b/tasmota/language/cs_CZ.h @@ -58,6 +58,7 @@ #define D_AS "jako" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blikání" #define D_BLINKOFF "BlikáníVyp" #define D_BOOT_COUNT "Počítadlo spuštění" diff --git a/tasmota/language/de_DE.h b/tasmota/language/de_DE.h index fc3c7950a9b8..81d078731b39 100644 --- a/tasmota/language/de_DE.h +++ b/tasmota/language/de_DE.h @@ -58,6 +58,7 @@ #define D_AS "als" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Ladung" // Battery charge in % #define D_BLINK "Blinken" #define D_BLINKOFF "BlinkenAus" #define D_BOOT_COUNT "Anzahl Startvorgänge" diff --git a/tasmota/language/el_GR.h b/tasmota/language/el_GR.h index d25e8c307c75..d28d321c7087 100644 --- a/tasmota/language/el_GR.h +++ b/tasmota/language/el_GR.h @@ -58,6 +58,7 @@ #define D_AS "ως" #define D_AUTO "ΑΥΤΟΜΑΤΟ" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blink" #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Καταμέτρηση εκκινήσεων" diff --git a/tasmota/language/en_GB.h b/tasmota/language/en_GB.h index 416fc3c03d85..f98f11e5f476 100644 --- a/tasmota/language/en_GB.h +++ b/tasmota/language/en_GB.h @@ -58,6 +58,7 @@ #define D_AS "as" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blink" #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Boot Count" diff --git a/tasmota/language/es_ES.h b/tasmota/language/es_ES.h index 1e86320089c5..0faf11db57d5 100644 --- a/tasmota/language/es_ES.h +++ b/tasmota/language/es_ES.h @@ -58,6 +58,7 @@ #define D_AS "como" #define D_AUTO "AUTO" #define D_BATT "Bat" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blink" #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Conteo Reinicios" diff --git a/tasmota/language/fr_FR.h b/tasmota/language/fr_FR.h index 0f62d157123b..a2d25a85f396 100644 --- a/tasmota/language/fr_FR.h +++ b/tasmota/language/fr_FR.h @@ -58,6 +58,7 @@ #define D_AS "comme" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blink" // Not better in french #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Nb. de boot" diff --git a/tasmota/language/fy_NL.h b/tasmota/language/fy_NL.h index 7c3955dacfd4..8881749bdee3 100644 --- a/tasmota/language/fy_NL.h +++ b/tasmota/language/fy_NL.h @@ -58,6 +58,7 @@ #define D_AS "als" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Lading" // Battery charge in % #define D_BLINK "Blinkje" #define D_BLINKOFF "BlinkjeUit" #define D_BOOT_COUNT "Op 'e nij begjinne" diff --git a/tasmota/language/he_HE.h b/tasmota/language/he_HE.h index 39daf879e1ad..545c44ba3630 100644 --- a/tasmota/language/he_HE.h +++ b/tasmota/language/he_HE.h @@ -58,6 +58,7 @@ #define D_AS "-כ" #define D_AUTO "אוטומטי" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "מהבהב" #define D_BLINKOFF "כיבוי היבהוב" #define D_BOOT_COUNT "מונה הפעלה מחדש" diff --git a/tasmota/language/hu_HU.h b/tasmota/language/hu_HU.h index bb0e6b21152c..4154a31f10ca 100644 --- a/tasmota/language/hu_HU.h +++ b/tasmota/language/hu_HU.h @@ -58,6 +58,7 @@ #define D_AS "mint" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Villogás" #define D_BLINKOFF "Villogás ki" #define D_BOOT_COUNT "Újraindulások száma" diff --git a/tasmota/language/it_IT.h b/tasmota/language/it_IT.h index 3e8b80e6fd2f..e2f5412e410d 100644 --- a/tasmota/language/it_IT.h +++ b/tasmota/language/it_IT.h @@ -58,6 +58,7 @@ #define D_AS "come" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Lampeggia" #define D_BLINKOFF "Lampeggia OFF" #define D_BOOT_COUNT "Numero boot" diff --git a/tasmota/language/ko_KO.h b/tasmota/language/ko_KO.h index c5db16e45f8b..f04d95756ddf 100644 --- a/tasmota/language/ko_KO.h +++ b/tasmota/language/ko_KO.h @@ -58,6 +58,7 @@ #define D_AS "as" #define D_AUTO "자동" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "깜박임" #define D_BLINKOFF "깜박임 끄기" #define D_BOOT_COUNT "부팅 횟수" diff --git a/tasmota/language/nl_NL.h b/tasmota/language/nl_NL.h index 4ab10ce0e202..87a38d82e9eb 100644 --- a/tasmota/language/nl_NL.h +++ b/tasmota/language/nl_NL.h @@ -58,6 +58,7 @@ #define D_AS "als" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Lading" // Battery charge in % #define D_BLINK "Knipper" #define D_BLINKOFF "KnipperUit" #define D_BOOT_COUNT "Herstarts" diff --git a/tasmota/language/pl_PL.h b/tasmota/language/pl_PL.h index 840a0a847495..1da04b14bd32 100644 --- a/tasmota/language/pl_PL.h +++ b/tasmota/language/pl_PL.h @@ -58,6 +58,7 @@ #define D_AS "jak" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Miganie" #define D_BLINKOFF "Miganie - Wył." #define D_BOOT_COUNT "Licznik restartów" diff --git a/tasmota/language/pt_BR.h b/tasmota/language/pt_BR.h index b4b32eeb164c..6b0136112232 100644 --- a/tasmota/language/pt_BR.h +++ b/tasmota/language/pt_BR.h @@ -58,6 +58,7 @@ #define D_AS "como" #define D_AUTO "Auto" #define D_BATT "Bat" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Piscar" #define D_BLINKOFF "Piscar desligado" #define D_BOOT_COUNT "Contagem de inicialização" diff --git a/tasmota/language/pt_PT.h b/tasmota/language/pt_PT.h index 8d22afd35799..eeb3dd2d9557 100644 --- a/tasmota/language/pt_PT.h +++ b/tasmota/language/pt_PT.h @@ -58,6 +58,7 @@ #define D_AS "como" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Piscar" #define D_BLINKOFF "Piscar Desligado" #define D_BOOT_COUNT "Contagem de Inicialização" diff --git a/tasmota/language/ro_RO.h b/tasmota/language/ro_RO.h index ddb93ccc6a39..995490a7d506 100644 --- a/tasmota/language/ro_RO.h +++ b/tasmota/language/ro_RO.h @@ -58,6 +58,7 @@ #define D_AS "as" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blink" #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Boot Count" diff --git a/tasmota/language/ru_RU.h b/tasmota/language/ru_RU.h index 655778364981..60d61d492c21 100644 --- a/tasmota/language/ru_RU.h +++ b/tasmota/language/ru_RU.h @@ -58,6 +58,7 @@ #define D_AS "как" #define D_AUTO "АВТО" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Мигать" #define D_BLINKOFF "Не Мигать" #define D_BOOT_COUNT "Количество загрузок" diff --git a/tasmota/language/sk_SK.h b/tasmota/language/sk_SK.h index bcb03e92d624..15a3ae00ca09 100644 --- a/tasmota/language/sk_SK.h +++ b/tasmota/language/sk_SK.h @@ -58,6 +58,7 @@ #define D_AS "ako" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blikanie" #define D_BLINKOFF "BlikanieVyp" #define D_BOOT_COUNT "Počítadlo spustení" diff --git a/tasmota/language/sv_SE.h b/tasmota/language/sv_SE.h index 7555763c00e1..1bbb4ddd94f3 100644 --- a/tasmota/language/sv_SE.h +++ b/tasmota/language/sv_SE.h @@ -58,6 +58,7 @@ #define D_AS "som" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blinka" #define D_BLINKOFF "BlinkaAv" #define D_BOOT_COUNT "Uppstartsräknare" diff --git a/tasmota/language/tr_TR.h b/tasmota/language/tr_TR.h index 36b763a0783f..32b6864abe4b 100644 --- a/tasmota/language/tr_TR.h +++ b/tasmota/language/tr_TR.h @@ -58,6 +58,7 @@ #define D_AS "as" #define D_AUTO "OTOMATIK" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blink" #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Yeniden başlama sayısı" diff --git a/tasmota/language/uk_UA.h b/tasmota/language/uk_UA.h index 0023f5c34c67..6271fe9525b5 100644 --- a/tasmota/language/uk_UA.h +++ b/tasmota/language/uk_UA.h @@ -58,6 +58,7 @@ #define D_AS "як" #define D_AUTO "АВТО" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Блимати" #define D_BLINKOFF "Не блимати" #define D_BOOT_COUNT "К-сть завант." diff --git a/tasmota/language/vi_VN.h b/tasmota/language/vi_VN.h index 11f293b03c6e..63e522ba19cf 100644 --- a/tasmota/language/vi_VN.h +++ b/tasmota/language/vi_VN.h @@ -58,6 +58,7 @@ #define D_AS "với tên gọi" #define D_AUTO "AUTO" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "Blink" #define D_BLINKOFF "BlinkOff" #define D_BOOT_COUNT "Số lần khởi động" diff --git a/tasmota/language/zh_CN.h b/tasmota/language/zh_CN.h index ea316b48dd3c..63d65eae2d98 100644 --- a/tasmota/language/zh_CN.h +++ b/tasmota/language/zh_CN.h @@ -58,6 +58,7 @@ #define D_AS "名称:" #define D_AUTO "自动" #define D_BATT "Batt" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "闪烁" #define D_BLINKOFF "闪烁关" #define D_BOOT_COUNT "启动次数" diff --git a/tasmota/language/zh_TW.h b/tasmota/language/zh_TW.h index 62b6560867f6..d6e7b5f7a5b9 100644 --- a/tasmota/language/zh_TW.h +++ b/tasmota/language/zh_TW.h @@ -58,6 +58,7 @@ #define D_AS "名稱:" #define D_AUTO "自動" #define D_BATT "電池" // Short for Battery +#define D_BATTERY_CHARGE "Charge" // Battery charge in % #define D_BLINK "閃爍" #define D_BLINKOFF "閃爍關" #define D_BOOT_COUNT "啟動計數" diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 495495bd8a0f..4a8291e2789f 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -711,6 +711,8 @@ // #define TC74_MAX_SENSORS 8 // Support non-default/multiple I2C addresses // #define TC74_I2C_PROBE_ADDRESSES { 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F } // Addresses to probe/support // #define TC74_MAX_FAILCOUNT 8 // Maximum failed polls before it's marked inactive until reprobing later +// #define USE_MAX17043 // [I2cDriver110] Enable MAX17043 sensor (I2C addresses 0x36) + // #define USE_PCA9557 // [I2cDriver81] Enable PCA9557 8-bit I/O Expander (I2C addresses 0x18 - 0x1F) (+2k5 code) // #define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one diff --git a/tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino b/tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino new file mode 100644 index 000000000000..918deeb68c11 --- /dev/null +++ b/tasmota/tasmota_xsns_sensor/xsns_110_max17043.ino @@ -0,0 +1,132 @@ +/* + xsns_109_max17043.ino - Support for MAX17043 fuel-gauge systems Lipo batteries for Tasmota + + Copyright (C) 2023 Vincent de Groot + + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifdef USE_I2C +#ifdef USE_MAX17043 + +#define XI2C_83 83 // See I2CDEVICES.md + +#define SENSOR_NAME "MAX17043" + +#include "DFRobot_MAX17043.h" + +/*********************************************************************************************\ + * MAX17043 fuel-gauge for 3.7 Volt Lipo batteries + * + * Battery voltage in Volt and State Of Charge (SOC) in percent are published via MQTT + * + * The alert flag and alert threshold are not required for MQTT, the alert pin is not used + * by this sensor driver. + * + * Wirering and other information: + * + * \lib\lib_i2c\DFRobot_MAX17043\resources + * + * Tested module(s): + * + * https://www.dfrobot.com/product-1734.html + * + * Not yet tested module(s): + * + * https://www.aliexpress.us/item/2251832479401925.html + * + \*********************************************************************************************/ + +#define XSNS_109 109 + +const char *mqttId = "MAX17043"; + +DFRobot_MAX17043 gauge; // Class to read from MAX17043 + +struct MAX17043 +{ + float voltage = 0.0; // Battery voltage in Volt + float percentage = 0.0; // Battery remaining charge in percent +} *max17043 = nullptr; + + /*********************************************************************************************/ + +void Max17043Init(void) { + + if (I2cSetDevice(MAX17043_ADDRESS)) { + I2cSetActiveFound(MAX17043_ADDRESS, "MAX17043"); + if (gauge.begin() == 0) { + max17043 = (MAX17043 *)calloc(1, sizeof(struct MAX17043)); + } + } +} + +void Max17043Read(void) { + + float percentage = 0.0; + + max17043->voltage = gauge.readVoltage()/1000.0; + + // During charging the percentage might be (slightly) above 100%. To avoid stange numbers + // in the statistics we the percentage provided by this driver will not go above 100% + percentage = gauge.readPercentage(); + if (percentage > 100.0) { + max17043->percentage = 100.0; + } + else { + max17043->percentage = percentage; + } +} + +void Max17043Json(void) { + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_VOLTAGE "\":%3_f,\"" D_JSON_BATTPERCENT "\":%2_f}"), mqttId, &max17043->voltage, &max17043->percentage ); +} + +#ifdef USE_WEBSERVER +void Max17043Show(void) { + WSContentSend_PD(PSTR("{s}%s " D_VOLTAGE "{m}%1_f" D_UNIT_VOLT "{e}"), SENSOR_NAME, &max17043->voltage); + WSContentSend_PD(PSTR("{s}%s " D_BATTERY_CHARGE "{m}%1_f %% {e}"), SENSOR_NAME, &max17043->percentage); +} +#endif // USE_WEBSERVER + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xsns109(uint32_t function) { +if (!I2cEnabled(MAX17043_ADDRESS)) { return false; } + + if (FUNC_INIT == function) { + Max17043Init(); + } + else if (max17043 != nullptr) { + switch (function) { + case FUNC_EVERY_SECOND: + Max17043Read(); + break; + case FUNC_JSON_APPEND: + Max17043Json(); + break; + #ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + Max17043Show(); + break; + #endif // USE_WEBSERVER + } + } + return false; +} + +#endif // USE_MAX17043 +#endif // USE_I2C \ No newline at end of file