This sample Python script is designed to run on
a Raspberry Pi 5. It measures and reports key electrical parameters,
including battery charging/discharging voltage and current, as well
as the output voltage and current of both the 12V and 5V UPS power
rails.
This tutorial assumes
you've already set up a Raspberry Pi with Raspbian12(bookworm). For
help installing the Debian-based OS on your Pi, check out the docs
onRaspberrypi.org.
1.0 Editing the EEPROM
configuration
1.1
From the command line or Terminal
window start by running the following command :
pi@raspberrypi~
$
sudo rpi-eeprom-config -e
Change the setting of POWER_OFF_ON_HALTfrom0to1, Add
PSU_MAX_CURRENT=5000 at the
end of the file that reads like this:
1.2
Reboot your
Raspberry Pi 5 to make the change take effect.
pi@raspberrypi~
$sudo
reboot
2.0 Configuring the Raspberry
Pi for I2C
2.1
From the command line or Terminal
window start by running the following command :
pi@raspberrypi~
$
sudo raspi-config
This will launch the raspi-config
utility. Select "Interfacing Options"
2.2
Highlight the “I2C” option and
activate "<Select>"
2.3
Select and activate “<Yes>”
2.4
Highlight and activate “<Ok>”
2.5
Activate
"<Finish>", this will exist the raspi-config utility.
2.6
Update your Pi and
Install the required
dependencies
The Raspberry Pi
will reboot and the interface will be enabled.
2.9
Once you have logged into your Raspberry Pi from the command
line, run the command to see all the connected devices
pi@raspberrypi~
$sudo
i2cdetect -y 1
#40 - The INA219 sensor's I2C address
for battery monitoring (charge/discharge)
#41 - The INA219's I2C address
for monitoring the UPS 12V output voltage and current.
#44 - The INA219's I2C address
for monitoring the UPS 5V output voltage and current.
3.0
Command to monitor battery charging &
UPS output status