Overview:
While browsing the internet, you’ll come across numerous UPS (Uninterruptible Power Supply) Power Bank designed for Raspberry Pi Boards. However, I’ve discovered that many of them are not genuine. A significant number face power failure issues, while others lack an adequate Battery Management System Circuit. Additionally, several boards have problems with balanced charging and battery protection mechanisms. SunFounder’s Raspberry Pi UPS Power Supply Board addresses and rectifies these concerns.
The SunFounder UPS Power Supply for Raspberry Pi offers a comprehensive UPS solution for Raspberry Pi 3/4 Model B/B+. The kit includes a PiPower board, a 2,000 mAh battery, and all necessary assembly accessories. Additionally, it’s compatible with other boards similar in size to Raspberry Pi that accept a 5V DC input.
In this article, we will unbox, assemble and test the Raspberry Pi UPS Power Bank from SunFounder. We will also write a sample Python Code to Send the Battery Status data to Blynk Server. The Blynk Server will show the status of USB Power, Battery Charging, Sufficient Charge status as well as Low Battery Alert status.
Why do we need UPS Power Bank?
If your Raspberry Pi project needs constant power source, relying only on the main power source isn’t advisable. Power inconsistencies, like drops and surges, can be common in certain areas, sometimes lasting for extended periods. These fluctuations can harm your Raspberry Pi, and an abrupt power loss can shut it down unsafely, risking the loss of all data on the SD card and potentially damaging it.
Thus, employing an uninterruptible power supply (UPS) is wise.
A UPS ensures that in the event of a power outage, a battery or alternate power source kicks in, preventing the device from shutting down. Essentially, a UPS acts as a backup power solution. Once the primary power is restored, the UPS recharges, preparing for any future power disruptions.
SunFounder Raspberry Pi UPS Power Supply
The SunFounder Raspberry Pi UPS Power Supply comes with a Battery, 5V/3A Power Bank Expansion Board which is compatible with Raspberry Pi 4B/3B+/3B/Zero 2 W/Zero W.
PiPower serves as an alternative power source for the Raspberry Pi. When a USB-C main adapter is connected to the PiPower, it not only charges its battery with a gentle current but also directly powers the Raspberry Pi. Should there be a power interruption or if the USB-C main power is detached, PiPower ensures uninterrupted power to the Raspberry Pi.
PiPower delivers a 5V/3A energy output suitable for diverse Raspberry Pi requirements. It features four energy indicators, with each light signifying 25% battery capacity. Additionally, there’s a built-in switch, eliminating the need to connect or disconnect cables to manage the Raspberry Pi’s power. Use Battery Capacity Tester to calculate Battery Capacity.
Raspberry Pi UPS Power Supply Key Features
- UPS module output – 5V/3A via USB Type-A port
- Battery charge – up to 5V/2A MAX
- Can power the Pi and charge the battery simultaneously
- Power Supply – 5V/3A via USB Type-C port
- Battery – 7.4V/2,000mAh. battery life: 3-4 hours
- Battery protection – Overcharge/discharge protection, balance charging, and overheating protection.
- Misc
- On/Off switch
- Power LED
- Charging LED
- 4x battery-level LEDs
- Header to monitor battery
- Dimensions – 90 x 56 x 24 mm
Unboxing the PiPower
The Raspberry Pi UPS Power Bank can be purchased from the Sunfounder PiPower link.
The kit includes the PiPower board, a screwdriver, assorted screws, standoffs, and cable ties.
Additionally, there are short USB-C and micro USB cables, double-sided tape, an acrylic panel, a quick setup guide, and a battery.
The PiPower utilizes the IP2326 lithium battery charging integrated circuit. Its underside features a space for the battery, a 3-pin connector for battery input, a power toggle, a GPIO header for battery status tracking, and headers that offer access to 5V and GND, which can be used to energize other devices.
The GPIO provides the following signals
- GND – Ground
- BT_LV – Battery voltage pin. The voltage of this pin is equal to 1/3 of the battery voltage.
- IN_DT – Input detect pin. Used to determine if there is USB power input, if so, this pin outputs high.
- CHG – Charging status indication pin. This pin is high when charging.
- LO_DT – Low voltage status pin. When the voltage is high enough, this pin is low, but when low battery voltage is detected, this pin is high.
- EN – Switch signal pin. The EN pin can be connected to an external switch, so the PiPower is powered off when the pin is set to 0. The EN pin is only active when the PiPower is turned on.
- GND – Ground
- LED – Power indicator pin. Output 5V at power on. Note a resistor must be added when connecting an external LED.
- GND – Ground
Assembly of PiPower
The Kit has an instruction manual that could help in assembling the Raspberry Pi Power Bank parts.
The Assembly process is very easy and would just take 5-10 minutes.
Once the assembly is done, the kit looks portable with a proper stand.
The battery is attached to the board with a double-sided tape and covered with transparent acrylic.
You can solder 9-pin male header pins to the PiPower Board. These pins can be connected to the GPIO Pins of Raspberry Pi in case you wanna communicate about the Battery status with Raspberry Pi.
Battery Charging & Discharging Test
The Battery provided with “SunFounder UPS Power Supply for Raspberry Pi” has a Nominal Voltage of 7.4V with a capacity of 2000mAh. According to the manufacturer, the battery would last for 3-4 hours.
Therefore I conducted the Battery discharge test. Initially, I charged the battery to full. In order to discharge the battery I connected 2 high-power DC motors across the 5V & GND pin of Raspberry Pi.
I observed that the battery discharging took 3 hours and 15 minutes. In the end, the Raspberry Pi completely shut down. This test was conducted under heavy load conditions. The battery life would be better in case, the Raspberry Pi is operated on normal mode. Some tests conducted showed the battery life is for 4 hours under low to moderate use.
In order to charge the Battery, plug a 5V USB Cable into the Raspberry Pi Type C-port, and the battery charging will start. The charging power is 7W, and it takes about 2 hours to charge from 0% to 100%.
There are 4 LED indicators (D4 ~ D7) that indicate Battery Level.
How to Monitor the Battery with Blynk Server?
I’ve soldered a GPIO header onto the PiPower board to make use of its battery monitoring pins. The LO_DT pin will help in identifying when the battery voltage is low, the CHG pin will indicate if the battery is in charging mode, and the IN_DT pin will reveal if the power is connected. While the BT_LV pin can determine the battery level, it necessitates an extra ADC chip.
In order to monitor the PiPower Battery with Raspberry Pi, we need some GPIO Connections to the PiPower Kit as follows:
- IN_DT to GPIO 23
- CHG to GPIO 24
- LO_DT to GPIO 25
- GND to GND
To monitor the Battery status online, I choose Blynk Cloud Server.
Setting Up Blynk Application
Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can simply sign in using the registered Email ID.
Click on +New Template.
Give any name to the Hardware such as “Battery_Monitor“. Choose the Hardware type as Raspberry Pi and the connection type as WiFi.
Now we need to set up Datastreams. Therefore Click on +New Datastreams and Select Virtual Pin.
Create datastreams for USB Power, Battery Charging, Low Battery, and Sufficient Charge and assign the virtual pins as V0, V1, V2 & V3 respectively.
Now go to the Dashboard section and set up the dashboard.
For USB Power, Battery Charging, Low Battery, and Sufficient Charge, link all the widgets with the datastreams and click on save.
Go to the Home and click on Add Device. Name the Device “Battery Monitor” and Click on Create.
After the device is successfully created, you will get the device ID and Authentication Token. The Authentication Token will be used in the code.
Python Code to Monitor Battery Status on Blynk
To monitor the battery data on Blynk Server, we need to develop a Python Code first.
Before going to the coding part, first, install a “Blynk Library“.
Go to Terminal and type the following command.
|
1 |
git clone https://github.com/vshymanskyy/blynk-library-python.git |
Now open Thonny IDE, and copy the following code. Save the file inside the Blynk library Folder.
In this code, change the Blynk Authentication Token from your Blynk ID.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import BlynkLib import RPi.GPIO as GPIO from BlynkTimer import BlynkTimer # Import BlynkTimer BLYNK_AUTH_TOKEN = '**********************' # Change the Blynk Auntentication Token here # Define GPIO pins IN_DT = 23 CHG = 24 LO_DT = 25 GPIO.setmode(GPIO.BCM) GPIO.setup(IN_DT, GPIO.IN) GPIO.setup(CHG, GPIO.IN) GPIO.setup(LO_DT, GPIO.IN) # Define Virtual Pins in Blynk App USB_POWER_VPIN = 0 CHARGING_VPIN = 1 BATTERY_LOW_VPIN = 2 BATTERY_STATUS_VPIN = 3 # New virtual pin for battery status # Initialize Blynk and BlynkTimer blynk = BlynkLib.Blynk(BLYNK_AUTH_TOKEN) timer = BlynkTimer() # Function to update battery status on Blynk def update_battery_status(): if GPIO.input(IN_DT) == 1: blynk.virtual_write(USB_POWER_VPIN, 1) print('USB Power detected') else: blynk.virtual_write(USB_POWER_VPIN, 0) print('No USB power. Power failure?') if GPIO.input(CHG) == 1: blynk.virtual_write(CHARGING_VPIN, 1) print('Battery is charging...') else: blynk.virtual_write(CHARGING_VPIN, 0) print('Battery is not charging...') if GPIO.input(LO_DT) == 1: blynk.virtual_write(BATTERY_LOW_VPIN, 1) blynk.virtual_write(BATTERY_STATUS_VPIN, 0) # 0 indicates low battery print('Low battery level detected!') else: blynk.virtual_write(BATTERY_LOW_VPIN, 0) blynk.virtual_write(BATTERY_STATUS_VPIN, 1) # 1 indicates battery has sufficient charge print('The battery has sufficient charge.') # This function will be called when Raspberry Pi connects to Blynk @blynk.on("connected") def blynk_connected(): print("Raspberry Pi Connected to New Blynk") # Start a timer that calls update_battery_status every 5 seconds timer.set_interval(5, update_battery_status) while True: blynk.run() timer.run() # Run BlynkTimer to execute any scheduled tasks |
Monitoring the Raspberry Pi UPS Battery
Run the above code, and observe the Thonny Shell.
The Thonny will show the following message when the Battery is not charging.
It will show the Battery is not charging and No USB Power is detected. If the battery charge is sufficient, it will show sufficient charge.
You may observe the same data on Blynk Dashboard.
When the Battery charge is sufficient, the Yellow indicator will light up.
While the Battery is charging through USB Power, it will show the following indications.
When the battery is low and in the discharging state, the Red lamp indicator will turn on.
You may unplug and plug the battery charger to observe the different lamp indications.
Similarly you may set up the “Blynk Mobile Dashboard” and observe the same thing.
This is how you can monitor the battery using Raspberry Pi & use indications on Blynk Server or Blynk Dashboard.
Conclusion
In conclusion, the SunFounder UPS Power Supply for Raspberry Pi provides a holistic UPS solution suitable for Raspberry Pi 3/4 Model B/B+. Not only does the kit come complete with the PiPower board, a 2,000 mAh battery, and all required assembly tools, but it’s also versatile enough to work with boards of a similar size to Raspberry Pi that needs a 5V DC input. Throughout this article, we explored the unboxing, assembly, and testing process of this UPS Power Bank, delving into its functionalities. We also demonstrated how to use Python to send battery status data to the Blynk Server, ensuring users are always updated on USB power, charging status, charge sufficiency, and low battery warnings.


































2 Comments
Hi. Your solution looks perfect. However, meanwhile is the v3 of the PiPower on the market (https://docs.sunfounder.com/projects/pipower3/en/latest/). Can I take the way provided in the video 1:1 also to new PiPower version?
I received the following reply fron SunFounders Support:
The GPIO pins on PiPower 3 are extended GPIO pins from the Pi 4:
PiPower IN_DT = GPIO17 Raspi PI4
PiPower CHG = GPIO18 Raspi PI4
PiPower LO_DT_PIN = GPIO27 Raspi Pi4
PiPower GND = GND Raspi PI4