Introduction: Make Your Pi Project Rechargeable...
The following aims to show how to make any Raspberry Pi project battery powered and rechargeable***. This isn't quite as easy as it should be because the Raspberry Pi requires just over 5VDC to operate properly. (It really wants 5.2 to 5.25 volts.) So we need to take the battery voltage of 3.7V and boost it to 5.2V. (Alternatively one could use a 7.2V battery and buck it down to 5.2V.) We also need a circuit to charge the battery. Luckily there are a couple of products that include both in one module. The one we're using here is the powerboost 1000C from Adafruit. It has an output of 5.2VDC which is perfect for the Raspberry Pi and has a 1 amp charging circuit (via micro USB) to recharge our battery without having to unplug it.
What you need-
- Powerboost 1000C boosting converter and charge controller
- 2500 mAh (or greater) 3.7V lipo batterywith JST-PH connector
- Raspberry Pi 2 (or B+)
- micro-USB cable (or solderable micro-USB male plug end)
- SPST Switch (optional) hard power switch for thr Powerboost
- SPST momentary push-button (optional) soft-reset/test of low battery script
- 1k-3.3k resistor (optional) load limiting resistor for low battery trigger
- small breadboard or PCB
- dupont patch wires (various)
***Another way is to connect a USB power pack to the Raspberry Pi. However, I have found this approach less than satisfactory for the Raspberry Pi... Most of the USB battery packs I see put out between 4.85 and 5 VDC. As mentioned above, the Pi requires slightly over 5 VDC. So what usually happens is that the Pi boots, but the little 'rainbow square' appears in the upper right corner of the display (see photo). This square indicates that the Pi is under-powered. Running the Raspberry Pi like this can cause anything from system instability to hardware damage. Notably damage to the SoC can occur from repeated under-powering. If you are going to use an 'off the shelf' USB battery for your pi try to find one that puts out 5.2-5.25VDC.
Step 1: Configure the Power Connection to the Pi
There are 2 possible ways to do connect the Powerboost to the Raspberry Pi -
- You can solder the USB A socket to the powerboost. (The module comes with the USB socket. But it's not soldered on.) If you choose this option then you can simply use any micro-USB cable to run your Pi.
- Solder the output of the Powerboost to the power +/- of a micro-USB plug. (see photo above). If you choose this option the the powerboost will plug directly into the Raspberry Pi micro-USB port. You can use an old Micro-USB cable and splice it to the Powerboost as shown. Power wires for the cables are usually red/black for +/-
Note - While it is possible to power the Raspberry Pi via the GPIO connector I do not recommend it as it bypasses the power protection circuitry of the Raspberry Pi. (i.e. the 5V pin of the GPIO connects directly to the SOC. See this thread on Stack Exchange.)
Once you've got this set up, unplug it. Once the battery is plugged in we will want to test the output voltage before plugging in the Pi for the first time.
Step 2: Connect the Control Pins (Optional)
You can optionally connect one or more of the control pins for the PowerBoost. The two pins you can use are -
- EN - this pin is pulled high internally by default. You can connect a SPST switch to this pin and ground to create a 'power off' switch.
- LBO - This pin is pulled high by default. But if the Powerboost senses low battery voltage, it goes to zero. Connect it to the digital GPIO pin of your choice via a 1K resistor to warn your Raspberry Pi when the battery is running low! Once you've got that connected you can download the 'off_button.py' script form this nice instructable and follow the instructions there to install the software, specifying the GPIO pin connected to LBO where the script says YOUR_CHOSEN_GPIO_NUMBER_HERE
Step 3: Connect and Charge the Battery
Now you can connect the battery to the Powerboost via the JST plug on the Powerboost. At this point the circuit is mostly complete. But if your battery is new I recommend charging it fully before proceeding to the next step. You can do this by plugging a USB charger into the micro-USB plug on the powerboost. If you have connected everything correctly, the yellow LED on the Powerboost will light to indicate charging. The light will turn green when the battery is fully charged.
AFA battery capacity, my personal experience is that the Powerboost + Pi + Wifi + keyboard ( + whatever else I plug in) uses around 1200-1500mA per hour during fairly heavy real-world usage. So a 5000mAH 3.7V flat pack battery is good for about a half-day of heavy usage or up to a full day of light usage if power saving is configured on the pi.
Step 4: Testing
Now we're ready to do some final testing before we plug in the Raspberry Pi. If all has gone well you should have a charged battery connected to the Powerboost. If you have installed a power switch turn it on and use a multimeter to test the powerboost voltage out (at the red/black wire on the right hand side in the photo above). It should read somewhere near 5.2VDC. If it doesn't have any or enough voltage out then check the following -
- double-check all connections and look for loose connections, solder bridges or short circuits.
- battery voltage should be at least 3.7VDC
- Low voltage will be indicated by a rainbow square in the upper right corner of the HDMI display for the raspberry pi (see picture).
- the Powerboost voltage out should be 5.2VDC (If the voltage is less than 5VDC then you may be drawing too much power. )
- the EN pin must be HIGH for normal operation.If it shorts to ground the power supply will turn off.
- If the LBO pin is low then the battery is low and must be charged. If you have connected the LBO pin to the Pi and set up the off_button.py script then the pi should power off automatically when the low-battery alert triggers.
There are 4 LEDs on thePowerboost which indicate different states and can help troubleshoot any issues.
- When the Boost 5VDC supply is on the blue LED will light up
- When charging the yellow LED will light up
- When charged the green LED will light up
- When the Battery is low the red LED will light up
Step 5: Fire It Up!
Now if all is well, you should be able to connect the Raspberry Pi (and flip the power switch if you included one in your project.) The pi should boot normally. If so, Congratulations! You now have a battery powered Raspberry Pi. To recharge simply take the USB power supply you used to power your pi with and plug it into the micro-USB port of the Powerboost instead.
If the Pi fails to boot or if the 'low voltage' warning* appears in the top right corner of the hdmi display then stop, go back and test the voltage with the pi connected, paying attention to the troubleshooting tips in the previous step.