How important is a UPS (Uninterrupted Power Supply) for your Raspberry Pi?

Background

If you have a Raspberry Pi project that requires to be powered all the time, then relying on the main power supply might not be a good idea after all. This is because if there is any sort of power fluctuation or power outage, it will instantly affect the Raspberry Pi. 

What happens if you don’t use a UPS for Raspberry Pi?

A power fluctuation such as low or high power can be harmful to the hardware on the Raspberry Pi. On the other hand, with a power outage, you are not able to shut down your Raspberry Pi properly. In this case, you are risk corrupting your Raspberry Pi’s SD card.  

Projects that require a UPS

A UPS is very important for projects involving data collection, streaming, scripts that don’t restart on boot to help ensure the stability of the project while providing backup power as soon as the power gets cut off. Also, if you are running a web server or Pi-hole on Raspberry Pi, a UPS would be an ideal addition to your project.

How about using a portable power bank?

You could use a portable power bank to achieve the same effect as a UPS but there are some factors to consider. The power bank should have the ability to charge and discharge at the same time. This means as the power bank charges, it should be able to output power from its ports simultaneously. Also sometimes normal power banks cannot deliver enough current such as for the Raspberry Pi 4 and in this case, need a power bank with a high current output which is expensive. So due to these reasons, it is not an ideal solution to use a power bank to power a Raspberry Pi.

What’s the best UPS solution for Raspberry Pi?

It is recommended to use a power management board along with batteries to provide a UPS solution for your Raspberry Pi. Once you power the power management board via a power adapter and connect batteries, you can essentially set up a power supply that keeps running even though there is a power outage. Also, power management boards have the ability to monitor the battery status of the connected batteries and predict how long the Raspberry Pi can run on battery when the power is lost.

UPS (with RTC & Coulometer) for Raspberry Pi 4B/3B+/3B

By taking all of the above factors into consideration, we recommend you use this UPS to power your Raspberry Pi projects. Learn more about it here.

This UPS board is equipped with a power management unit and a charging management unit to ensure that your Raspberry Pi receives stable power at all times. Also, it runs on two 18650 batteries which you can easily swap out at any time.

Why RTC and Coulomb Counter?

This UPS board includes an RTC (Real-Time Clock) to retain the time information for your Raspberry Pi project. It also includes a coulomb counter which can be useful to monitor battery voltage and current information when the Raspberry Pi is running on backup power.

Hardware Overview

Setting up this UPS with your Raspberry Pi

Onboard Power Level Indicators

The onboard power level indicators can be useful to monitor the remaining battery power when the Raspberry Pi is in use.

Reading voltage and current information

The onboard coulomb counter is helpful to provide the remaining voltage and current information of the batteries. You can follow the steps below to view this information on your Raspberry Pi.

  • Flash the latest Raspberry Pi OS to the micro-SD card and boot up Raspberry Pi.
  • Make sure Raspberry Pi connect to the internet and update the repository’s information with the command: “sudo apt-get update”
  • Make sure the I2C function has been turned on.
  • Install the python library:
sudo pip3 install pi-ina219
  • Create a new .py file and paste the following demo code
# IMPORT THE LIBERARY.
from ina219 import INA219
from ina219 import DeviceRangeError
SHUNT_OHMS = 0.05


def read():
    """Define method to read information from coulometer."""
    ina = INA219(SHUNT_OHMS)
    ina.configure()
    print("Bus Voltage: %.3f V" % ina.voltage())
    try:
        print("Bus Current: %.3f mA" % ina.current())
        print("Power: %.3f mW" % ina.power())
        print("Shunt voltage: %.3f mV" % ina.shunt_voltage())
    except DeviceRangeError as e:
        print(e)

if __name__ == "__main__":
    read()
  • Run the demo code by entering the following command
python demo.py

Finally, you will be able to see the battery information on the Raspberry Pi terminal.

Conclusion

We believe that this blog was helpful for you to understand the importance of a UPS in your Raspberry Pi projects and hope you use one in your next project!

About Author

Calendar

June 2020
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930