Description
LiPo Shim for Raspberry Pi Pico
This handy product from our pals at Pimoroni provides a convenient way of powering your Raspberry Pi Pico from a LiPo/LiIon battery. You can recharge the battery easily by providing power to the Pico's USB port.
- MCP73831 charger with 215mA charging current (datasheet)
- XB6096I2S battery protector (datasheet)
- Power button
- 2-pole JST PH connector, with polarity marked on the board
- Power and charging LED indicators
- Compatible with Raspberry Pi Pico.
- Soldering required.
- Dimensions: approx 21mm x 21mm x 7mm (L x W x H, including connectors)
- Schematic
Getting started
You'll need to solder the SHIM to the back of your Pico, with the power button at the same end as the USB port. The text on the SHIM and the pin labels on the back of the Pico should be facing each other.
Software
You can use LiPo SHIM for Pico with any Pico OS as it doesn't require any software installing to work.
We've put together a MicroPython example showing how you can read the system voltage from Pico's VSYS pin to estimate how much charge is left in the battery, and display it on Pico Explorer or Pico Display:
[code language="python"]
# This example shows how to read the voltage from a lipo battery connected to a Raspberry Pi Pico via our Pico Lipo SHIM, and uses this reading to calculate how much charge is left in the battery.
# It then displays the info on the screen of Pico Display or Pico Explorer.
# Remember to save this code as main.py on your Pico if you want it to run automatically!
from machine import ADC, Pin
import utime
import picodisplay as display # change "picodisplay" to "picoexplorer" if you're using a Pico Explorer
# Set up and initialise display
buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
display.set_backlight(0.8) # comment out this line if you have a Pico Explorer as it doesn't have a controllable backlight
vsys = ADC(29) # reads the system input voltage
charging = Pin(24, Pin.IN) # reading GP24 tells us whether or not USB power is connected
conversion_factor = 3 * 3.3 / 65535
full_battery = 4.2 # these are our reference voltages for a full/empty battery, in volts
empty_battery = 2.8 # the values could vary by battery size/manufacturer so you might need to adjust them
while True:
voltage = vsys.read_u16() * conversion_factor
percentage = 100 * ((voltage - empty_battery) / (full_battery - empty_battery))
if percentage > 100:
percentage = 100.00
# draws the battery
display.set_pen(0, 0, 0)
display.clear()
display.set_pen(190, 190, 190)
display.rectangle(0, 0, 220, 135)
display.rectangle(220, 40, 20, 55)
display.set_pen(0, 0, 0)
display.rectangle(3, 3, 214, 129)
display.set_pen(0, 255, 0)
display.rectangle(5, 5, round(210 / 100 * percentage), 125)
# adding text
display.set_pen(255, 0, 0)
if charging.value() == 1: # if it's plugged into USB power...
display.text("Charging!", 15, 55, 240, 4)
else: # if not, display the battery stats
display.text('{:.2f}'.format(voltage) + "v", 15, 10, 240, 5)
display.text('{:.0f}%'.format(percentage), 15, 50, 240, 5)
display.update()
utime.sleep(1)
[/code]
Notes
- The power button can also be used as a reset button, yay! Just double press it to cut and reinstate the power whilst holding down the BOOTSEL button on the Pico to get into bootloader mode, with no plugging and unplugging of cables required.
- Because Pico Display has a chunky display connector on the underside you might have difficulty sandwiching the SHIM underneath if your Pico's header pins are on the shorter side. We'd suggest picking up some longer stacking headers or a Pico Omnibus / Pico Decker if you want to use this SHIM with Pico Display.
- Alternatively, if you're ambitious in the ways of experimental soldering, you can try soldering the Pico and the SHIM both to the short end of your header, back to back. This method makes for a much more slimline Pico/SHIM package which works nicely with Pico Display, but you'll need to make sure your solder joints make good contact with the pads of both boards and the header.
About Raspberry Pi Pico
Raspberry Pi Pico is a flexible, low cost microcontroller development board from the folks at Raspberry Pi, based on their very own chip - the RP2040. It's easily programmable over USB with C/C++ or MicroPython, and ideal for using in all sorts of physical computing projects, devices and inventions - we're so excited to see what you make with it!
Your Pico will need to have male headers soldered to it (with the pins pointing downwards) to attach to our add-on boards.