Simple battery test

Ensure your device works with this simple test, it show the battery voltage if a battery is connected to AXP2101

examples/axp2101_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2024 Dario Cammi
 2#
 3# SPDX-License-Identifier: Unlicense
 4"""
 5This script detect if a battery is connected to AXP2101 and
 6if it is connected it reads the voltage
 7"""
 8import time
 9import board
10from axp2101 import AXP2101
11
12i2c = board.I2C()
13pmic = AXP2101(i2c)
14
15while True:
16    if pmic.is_battery_connected:
17        battery_voltage = pmic.battery_voltage
18        print(f"Battery voltage {battery_voltage}V")
19    else:
20        print("No battery connected")
21
22    time.sleep(1)

Power key pressed test

Simple test to show how to read the power key button press status

examples/axp2101_power_key_press.py
 1# SPDX-FileCopyrightText: Copyright (c) 2024 Dario Cammi
 2#
 3# SPDX-License-Identifier: MIT
 4"""
 5This script demonstrate how to get the power key press status
 6"""
 7import time
 8import board
 9from axp2101 import AXP2101
10
11i2c = board.I2C()
12pmic = AXP2101(i2c)
13
14while True:
15    short_press, long_press = pmic.power_key_was_pressed
16    if short_press:
17        print("Power key was short pressed")
18    elif long_press:
19        print("Power key was long pressed")
20    else:
21        print("Power key isn't press")
22
23    time.sleep(1)