axp2101

Circuitpython driver for AXP2101 power management IC

  • Author(s): Dario Cammi

Implementation Notes

Hardware:

Software and Dependencies:

class axp2101.AXP2101(i2c: I2C, device_address: int = 0x34)

Circuitpython driver for AXP2101 power management IC

This driver class is designed not to be directly instanciated but to be extended. The subclass should not directly expose LDOs but specific properties and methos to interact with connected hardware. For example on M5Stack Core3 the DLDO1 is the output power the LCD backlight. The subclass instead of expose the DLDO1 voltage control should expose a property to control the DLDO1 brightness

Parameters:
  • i2c (I2C) – The I2C bus AXP2101 is connected to

  • device_address (int) – The I2C bus addres. Default to 0x34

Quickstart: Importing and using the device

Here is an example of using the AXP2101 class. First you will need to import the libraries to use the sensor

import board
from axp201 import AXP201

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
pmic = AXP2101(i2c)

Now you can get the AXP2101 battery status

is_battery_connected = pmic.is_battery_connected
battery_voltage = pmic.battery_voltage
property battery_charging_enabled: bool

Enable/disable the battery charging

property battery_level: int

Battery level in percentage (0% - 100%)

Returns 0 if no battery is connected to AXP2101

property battery_status: BatteryStatus

Battery charging status

Returns if the battery is charging, discharging or in standby Returns None if no battery is connected

Statuse

BatteryStatus.DISCHARGING

BatteryStatus.STANDBY

BatteryStatus.CHARGING

property battery_voltage: int

Battery voltage in mV

property is_battery_connected: bool

True when a battery is connected to AXP2101

property power_key_was_pressed: Tuple[bool, bool]

Power key pressed status

Returns:

Two booleans: Power key is short press and power key is long press

power_off() None

Switch off the AXP2101 and the connected devices

class axp2101.BatteryStatus(value)

Enum-like class from AXP2101 battery charging status

DISCHARGING: BatteryStatus

The battery is discharging, battery is powering the devices

STANDBY: BatteryStatus

The battery is neither charging neither discharging

CHARGING: BatteryStatus

The battery is charging