Skip to content

Instantly share code, notes, and snippets.

@diegojfer
Last active February 26, 2026 14:52
Show Gist options
  • Select an option

  • Save diegojfer/d1bd048ed33c02edd0ee8fc30afa2206 to your computer and use it in GitHub Desktop.

Select an option

Save diegojfer/d1bd048ed33c02edd0ee8fc30afa2206 to your computer and use it in GitHub Desktop.

Battery Percent on Argon ONE UP (Ubuntu)

I received the unit yesterday and started testing it. Argon provides a script to manage the battery, but it does not integrate natively with the operating system. The problem is that the script does not register any battery on the power_supply subsystem, so the system cannot recognize the battery as standard.

According to the block diagram, the Argon ONE UP uses a Cellwise CW2217 chip connected over I2C (on RPI1, bus i2c-1, address 0x64), so creating a driver for it is not very difficult.

I created the driver and uploaded it to GitHub kmod-cw2217b. After installing it, the system can display the battery percentage on Ubuntu or Debian.

🛠️ Build & Install the Module

Install the dependencies.

sudo apt update
sudo apt install git build-essential linux-headers-$(uname -r) dkms device-tree-compiler

Install the driver module

# Download kernel module
git clone https://github.com/diegojfer/kmod-cw2217b.git
cd kmod-cw2217b

# Build and install kernel module
sudo make install

Configure the system to automatically load the kernel module.

# Load automatically on boot
echo cw2217b | sudo tee /etc/modules-load.d/cw2217b.conf

🌳 DeviceTree Overlay

By default, the bootloader does not expose the CW2217 IC to the kernel (it only enables the I2C bus). Therefore, you need to either add a Device Tree entry or create the device manually.

Register Manually

If you choose to register it manually, you will have to recreate the device every time the system reboots.

# Create device
echo cw2217b 0x64 | sudo tee /sys/bus/i2c/devices/i2c-1/new_device

# If you want to remove device
echo 0x64 | sudo tee /sys/bus/i2c/devices/i2c-1/delete_device

Register on Bootloader

To register an overlay, you need to know where the bootloader loads overlay files from. Normally, on Ubuntu on Raspberry Pi, this is /boot/firmware/current/overlays.

// FILE: cw2217b.dts

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2711", "brcm,bcm2712", "brcm,bcm2835";

    fragment@0 {
        target = <&i2c1>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            cw2217b: cw2217b@64 {
                reg = <0x64>;
                compatible = "cellwise,cw2217b";
            };
        };
    };
};
# Compile DeviceTree Overlay
dtc -@ -I dts -O dtb -o cw2217b.dtbo cw2217b.dts

# Copy DeviceTree Overlay
sudo mv cw2217b.dtbo /boot/firmware/current/overlays/cw2217b.dtbo

After compiling and copying the Device Tree overlay, you must enable it. To do this, add the following line under the [all] section in config.txt.

dtoverlay=cw2217b

⚠️ Known Issues

  • Kernel updates: Thanks to the contribution of rbm78bln, DKMS support is now implemented. After updating the kernel, you must rebuild and reinstall the module because it is an external driver. Consider using DKMS to automate this.

  • No DeviceTree overlay: If you create the I2C device manually (new_device), you will need to recreate it after every reboot. Using a proper overlay avoids this.

❗ Troubleshooting

  • General Logging: The driver uses the standard kernel logging system. If you run into issues, such as the 0% battery problem, try running dmesg -w to debug.

  • /boot/firmware read-only filesystem: If you’re having issues installing the device-tree overlay, try remounting the filesystem as read-write. The following code works only on Ubuntu. Raspbian uses a different boot path.

    # Remount as read-write.
    sudo mount -o remount,rw /boot/firmware
    
    # Switch back to read-only.
    sudo mount -o remount,ro /boot/firmware
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment