mirror of https://github.com/arendst/Tasmota.git
MAX17043 sensor integration (#18788)
* Restart MAX17043 from the scratch * revert change * Changed battery capacity in charge (capacity is the Ah value of the battery, this degrades over time when battery ages) * merge * Changing xsns_109 to 110 * fix nr * removed old xsns109 * Update I2CDEVICES.md * clean-up usage of Interface
This commit is contained in:
parent
973ce106e7
commit
bc41500d9c
|
@ -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 |
|
||||
| |
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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.
|
|
@ -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
|
||||
<br>
|
||||
<img src="./resources/images/UNO.jpg">
|
||||
<br>
|
||||
|
||||
* ESP32
|
||||
<br>
|
||||
<img src="./resources/images/esp32.jpg">
|
||||
<br>
|
||||
|
||||
|
||||
## 库安装
|
||||
|
||||
这里有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/))
|
||||
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
DFRobot_MAX17043 KEYWORD1
|
||||
|
||||
begin KEYWORD2
|
||||
readVoltage KEYWORD2
|
||||
readPercentage KEYWORD2
|
||||
setInterrupt KEYWORD2
|
||||
clearInterrupt KEYWORD2
|
||||
setSleep KEYWORD2
|
||||
setWakeUp KEYWORD2
|
|
@ -0,0 +1,9 @@
|
|||
name=DFRobot_MAX17043
|
||||
version=1.0.0
|
||||
author=DFRobot
|
||||
maintainer=ouki.wang <ouki.wang@dfrobot.com>
|
||||
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=*
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
||||
<br>
|
||||
<img src="../../resources/images/esp32.jpg">
|
||||
<br>
|
||||
|
||||
|
||||
## 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/))
|
|
@ -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
|
||||
|
||||
<br>
|
||||
<img src="../../resources/images/esp32.jpg">
|
||||
<br>
|
||||
|
||||
|
||||
## 库安装
|
||||
|
||||
要使用此库,请下载 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/))
|
||||
|
|
@ -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)) + '%')
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
<br>
|
||||
<img src="../../resources/images/Raspberry Pi.jpg">
|
||||
<br>
|
||||
|
||||
## 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<br>
|
||||
```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 :<br>
|
||||
|
||||
```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/))
|
|
@ -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
|
||||
<br>
|
||||
<img src="../../resources/images/Raspberry Pi.jpg">
|
||||
<br>
|
||||
|
||||
## 库安装
|
||||
1. 下载库至树莓派,要使用这个库,首先要将库下载到Raspberry Pi,命令下载方法如下:<br>
|
||||
```python
|
||||
sudo git clone https://github.com/DFRobot/DFRobot_MAX17043
|
||||
```
|
||||
2. 打开并运行例程,要执行一个例程demo_x.py,请在命令行中输入python demo_x.py。例如,要执行 demo_read_and_int.py例程,你需要输入:<br>
|
||||
|
||||
```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/))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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)) + '%')
|
|
@ -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
|
||||
<br>
|
||||
<img src="./resources/images/UNO.jpg">
|
||||
<br>
|
||||
|
||||
* ESP32
|
||||
<br>
|
||||
<img src="./resources/images/esp32.jpg">
|
||||
<br>
|
||||
|
||||
|
||||
## 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/))
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 "Брой стартирания"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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í"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 "Καταμέτρηση εκκινήσεων"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 "מונה הפעלה מחדש"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 "부팅 횟수"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 "Количество загрузок"
|
||||
|
|
|
@ -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í"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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ı"
|
||||
|
|
|
@ -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 "К-сть завант."
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 "启动次数"
|
||||
|
|
|
@ -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 "啟動計數"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
Loading…
Reference in New Issue