Chain Pedal
PedalChain is the helper class for Chain Pedal devices on the Chain bus. It provides access to the physical pedal state, logical switch state, event callbacks, work modes, and the four RGB LEDs.
Support the following products:
Product Features
Read the physical pedal state or the latched logical switch state.
Use single-click mode or switch mode, and receive click or status-change callbacks when event reporting is enabled.
Control four RGB LEDs independently and select which LEDs show the pedal event overlay.
Configure how long the pedal must be held to enter local configuration mode.
Optionally save the work mode, configuration-entry time, RGB overlay mask, and RGB brightness to flash.
UiFlow2 Example
Switch status callbacks
Open the chain_pedal_core2_example.m5f2 project in UiFlow2.
This example configures Chain Pedal in switch mode, sets the RGB LEDs, and prints a message when the switch status changes.
UiFlow2 Code Block:
Example output:
switch open switch close
MicroPython Example
Switch status callbacks
This example configures Chain Pedal in switch mode, sets the RGB LEDs, and prints a message when the switch status changes.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8import m5ui 9import lvgl as lv 10from chain import PedalChain 11from chain import ChainBus 12 13 14page0 = None 15bus1 = None 16chain_pedal_0 = None 17 18 19def chain_pedal_0_status_open_event(args): 20 global page0, bus1, chain_pedal_0 21 print("switch open") 22 23 24def chain_pedal_0_status_close_event(args): 25 global page0, bus1, chain_pedal_0 26 print("switch close") 27 28 29def setup(): 30 global page0, bus1, chain_pedal_0 31 32 M5.begin() 33 Widgets.setRotation(0) 34 m5ui.init() 35 page0 = m5ui.M5Page(bg_c=0xFFFFFF) 36 37 bus1 = ChainBus(1, tx=14, rx=13) 38 chain_pedal_0 = PedalChain(bus1, 1) 39 chain_pedal_0.set_trigger_callback(PedalChain.STATUS_OPEN, chain_pedal_0_status_open_event) 40 chain_pedal_0.set_trigger_callback(PedalChain.STATUS_CLOSE, chain_pedal_0_status_close_event) 41 print(chain_pedal_0.set_work_mode(PedalChain.WORK_MODE_SWITCH, save=False)) 42 chain_pedal_0.fill_rgb_color(0x6600CC) 43 chain_pedal_0.set_rgb_overlay(0x0F, save=False) 44 45 46def loop(): 47 global page0, bus1, chain_pedal_0 48 M5.update() 49 50 51if __name__ == "__main__": 52 try: 53 setup() 54 while True: 55 loop() 56 except (Exception, KeyboardInterrupt) as e: 57 try: 58 bus1.deinit() 59 m5ui.deinit() 60 from utility import print_error_msg 61 62 print_error_msg(e) 63 except ImportError: 64 print("please update to latest firmware")
Example output:
switch open switch close
API
PedalChain
- class chain.pedal.PedalChain(bus, device_id)
Bases:
ChainDevicePedal Chain class for interacting with pedal devices over Chain bus.
- Parameters:
UiFlow2 Code Block:

MicroPython Code Block:
from chain import ChainBus, PedalChain chainbus_0 = ChainBus(2, tx=32, rx=33) pedalchain_0 = PedalChain(chainbus_0, 1)
- get_button_state()
get button state.
- Returns:
Button state, True if pressed, False if released or failed.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
state = pedalchain_0.get_button_state()
- get_switch_status()
get switch status.
- Returns:
Switch status, 0 for close, 1 for open, or -1 if failed.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
status = pedalchain_0.get_switch_status()
- set_click_callback(callback)
set button click callback.
- Parameters:
callback – Callback function accepting one argument, or None to disable it.
- Return type:
None
Note
Chain related methods cannot be called in the callback function.
UiFlow2 Code Block:

MicroPython Code Block:
def pedal_click_callback(args): print("click") pedalchain_0.set_click_callback(pedal_click_callback)
- set_trigger_callback(trigger_type, callback)
set callback for switch status change events.
- Parameters:
trigger_type (int) – Trigger type, 0 for close or 1 for open.
callback – Callback function accepting one argument, or None to disable it.
- Raises:
ValueError – If
trigger_typeis not 0 or 1.- Return type:
None
Note
Chain related methods cannot be called in the callback function.
UiFlow2 Code Block:

MicroPython Code Block:
def pedal_status_callback(args): print("switch status changed") pedalchain_0.set_trigger_callback( PedalChain.STATUS_OPEN, pedal_status_callback )
- set_work_mode(mode, save=False)
set pedal work mode.
- Parameters:
- Returns:
True if success, False otherwise.
- Return type:
- Raises:
ValueError – If
modeis not a supported work mode.
UiFlow2 Code Block:

MicroPython Code Block:
pedalchain_0.set_work_mode(PedalChain.WORK_MODE_SWITCH)
- fill_rgb_color(color)
fill RGB color.
- Parameters:
color (int) – RGB color value.
- Returns:
True if success, False otherwise.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
device.fill_rgb_color(0xFF0000)
- get_bootloader_version()
get bootloader version.
- Returns:
Bootloader version.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
version = device.get_bootloader_version()
- get_device_type()
get device type.
- Returns:
Device type. Returns -1 if failed.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
device_type = device.get_device_type()
- get_device_uid(uid_type)
get device UID.
- Parameters:
uid_type (int) – UID type, 0 for 4-byte UID, 1 for 12-byte UID.
- Returns:
Tuple of UID bytes (4 bytes or 12 bytes). Returns empty tuple on error.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
uid = device.get_device_uid(0) # 4-byte UID uid = device.get_device_uid(1) # 12-byte UID
- get_firmware_version()
get firmware version.
- Returns:
Firmware version.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
version = device.get_firmware_version()
- get_rgb_brightness()
get RGB brightness.
- Returns:
Brightness value (0-100).
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
brightness = device.get_rgb_brightness()
- get_rgb_color(index)
get RGB color.
UiFlow2 Code Block:

MicroPython Code Block:
color = device.get_rgb_color(0)
- get_work_mode()
get pedal work mode.
- Returns:
Work mode, 0 for single click, 1 for switch, or -1 if failed.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
mode = pedalchain_0.get_work_mode()
- set_rgb_brightness(brightness, save=False)
set RGB brightness.
- Parameters:
- Returns:
True if success, False otherwise.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
device.set_rgb_brightness(80)
- set_rgb_color(index, color)
set RGB color.
- Parameters:
- Returns:
True if success, False otherwise.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
device.set_rgb_color(0, 0xFF0000)
- set_button_mode(mode)
set button reporting mode.
- Parameters:
mode (int) – Reporting mode. Use
MODE_POLLorMODE_EVENT.- Returns:
True if success, False otherwise.
- Return type:
- Raises:
ValueError – If
modeis not a supported reporting mode.
UiFlow2 Code Block:

MicroPython Code Block:
pedalchain_0.set_button_mode(PedalChain.MODE_EVENT)
- get_button_mode()
get button reporting mode.
- Returns:
Reporting mode, 0 for polling, 1 for events, or -1 if failed.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
mode = pedalchain_0.get_button_mode()
- set_enter_config_time(seconds, save=False)
set local configuration entry time.
- Parameters:
- Returns:
True if success, False otherwise.
- Return type:
- Raises:
ValueError – If
secondsis outside the range 0-30.
UiFlow2 Code Block:

MicroPython Code Block:
pedalchain_0.set_enter_config_time(10)
- get_enter_config_time()
get local configuration entry time.
- Returns:
Time in seconds, 0 if disabled, or -1 if failed.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
seconds = pedalchain_0.get_enter_config_time()
- set_rgb_overlay(overlay_mask, save=False)
set the pedal event RGB overlay mask.
- Parameters:
- Returns:
True if success, False otherwise.
- Return type:
- Raises:
ValueError – If
overlay_maskis outside the range 0x00-0x0F.
UiFlow2 Code Block:

MicroPython Code Block:
pedalchain_0.set_rgb_overlay(0x0F)


