Software Tutorials

Last revision 2025/12/30

The article guides users through the software setup of Raspberry Pi 5 with UPS, detailing hardware requirements, software installations, and configurations for efficient battery management and power detection. It includes commands for EEPROM editing, I2C enabling, UPS status reading, and battery charging control, making it a comprehensive tutorial for both beginners and advanced users.

Hardware Preparation

Software Preparation

Wiring Diagram

No additional wiring is required for I2C configuration; the UPS board uses pogo pins to connect to the Raspberry Pi 5's I2C pins (GPIO2 and GPIO3).

Other Preparation Work

  1. Ensure the Raspberry Pi 5 is powered on and connected to a keyboard, mouse, and display, or accessed via SSH.
  2. Open the Terminal window from the desktop or via SSH.

Tutorials

Editing the EEPROM configuration

1.From the command line or Terminal window start by running the following command:

command: sudo rpi-eeprom-config -e

Change the setting of POWER_OFF_ON_HALT from 0 to 1 ,Add PSU_MAX_CURRENT=5000 at the end of the file that reads like this:

2.Reboot your Raspberry Pi 5 to make the change take effect.

command: sudo reboot

Configuring the Raspberry Pi for I2C

  • Open I2C through graphical interface or command line

  • Update your Pi and Install the required dependencies

command1: sudo apt-get update
command2: sudo apt-get upgrade -y
command3: sudo apt-get install python3-pip

  • Download the required scripts

command: git clone https://github.com/suptronics/x120x.git

git clone https://github.com/suptronics/x120x.git
  • Reboot the Raspberry Pi

    command: sudo reboot

The Raspberry Pi will reboot and the interface will be enabled.

  • Once you have logged into your Raspberry Pi from the command line, run the command to see all the connected devices

command: sudo i2cdetect -y 1

the address of the battery fuel gauging chip

Reading UPS status

Command line for reading UPS status,Run the command to read battery voltage and percentage
For Debian12 (bookworm), Kernel version 6.6

command: sudo python3 merged.py

For Debian13 (trixie), Kernel version 6.12

command: sudo python3 merged-trixie.py

Desktop interface for reading UPS status

command: sudo python3 qtx120x.py

Manual reading battery voltage & percentage

Run the command to read battery voltage and percentage

command: sudo python3 bat.py

Change the battery low voltage to implement safe shutdown. default is less than 3.20Vdc.

command: sudo nano bat.py


Note: the voltage range must be 3.00~4.10vdc.

Save and exit. In nano, you do that by hitting CTRL + X, answering Y and hitting Enter when prompted.

Manua testing AC Power loss or power adapter failure detection (PLD)

Execute the command to initiate power loss detection (PLD)
For Debian12 (bookworm), Kernel version 6.6

command: sudo python3 pld.py

For Debian13 (trixie), Kernel version 6.12

command: sudo python3 pld-trixie.py

Disconnect the power adapter and observe the detection of the power loss.

Control battery charging - for advanced users only

To disable battery charging

command: pinctrl set 16 op dh

To enable battery charging

command: pinctrl set 16 op dl

Was this article helpful?

TOP