Video of project:
The features and functions of this device are:
- Adjustable charge voltage and current with a battery store mode
- Adjustable boost voltage and current
- SSD1306 OLED display
- Rotary encoder for menu selection
- Low battery charge mode
- Reverse battery polarity protection using MOSFETs
- 3 AMP Fast Charge current and 2 AMP powerbank output
- USB C, Type A and Micro ports
- NTC thermistors for the battery and IC temperature monitoring
- ICSP header
- Buzzer for audio feedback
- Low power mode and full auto power off mode
- Heatsink to dissipate the 3 AMP of charging switching loss
- WS2812B indicator LEDs
A lot of the features are autonomous and if desired can be changed via the code. The BQ25896 is controllable and configurable via I2C, and has 15 Register Maps and the driver library has references to all of them.
The image below shows the simplified schematic of a charger circuit, this particular version of the IC the VBUS and OTG out share the same pin. The driver library can be adapted to use with other BQ2589x ICs.
According to the Texas Instruments datasheet these are features of the IC:
- 92.5% Charge Efficiency at 2 A and 90.5% Charge Efficiency at 3 A Charge Current
- USB On-the-Go (OTG) with Adjustable Output from 4.5 V to 5.5 V with up-to 2 A Output
- 93% Boost Efficiency at 5 V at 1 A Output
- Support down-to 2.5V Battery
- Integrated ADC for System Monitor (Voltage, Temperature, Charge Current)
- ±0.5% Charge Voltage Regulation, ±5% Charge Current Regulation, ±7.5% Input Current Regulation
An Atmel ATMEGA32U4 MCU is used to send commands to the BQ25896, during bootup a sequence commands are sent to set the IC to a baseline. After that the rotary encoder can be used to change some of the settings. All settings are saved to EEPROM. As there is only 28KB of usable flash I was unable to make fancy battery level indicators, in hindsight I should have used an ATSAMD21.
The voltage for the ATMEGA32U4 and the OLED is supplied via BAT/SYS, when there is a USB input VSYS is maintained at VSYS_MIN (3.6V). When running on battery it tracks the battery voltage, so it does mean VSYS can drop to as low as 2.9V, as the MCU and OLED are fed via the 3.3V LDO the voltages can drop very low.
The safe operating area for the ATMEGA32U4 is as low as 2.7V when running at 8MHz. The SSD1306 OLED voltage range is 1.65 - 3.3V.
I have tested this and seems to operate ok at these low voltages, but there were a couple of times when the battery dropped below 3.1V and when in BOOST mode with 2A being drawn the MCU malfunctioned.
Arduino IDE .INO File
The .INO file can be found in the Release folder of the Github repository, the code has a lot of comments. I used Zadig to load a driver and then used the ICSP header to load the SparkFun Pro Micro bootloader. After that the device is recognised via the MicroUSB port on Windows10/11.
After compiling the sketch uses the following program space:
Sketch uses 28536 bytes (99%) of program storage space. Maximum is 28672 bytes.
Global variables use 1105 bytes (43%) of dynamic memory, leaving 1455 bytes for local variables. Maximum is 2560 bytes.
The following libraries used, the Adafruit SSD1306 library needs to be edited to remove the splash screen, mask out #include "splash.h" in file Adafruit_SSD1306.cpp, otherwise it does not fit the ATMEGA32U4.
#include <Wire.h>
#include <EEPROM.h> // v2.0 | https://github.com/PaulStoffregen/EEPROM
#include <BQ2589x.h> // v1.0 | https://github.com/Ratti3/BQ2589x
#include <FastLED.h> // v3.5.0 | https://github.com/FastLED/FastLED
#include <TimerOne.h> // v1.1.1 | https://github.com/PaulStoffregen/TimerOne
#include <LowPower.h> // v2.2 | https://github.com/LowPowerLab/LowPower
#include <AbleButtons.h> // v0.3.0 | https://github.com/jsware/able-buttons
#include <BasicEncoder.h> // v1.1.4 | https://github.com/micromouseonline/BasicEncoder
#include <Adafruit_GFX.h> // v1.11.5 | https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h>...
Read more »