element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Community Hub
Community Hub
Member Blogs Wio Terminal - Battery Fuel Gauge
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 8 Jan 2021 4:49 AM Date Created
  • Views 3416 views
  • Likes 5 likes
  • Comments 8 comments
  • battery fuel gauge
  • ti bq27441
  • wio terminal
Related
Recommended

Wio Terminal - Battery Fuel Gauge

ralphjy
ralphjy
8 Jan 2021

The new version of the Battery Chassis add-on for the Wio Terminal has added an On-Off button and a Texas Instrument's BQ27441 Battery Fuel Gauge https://wiki.seeedstudio.com/Wio-Terminal-Chassis-Battery(650mAh)/  .

 

The fuel gauge is a great feature that measures your battery's voltage to estimate its charge percentage and remaining capacity. The chip is also hooked up to a current-sensing resistor, which allows it to measure current and power.  The fuel gauge interfaces using I2C.  This will be useful to monitor the battery in remote datalogging applications.

 

TI BQ27441

image

 

image

There is a SparkFun Arduino library https://github.com/sparkfun/SparkFun_BQ27441_Arduino_Library  .  The library abstracts away all of the low-level I2C communication, so you can easily initialize the fuel gauge then read voltage, state-of-charge, current, power, and capacity. It also implements all of the chip's low-battery, and SoC-change alerts on the GPOUT pin.

 

Here is a demo of Battery Status display on the Wio Terminal during discharging (running on battery power) and charging (running and charging from USB).  I haven't quite figured out "State of Health" yet - it always returns 0%.  And I'm not sure why the full battery capacity is incorrect (it should be 650 mAh).  I'll need to read through the BQ27441 spec.  And I also haven't been able to get the correct schematic for the new Battery Chassis, but I've requested it on the SEEED forum.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Wio_Terminal_Battery_Gauge.ino

#include <SparkFunBQ27441.h>
#include"TFT_eSPI.h"

TFT_eSPI tft;
TFT_eSprite spr = TFT_eSprite(&tft);  // Sprite
#define FF17 &FreeSans9pt7b

const unsigned int BATTERY_CAPACITY = 650; // Set Wio Terminal Battery's Capacity 

void setupBQ27441(void)
{
  // Use lipo.begin() to initialize the BQ27441-G1A and confirm that it's
  // connected and communicating.
  if (!lipo.begin()) // begin() will return true if communication is successful
  {
  // If communication fails, print an error message and loop forever.
    Serial.println("Error: Unable to communicate with BQ27441.");
    Serial.println("  Check wiring and try again.");
    Serial.println("  (Battery must be plugged into Battery Babysitter!)");
    tft.setTextColor(TFT_RED);
    tft.setCursor((320 - tft.textWidth("Battery Not Initialised!"))/2, 120);
    tft.print("Battery Not Initialised!");
    while (1) ;
  }
  Serial.println("Connected to BQ27441!");

  // Uset lipo.setCapacity(BATTERY_CAPACITY) to set the design capacity
  // of your battery.
  lipo.setCapacity(BATTERY_CAPACITY);
}

void printBatteryStats()
{
  // Read battery stats from the BQ27441-G1A
  unsigned int soc = lipo.soc();  // Read state-of-charge (%)
  unsigned int volts = lipo.voltage(); // Read battery voltage (mV)
  int current = lipo.current(AVG); // Read average current (mA)
  unsigned int fullCapacity = lipo.capacity(FULL); // Read full capacity (mAh)
  unsigned int capacity = lipo.capacity(REMAIN); // Read remaining capacity (mAh)
  int power = lipo.power(); // Read average power draw (mW)
  int health = lipo.soh(); // Read state-of-health (%)

  // Now print out those values:
  String toPrint = String(soc) + "% | ";
  toPrint += String(volts) + " mV | ";
  toPrint += String(current) + " mA | ";
  toPrint += String(capacity) + " / ";
  toPrint += String(fullCapacity) + " mAh | ";
  toPrint += String(power) + " mW | ";
  toPrint += String(health) + "%";

  Serial.println(toPrint);

  // LCD Graphics
  tft.setTextColor(TFT_BLUE);
  tft.drawRoundRect(10, 10, 300, 220, 10, TFT_BLUE);
  tft.setTextColor(TFT_MAGENTA);
  tft.drawString("State of Chage:", 20, 30);
  tft.drawString("Battery Voltage:", 20, 55);
  tft.drawString("Average Current:", 20, 80);
  tft.drawString("Remain Capacity:", 20, 105);
  tft.drawString("Full Capacity:", 20, 130);
  tft.drawString("Average Power:", 20, 155);
  tft.drawString("State of Health:", 20, 180);

  // Data
  spr.createSprite(80, 170);
  spr.fillSprite(TFT_BLACK);
  spr.setFreeFont(FF17);
  spr.setTextColor(TFT_WHITE);
  spr.drawString(String(soc)+" % ", 0, 0);
  spr.drawString(String(volts)+" mV ", 0, 25);
  spr.drawString(String(current)+" mA ", 0, 50);
  spr.drawString(String(capacity)+" mAh ", 0, 75);
  spr.drawString(String(fullCapacity)+" mAh ", 0, 100);
  spr.drawString(String(power)+" mW ", 0, 125);
  spr.drawString(String(health)+" % ", 0, 150);
  spr.pushSprite(170, 30);
  spr.deleteSprite();
}

void setup()
{
  Serial.begin(115200);
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(TFT_BLACK);
  tft.setFreeFont(FF17); 
  setupBQ27441();
  tft.setTextColor(TFT_GREEN);
  tft.setCursor((320 - tft.textWidth("Battery Initialised!"))/2, 120);
  tft.print("Battery Initialised!");
  delay(1000);
  tft.fillScreen(TFT_BLACK);
}

void loop() 
{
  printBatteryStats();
  delay(1000);
}

  • Sign in to reply

Top Comments

  • genebren
    genebren over 4 years ago +2
    Interesting device. The datasheet on the BQ27441 mentions a Coulomb counter, which would imply that the charge and discharge currents (mA) are being used to accumulate the charge over time (mAH) to determine…
  • Jan Cumps
    Jan Cumps over 4 years ago +2
    I've used a bq27510-G2. Time to review that again. These gauges are a great way to keep track of charge and health...
  • ralphjy
    ralphjy over 4 years ago in reply to genebren +1
    Thanks, I'll go read that white paper. The thing that confused me - still does - about the battery capacity is that the program sets that value in a register using lipo.setCapacity(BATTERY_CAPACITY). I…
  • ralphjy
    ralphjy over 4 years ago in reply to Jan Cumps +1
    I haven't used a battery fuel gauge before, but I'd also not encountered PMICs until having to reprogram one on the Ultra96v2 board. Now I see PMICs being used on even low cost boards and I'll probably…
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to ralphjy +1
    ralphjy wrote: ... I'd also not encountered PMICs until having to reprogram one on the Ultra96v2 board. Now I see PMICs being used on even low cost boards and I'll probably want to use those and these…
  • genebren
    genebren over 4 years ago in reply to ralphjy +1
    Ralph, I have looked through the datasheet and through the SparkFunBQ27441 library and I am completely confused. The library does not seem to match the datasheet. There is a lot to be confused about, as…
  • ralphjy
    ralphjy over 4 years ago in reply to genebren +1
    Gene, Thanks for taking a look. I definitely want to get to the bottom of this, but it will have to wait a bit. This was supposed to be a quick diversion from working on Vibration Sensor data. I guess…
  • genebren
    genebren over 4 years ago in reply to ralphjy

    Good luck!  Let me know if you need any help or come up with any good solutions.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 4 years ago in reply to genebren

    Gene,

     

    Thanks for taking a look.  I definitely want to get to the bottom of this, but it will have to wait a bit.  This was supposed to be a quick diversion from working on Vibration Sensor data.  I guess even supposedly simple things are never quick image.  Maybe the library has some mistakes.  I'll try posting later on the SparkFun forum if I can't figure it out.

     

    Ralph

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 4 years ago in reply to ralphjy

    Ralph,

     

    I have looked through the datasheet and through the SparkFunBQ27441 library and I am completely confused.  The library does not seem to match the datasheet.  There is a lot to be confused about, as there are multiple 'Capacity' variables and given the offsets I see in the library it looks like they are setting the 'FullAvailableCapacity' as opposed to the 'DesignCapacity'.  Also in looking at their attempt to set the capacity, they seemed to be attempting to write to 'FullAvailableCapacity' without checking and/or setting the 'SEALED/UNSEALED' mode, which protects the 'FullAvailableCapacity' register.

     

    Some of this might explain why the 'StateOfHealth' is looking a bit off.  I don't know how deep you want to dive into this, but here is the technical reference document number (SLUUAC9A) that shows a lot more information on the internal registers of the BQ27441 device.

     

    Good luck,

    Gene

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to ralphjy

    ralphjy  wrote:

     

    ... I'd also not encountered PMICs until having to reprogram one on the Ultra96v2 board.  Now I see PMICs being used on even low cost boards and I'll probably want to use those and these fuel gauges in battery powered circuits that I might design in the future.

    A while ago, when rscasny asked what would be interesting road test, I suggested power management devices. I think they are interesting devices.

    Re: RoadTest request: ICs that manage the power up sequence of a board

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 4 years ago in reply to Jan Cumps

    I haven't used a battery fuel gauge before, but I'd also not encountered PMICs until having to reprogram one on the Ultra96v2 board.  Now I see PMICs being used on even low cost boards and I'll probably want to use those and these fuel gauges in battery powered circuits that I might design in the future.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube