Gravity__3.7V_Li_Battery_Fuel_Gauge_SKU__DFR0563-DFRobot

Introduction

3.7V lithium batteries are commonly used in many projects. However, The remaining power and voltage of the lithium battery are highly nonlinear. We can only roughly judge whether the battery is full or almost empty according to its voltage. The Gravity 3.7V Lithium Battery Fuel Gauge employs Gravity I2C interface, ultra-low operating 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 accumulation 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 pulse to trigger the external interrupt of the controller. You will find it a great help to estimate the battery life by learning the power consumption of the system with this module. In the solar powered projects, it helps to record the status of the battery power change in a day or even months, which benefits to understand the power balance of charge and discharge of the solar system.

Features

Specifications

Applications

Board Overview


Label Name Description
+ VCC Power VCC(3.3~6.0V)
- GND Power GND
C SCL I2C Clock Signal
D SDA I2C Data Signal
ALR ALRT* Low battery power alert interrupt (active low)
BAT IN Battery input 3.7V lithium battery connection port
REV BAT Battery reverse Indicator When the battery connection is reversed, REV BAT lights up.

Tutorial

Requirements

Connection Diagram


Read Battery Voltage, Remaining Power and Set Low Power Interrupt Alert

Sample Code

/*
 * file DFRobot_MAX17043.ino
 *
 * connect gauge I2C interface with your board (please reference board compatibility)
 *
 * Voltage, percentage will be printed via serial.
 * Use API to config alaram and sleep (please reference to the readme in lib)
 *
 * Copyright   [DFRobot](https://www.dfrobot.com), 2016
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-3-26
 */

#include "DFRobot_MAX17043.h"
#include "Wire.h"

#ifdef __AVR__
  #define ALR_PIN       2
#else
  #define ALR_PIN       D2
#endif

#define PRINT_INTERVAL        2000
#define BAT_PERCENTAGE        32

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(digitalPinToInterrupt(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(BAT_PERCENTAGE);  //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
  }
}

Results


Raspberry Pi Tutorial

Requirements

Connection Diagram


Installation

1.Start the I2C interface of the Raspberry Pi. If it is already open, skip this step. Open Terminal, type the following command, and press Enter:

 pi@raspberrypi:~ $ sudo raspi-config

Then use the up and down keys to select “5 Interfacing Options” -> “P5 I2C” and press Enter to confirm “YES”. Reboot the Raspberry Pi.

2.Installing Python libraries and git (networking required). If it is already installed, skip this step. In the Terminal, type the following commands, and press Enter:

pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git

3.Download the driver library and run it. In Terminal, type the following commands, and press Enter:

pi@raspberrypi:~ $ git clone https://github.com/DFRobot/DFRobot_MAX17043.git
pi@raspberrypi:~ $ cd ~/DFRobot_MAX17043/RaspberryPi/python
pi@raspberrypi:~/DFRobot_MAX17043/RaspberryPi/python $ python DFRobot_MAX17043.py

Read Battery Voltage, Remaining Power and Set Low Power Interrupt Alert

pi@raspberrypi:~/DFRobot_MAX17043/RaspberryPi/python $ cd readAndInt
pi@raspberrypi:~/DFRobot_MAX17043/RaspbeeryPi/python/readAndInt $ python readAndInt.py

Results


Application Examples

Build a Solar Power Management System

Gravity: 3.7V Li Battery Fuel Gauge can be used with the Solar Power Manager 5V to build a solar power management system. The battery fuel gauge can be used to monitor the charging of the battery with a solar panel in real time during the day, and the power consumption of the system during the night. Users can write their own code to record or print battery voltage and remaining power data, which can be employed to evaluate the "power balance" of the solar system in a day or even several months. These datum helps users to determine whether the nominal power of the panel or lithium battery power is large enough to fully support the entire system during the day and night.

The low power interrupt alert of the fuel gauge and controllable 5V power supply of the solar power management module can be used to save power when the battery power is lower than a specified threshold. The ALR pin will send an interrupt signal to trigger the controller to turn off the 5V power supply. This shuts off the power supply of external modules connected to the solar power module, and thus saves power.


FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents