I have a simple project setup to learn how to use the battery babysitter. For the most part, the project works. Here’s what I’ve designed:
Battery baby sitter hooked up to an Arduino Nano, an OLED screen and a tri-color LED.
The battery baby sitter is hooled up to a 1000mAh LiPo battery. The LED is programmed to shine green for 90% to 100% charge, blink blue for 20% to 90% charge, shine yellow for 10% to 20% charge, and shine red for 0% to 10% charge. The OLED display simply displays the % charge so I can roughly gauge when to expect the LED to change status.
Problem:
Everything works fine except after the battery runs out. When I plug in a USB cable to the battery babysitter to charge the battery again, I noticed that the battery doesn’t charge as long as the Battery Babysitter Vout is connected to the Arduino Nano Vin. And also, the project simply doesn’t power up will the USB charge cable is connected.
I attached a picture of the setup and the code.
https://sherekaan.files.wordpress.com/2 … 173740.jpg/******************************************************************************
BQ27441_Basic
BQ27441 Library Basic Example
Jim Lindblom @ SparkFun Electronics
May 9, 2016
https://github.com/sparkfun/SparkFun_BQ27441_Arduino_Library
Demonstrates how to set up the BQ27441 and read state-of-charge (soc),
battery voltage, average current, remaining capacity, average power, and
state-of-health (soh).
After uploading, open up the serial monitor to 115200 baud to view your
battery's stats.
Hardware Resources:
- Arduino Development Board
- SparkFun Battery Babysitter
Development environment specifics:
Arduino 1.6.7
SparkFun Battery Babysitter v1.0
Arduino Uno (any 'duino should do)
******************************************************************************/
// SDA goes to D2
// SCL goes to D1
#include <SparkFunBQ27441.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//define pins
#define D0 16
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as "LED_BUILTIN", but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0 (Serial console)
#define OLED_MOSI 2 //D1 on display [2 is D4 on ESP2866]
#define OLED_CLK 0 //D0 on dispale [0 is D3 on ESP2866]
#define OLED_DC 14 //[14 is D5 on ESP2866]
#define OLED_CS 10 // [10 is SD3 on ESP2866]
#define OLED_RESET 16 // [16 is D0 on ESP2866]
// Set BATTERY_CAPACITY to the design capacity of your battery.
const unsigned int BATTERY_CAPACITY = 1000; // e.g. 850mAh battery
int pinD6 = D6; // RED LED
int pinD7 = D7; // GREEN LED
int pinD8 = D8; // BLUE LED
unsigned long timer_prev = 0;
unsigned long timer_curr= 0;
int LEDstate = HIGH;
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
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!)");
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);
display.print("Charge %: ");
display.print(soc);
}
void setup()
{
Serial.begin(115200);
setupBQ27441();
pinMode(pinD8, OUTPUT); //D6 is RED
pinMode(pinD6, OUTPUT); //D7 is GREEN
pinMode(pinD7, OUTPUT); //D8 is BLUE
display.begin(SSD1306_SWITCHCAPVCC);
display.display();
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
}
void loop()
{
display.clearDisplay();
display.setCursor(0,0);
printBatteryStats();
unsigned int soc = lipo.soc();
if (soc <= 100 && soc >= 90){
digitalWrite(pinD7, LOW);
digitalWrite(pinD6, HIGH);
digitalWrite(pinD8, HIGH);
}
else if (soc < 90 && soc >= 20){
//digitalWrite(pinD8, HIGH);
digitalWrite(pinD7, HIGH);
digitalWrite(pinD6, HIGH);
timer_curr = millis();
if(timer_curr - timer_prev >= 2000){
timer_prev = timer_curr;
if (LEDstate == HIGH){
LEDstate = LOW;
}
else{
LEDstate = HIGH;
}
digitalWrite(pinD8, LEDstate);
}
}
else if (soc < 20 && soc >= 10){
digitalWrite(pinD7, LOW);
digitalWrite(pinD6, LOW);
digitalWrite(pinD8, HIGH);
}
else if (soc < 10){
digitalWrite(pinD7, HIGH);
digitalWrite(pinD6, LOW);
digitalWrite(pinD8, HIGH);
}
display.display();
}