From d8572a785e1dc85e89f4dbca85f245deaf280bd4 Mon Sep 17 00:00:00 2001 From: Charly-sketch Date: Mon, 21 Sep 2026 11:11:02 +0200 Subject: [PATCH] feat(bq27441): Add clear error when battery is not connected. --- lib/bq27441/bq27441/device.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/bq27441/bq27441/device.py b/lib/bq27441/bq27441/device.py index 5ff4457c..f39af9cd 100644 --- a/lib/bq27441/bq27441/device.py +++ b/lib/bq27441/bq27441/device.py @@ -139,12 +139,21 @@ def __init__( self._seal_flag = False self.gpout_pin = gpout_pin self.capacity_mAh = capacity_mAh + + # The BQ27441 is powered by the battery. + # If no battery is connected, the device will not appear on the I2C bus. + if self.address not in self.i2c.scan(): + raise OSError( + "BQ27441 not detected at I2C address 0x{:02X}. " + "Make sure a battery is connected.".format(self.address) + ) + self.configure_gpout_input() self.power_on() def configure_gpout_input(self): - if self.gpout_pin: - self.gpout = Pin(self.gpout_pin, mode=Pin.IN, pull=Pin.PULL_UP) + if self.gpout_pin: + self.gpout = Pin(self.gpout_pin, mode=Pin.IN, pull=Pin.PULL_UP) def configure_gpout_output(self): if self.gpout_pin: