Linux kernel modules for PiSugar 3.
Congratulations if your PI is running a linux distribution that has /lib/modules/$(uname -r)/build/
directory, e.g. ubuntu-server or latest pi os, you don't need to manually build RPI kernel, and that will save a lot of time.
Install build-essential
and linux-headers
sudo apt install -y build-essential linux-headers-$(uname -r)
As kernel symbols is not included in Raspberry Pi OS (no /lib/modules/$(uname -r)/build
), so you need to compile the kernel and generate the kernel symbols by yourself.
To build the kernel, see official doc: https://www.raspberrypi.com/documentation/computers/linux_kernel.html
Clone this repository, make kernel modules:
make
Load module:
sudo insmod pisugar_3_battery.ko
# or
sudo insmod pisugar_3_battery.ko i2c_bus=1 i2c_addr=0x57
Now, it is loaded:
lsmod | grep battery
And you will see extra device files in /sys/class/power_supply
ls /sys/class/power_supply
Remove module:
sudo rmmod pisugar_3_battery.ko
Now, you can enable battery monitor plugin.
If you want to load kernel module at boot time, copy it to /lib/modules/$(uname -r)/kernel/drivers
sudo cp -f pisugar_3_battery.ko /lib/modules/$(uname -r)/kernel/drivers
sudo echo pisugar_3_battery >> /etc/modules
sudo depmod -a
GPL