pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Unit timerpwr

Example

Get battery, USB, and Grove port status information from the TimerPWR module, configure various functions of the module (such as button, Grove output, OLED backlight, etc.), and handle events related to device sleep and wake-up.

from m5stack import *
from m5ui import *
from uiflow import *
import unit

timerpwr_1 = unit.get(unit.TIMERPWR, unit.PORTA)

timerpwr_1.init_i2c_address(0x56)

timerpwr_1.set_oled_backlight_status(True)
timerpwr_1.set_wakeup_trigger(timerpwr_1.TRIG_ALL)
while True:
  timerpwr_1.sleep_cycle(0, 0, 5, 0, 0, 5)
  print(timerpwr_1.get_battery_voltage())
  print(timerpwr_1.get_battery_current())
  print(timerpwr_1.get_usb_voltage())
  print(timerpwr_1.get_usb_current())
  print(timerpwr_1.get_grove_voltage())
  print(timerpwr_1.get_grove_current())
  print(timerpwr_1.get_firmware_version())
  wait_ms(2)

API

timerpwr_1.init_i2c_address(0x56)
  • Initializes the TimerPWR module’s I2C address to 0x56. This address is used to communicate with the module over the I2C bus.
timerpwr_1.get_battery_voltage()
  • Gets the current battery voltage value.
timerpwr_1.get_battery_current()
  • Gets the current battery current value.
timerpwr_1.get_usb_voltage()
  • Gets the current USB port voltage.
timerpwr_1.get_usb_current()
  • Gets the current USB port current.
timerpwr_1.get_grove_voltage()
  • Gets the voltage of the external device connected to the Grove port.
timerpwr_1.get_grove_current()
  • Gets the current information of the Grove port.
timerpwr_1.get_button_status(0)
  • 0 is the button number, and this returns whether the button is pressed or not.
timerpwr_1.get_grove_output_status()
  • Returns the current enable/disable status of the Grove output port.
timerpwr_1.get_oled_backlight_status()
  • Returns whether the OLED backlight is currently turned on.
timerpwr_1.get_firmware_version()
  • Gets the current firmware version of the TimerPWR module.
timerpwr_1.save_data_to_flash()
  • Saves data to flash memory. This block stores data (such as battery, current, etc.) in persistent storage for later use.
timerpwr_1.set_grove_output_status(True)
  • Enables the Grove output port by setting its status to True.
timerpwr_1.set_oled_backlight_status(True)
  • Enables the OLED backlight by setting its status to True.
timerpwr_1.set_wakeup_trigger(timerpwr_1.TRIG_ALL)
  • Sets the wake-up trigger condition to all events (TRIG_ALL). This block configures the module to wake up on any event (such as button press, USB insertion, etc.).
timerpwr_1.set_sleep_trigger(timerpwr_1.TRIG_ALL)
  • Sets the sleep trigger condition to all events (TRIG_ALL). This block configures the module to enter sleep mode on any event to save power.
timerpwr_1.sleep_once(0, 0, 5, 0, 0, 5)
  • Sets a one-time sleep mode with timed sleep configuration (e.g., entering sleep mode every 5 seconds). This makes the device enter sleep mode and wake up after the specified time.
timerpwr_1.sleep_cycle(0, 0, 5, 0, 0, 5)
  • Sets a cyclic sleep mode. This block makes the device periodically enter sleep mode and wake up (e.g., entering sleep mode every 5 seconds).
def timerpwr_1_btna_released_event(args):
  # global params
  pass
timerpwr_1.set_callback(timer

pwr_1.EVENT_BUTTONA_RELEASED, timerpwr_1_btna_released_event)
  • Sets a callback function for the EVENT_BUTTONA_RELEASED event. This event triggers the timerpwr_1_btna_released_event function when button A is released. The args parameter contains relevant data when the event is triggered.
def timerpwr_1_charging_event(args):
  # global params
  pass
timerpwr_1.set_callback(timerpwr_1.EVENT_CHARGING, timerpwr_1_charging_event)
  • Sets a callback function for the EVENT_CHARGING event. This event triggers the timerpwr_1_charging_event function when the charging status changes.
def timerpwr_1_usb_inserted_event(args):
  # global params
  pass
timerpwr_1.set_callback(timerpwr_1.EVENT_USB_INSERTED, timerpwr_1_usb_inserted_event)
  • Sets a callback function for the EVENT_USB_INSERTED event. This event triggers the timerpwr_1_usb_inserted_event function when USB is inserted.
timerpwr_1.tick()
  • Updates and processes the internal state of the TimerPWR module. It is typically called within a loop to ensure the module’s operational status and event handling.
On This Page