Charge ‘n Boost: Arduino IDE Programmable Powerbank
Build your own powerbank!
Tell it to charge at 1A, 2A or even 3A. Charge your phone. Power a Raspberry Pi. Make it shutdown. Make it wake on USB load, button press or timer. Keep it alive forever. Connect an I2C OLED display. Use the RGB leds to display capacity in color-code or simply use individual leds. Send and receive serial data/commands to and from an Arduino or Pi. Switch on or off USB powered devices. Program a torchlight. Code an RGB led charging animation… The possibilities are endless.
Features:
- 3.2A synchronous lipo charge IC, automatic USB input rating detection, 4-14V input
- 3.5A 5V USB boost IC (5.1V or 5.5V output)
- Dynamic power path management: When input is connected a USB load is prioritized over charging. When input is sufficiently rated both the load and battery can be powered. When an input is insufficiently rated for current load, the battery will go into load supplement mode.
- On-board programmable Atmega328p
- On-board fuel gauge
- Automatic USB adapter current rating recognition
- BC1.2 USB controller IC on output
- 1 addressable RGB led, led-data pin and 5v MOSFET switched supply pin broken out, extend by up to 1A of additional WS2812B leds
- 1 tactile button
- Fully featured library for Arduino IDE, a few lines of code will setup your powerbank
Program (using serial or ISP programmer or even an Arduino):
- Max input current (500mA up to 3250mA)
- Max charge current (500mA up to 5000mA! Anything over 3A will require active cooling)
- USB boost output voltage: 5.1V or optionally 5.5V
- Independently enable/disable charger IC
- Independently enable/disable USB boost output
- Deepsleep shutdown (45uA sleep)
- Interrupt wake on button, USB load or INT pin
- 3 RGB WS2812b leds, individually addressable
- Slide switch functionality, 3 positions
- Tactile button functionality
Digitally monitor:
- Input current
- Charge current
- Output current
- Input voltage
- Charging status (precharge, fastcharge, charging done, not charging)
- USB Input type (SDP, CDP, DCP, or High voltage adaptive fastcharge @ 9 or 12V)
- Battery percentage
- Battery voltage
- Battery temperature
- Slide switch position
- Button press
Safety:
- Reverse polarity battery protection
- Automatically detect current rating USB input
- Undervoltage battery FET disconnect
- Overvoltage battery FET disconnect
- Boost IC under voltage lockout
- Battery temperature monitor, battery will disconnect on NTC over- and undertemp
- USB output overcurrent protection
- Thermal shutdown protection for both charge and boost IC’s
- Watchdog timer
Broken out I/O and power:
- SDA/SCL, attach 3V logic compatible I2C devices (OLED 0.96 display succesfully tested!)
- Hardware Serial pins
- Interrupt pin internally connected to button and charger IC interrupts
- 3V linear regulator pin
- 5V output voltage pin
- Two GND pins
- ISP connector
- Reset pin with timing capacitor (connect Serial programmer with auto reset, user will need to burn Arduino bootloader through ISP)
Price
Not set yet but aiming at Kickstarter $35 – $45 pricepoint for assembled 65x40mm units. V1.0 and V2.0 have been tested succefully, V3 kinks excluded is on the way. Two ounce copper, ENIG finish.
Keep posted or check my twitter for launch day (currently waiting on final version PCB, working on video)!
Library functions
Powerbank mypb
Description
Create an instance of Powerbank class, name it anything, in this case ‘mypb’. Place outside of loop/setup.
mypb.init( int fastChargeCurrent );
Description
Enables charge IC. Enables Boost IC. Resets all charger registers to default value. Sets battery fastcharge current limit. Begins Atmega328P I2C. Sets Atmega328P ADC reference to internal 1.1V. Typically placed in setup.
Parameters
fastChargeCurrent: Set battery fast charge current limit (500 – 5000mA). fastChargeCurrent is automatically limited by detected USB input current rating and/or slide setting battery charge current limit. The lower of which is set as the limit.
Returns
None
mypb.resetWatchdog();
Description
Resets charger IC watchdog timer and re-enables charging function. Function must be called every 40 seconds (or less). Safety feature. In the unlikely event of microcontroller failure with I/O at hi-Z, charging and boosting functions are disabled. In the event of microcontroller failure with charge-enable output LOW, charge IC will reset to standalone mode (2A charging).
Parameters
None.
Returns
None.
mypb.getInputCurrent();
Description
Gets current flowing into device.
Parameters
None.
Returns
Input current in mA (int).
mypb.getChargeCurrent();
Description
Gets current flowing into battery. Value is retrieved using BQ25895’s internal 7 bits ADC. Reading is battery charge current only, discharge current is not monitored.
Parameters
None.
Returns
Charge current in mA, 50mA resolution (int).
mypb.getBatteryLevel();
Description
Gets current battery level. Value is retrieved over I2C from fuel gauge.
Parameters
None.
Returns
Battery relative state of charge as a percentage (byte).
mypb.getOutputCurrent();
Description
Gets boost regulator (usb output) current. Current is calculated using Atmega328p internal 1.1V voltage reference and boost regulator constant current pin regulating to 1.244V at full current output.
Parameters
None.
Returns
Output current in mA (0.0 – 3500.0, float).
mypb.getBatteryVoltage();
Description
Gets battery voltage from fuel gauge over I2C.
Parameters
None.
Returns
Battery voltage in mV (unsigned long).
mypb.getVbusVoltage();
Description
Gets voltage on charger input. 7 Bits Value retrieved from charger IC over I2C.
Parameters
None.
Returns
Voltage on charger input in mV, range 2600 – 15300mV (100mV resolution, unsigned int).
mypb.getBatTemp( int betaValue, boolean setting );
Description
Gets the temperature from thermistor. Make sure the thermistor bead is placed as close to the battery as possible. Note: The charge IC will constantly monitor battery temperature, when out of temperature bounds (0° – 45° C), charge functions will cease.
Parameters
betavalue: the betavalue of the 10K NTC thermistor at room temperature (25° C). This value can be found in your thermistor’s datasheet and is used by a simplified Steinhart Hart equation to calculate temperature based on BQ25895’s voltage reading at the TS pin. setting: False for Kelvin or True for Celsius.
Returns
Temperature in degrees Kelvin or Celsius (byte).
mypb.getChargeStatus();
Description
Checks current charge status.
Parameters
None.
Returns
Returns corresponding charge status value (byte):
0 = Not charging
1 = Pre-charge
2 = Fast charging
3 = Charge termination done
mypb.getVbusInputType();
Description
Checks detected charger input type. Detection is done automatically by charger IC and stored in one of its registers.
Parameters
None.
Returns
Returns corresponding input type value (byte):
0 = No input
2 = USB CDP (1.5A)
3 = USB DCP (3.25A)
4 = Adjustable High voltage DCP (1.5A, Quickcharge)
5 = Unknown Adapter
6 = Non Standard adapter
mypb.btnPressed();
Description
Polls for button press (button is connected to hardware interrupt pin (PD3), buttonpress detect is possible without polling but will need to be coded manually).
Parameters
None.
Returns
True if button is pressed (boolean).
mypb.highVoltageMode( boolean setting );
Description
Sets boost regulator output to 5.5V instead of default 5.1V. Useful when expecting significant voltage drop at higher output current (usb contact resistance, cable resistance etc). Calculate your estimated voltage drop using this nifty calculator.
Parameters
setting (boolean): True will enable high voltage output, false will return to default 5.1V.
Returns
None.
mypb.sleepBtnWake();
Description
Forces charger, microcontroller and fuel gauge into sleep mode. Mosfet separating charger and attached battery is turned off. Charger IC is set to Hi-Z mode. Microcontroller is set to sleep mode. Fuel gauge IC set to sleep mode. Wake interrupts are attached to button press and charger interrupt. When device exits sleep mode after interrupt (button press or BQ25895 interrupt i.e. Vbus attach), a full Atmega328P reset is executed (reset after 15 ms watchdog expires), essentially restarting from start of sketch with all microcontroller registers reset. Current consumption is reduced to 45uA.
Parameters
None.
Returns
None.