Display Raspberry Pi Battery Indicator

If you're using a PiSugar 2 (Plus) or PiSugar 3 (Plus) battery pack with your Raspberry Pi, you may want to display a Raspberry Pi battery indicator in the Raspbian desktop status bar. This tutorial will guide you through installing the necessary kernel module to achieve this.

Raspberry Pi Battery Indicator

Why We Need A Raspberry Pi Battery Indicator?

Having a battery indicator on your Raspberry Pi desktop provides real-time information about your device's battery level and charging status. This can help you:

  • Monitor power levels without opening a terminal.
  • Get a visual alert before the battery runs out.
  • Check charging status at a glance.

Prerequisites

Before proceeding, ensure you have the following:

  • A Raspberry Pi running Raspberry Pi OS (Desktop version).
  • A PiSugar 2 (Plus) or PiSugar 3 (Plus) battery module installed.
  • Internet access on the Raspberry Pi.

Step-by-Step Installation

Installing the PiSugar Kernel Module

PiSugar provides a kernel module that integrates battery monitoring into the system. The installation process differs for PiSugar 2 and PiSugar 3.

For PiSugar 2 Series

Run the following commands in the terminal:

sudo apt update
sudo apt install -y dkms raspberrypi-kernel-headers git

Next, clone the PiSugar 2 kernel module repository and install it:

git clone https://github.com/PiSugar/pisugar-power-manager-rs.git
cd pisugar-power-manager-rs/pisugar-module/pisugar-2
make
sudo make install
sudo insmod pisugar_2_battery.ko
sudo reboot

For additional details, refer to the official repository:
PiSugar 2 Kernel Module

For PiSugar 3 Series

Run the following commands in the terminal:

sudo apt update
sudo apt install -y dkms raspberrypi-kernel-headers git

Next, clone the PiSugar 3 kernel module repository and install it:

git clone https://github.com/PiSugar/pisugar-power-manager-rs.git
cd pisugar-power-manager-rs/pisugar-module/pisugar-3
make
sudo make install
sudo insmod pisugar_3_battery.ko
sudo reboot

For additional details, refer to the official repository:
PiSugar 3 Kernel Module

Enabling the Battery Indicator on the Desktop

Once the kernel module is installed, you can display the battery indicator in the Raspberry Pi OS status bar using LXPanel.

  1. Open a terminal and check if the battery is detected:
    cat /sys/class/power_supply/BAT0/status
  2. Enable the battery monitoring applet:
    • Right-click on the Panel in the Raspberry Pi OS desktop.
    • Select Add / Remove Panel Items.
    • Click Add and choose Battery Monitor.
    • Configure it to read from /sys/class/power_supply/BAT0.
  3. Restart LXPanel for the changes to take effect (run this command on Raspbain Desktop terminal):
    lxpanelctl restart

Troubleshooting

  • If the battery indicator does not appear, verify the module is loaded:
    lsmod | grep battery
  • Check system logs for errors:
    dmesg | grep battery
  • Ensure you are using the correct module for your PiSugar version.

Conclusion

By following this guide, you can easily add a battery indicator to your Raspberry Pi's desktop when using a PiSugar 2 (Plus) or PiSugar 3 (Plus) battery pack. This enhances usability and ensures you always have power information at a glance.

For more Raspberry Pi battery management tips, stay tuned for future guides!

Back to blog