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
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.
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); }
Top Comments