Step16 Unit
This library is the driver for Unit Step16.
Support the following products:
UiFlow2 Example
Read Encoder
Open the cores3_step16_unit_example.m5f2 project in UiFlow2.
This example shows how to read and display encoder readings.
UiFlow2 Code Block:
Example output:
None
MicroPython Example
Read Encoder
This example shows how to read and display encoder readings.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import I2C 9from hardware import Pin 10from unit import Step16Unit 11 12 13title0 = None 14label1 = None 15label_val = None 16i2c0 = None 17step16_0 = None 18val = None 19 20 21def setup(): 22 global title0, label1, label_val, i2c0, step16_0, val 23 M5.begin() 24 Widgets.setRotation(1) 25 Widgets.fillScreen(0x222222) 26 title0 = Widgets.Title("UnitStep16 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu24) 27 label1 = Widgets.Label( 28 "Encoder Value:", 10, 55, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24 29 ) 30 label_val = Widgets.Label("0", 205, 55, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24) 31 32 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) 33 step16_0 = Step16Unit(i2c0, 0x48) 34 print((str("i2c addr: ") + str((step16_0.get_addr())))) 35 print((str("version: ") + str((step16_0.get_firmware_version())))) 36 step16_0.set_led_mode(Step16Unit.AUTO_OFF, 5) 37 step16_0.set_led_brightness(80) 38 print((str("rgb brightness: ") + str((step16_0.get_rgb_brightness())))) 39 print((str("rgb value: ") + str((step16_0.get_rgb_value())))) 40 if step16_0.get_rgb_power(): 41 print("RGB power on") 42 else: 43 print("RG B power off") 44 step16_0.set_rgb_power(True) 45 step16_0.set_rgb_value(0x3333FF) 46 47 48def loop(): 49 global title0, label1, label_val, i2c0, step16_0, val 50 M5.update() 51 val = step16_0.get_encoder_value() 52 label_val.setText(str(val)) 53 54 55if __name__ == "__main__": 56 try: 57 setup() 58 while True: 59 loop() 60 except (Exception, KeyboardInterrupt) as e: 61 try: 62 from utility import print_error_msg 63 64 print_error_msg(e) 65 except ImportError: 66 print("please update to latest firmware")
Example output:
None
API
Step16Unit
- class unit.step16.Step16Unit(i2c, addr=72)
Bases:
objectCreate an Step16Unit object.
UiFlow2 Code Block:

MicroPython Code Block:
from unit import Step16Unit unit_step16_0 = Step16Unit(i2c0, 0x48)
- get_encoder_value()
Get the current encoder value (0~15).
- Returns:
Encoder value.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
value = unit_step16_0.get_encoder_value()
- set_encoder_cw_increase(enable)
Configure whether clockwise rotation increases encoder value.
- Parameters:
enable (bool) –
True: Clockwise rotation increases the encoder value.
False: Clockwise rotation decreases the encoder value.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.set_encoder_cw_increase(True) unit_step16_0.set_encoder_cw_increase(False)
- get_encoder_cw_increase()
Get current encoder direction mode.
- Returns:
1 for increasing clockwise, 0 for decreasing.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
direction = unit_step16_0.get_encoder_cw_increase()
- set_led_mode(mode, seconds=5)
Set LED display mode.
- Parameters:
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.set_led_mode(0) # Always off unit_step16_0.set_led_mode(1) # Always on unit_step16_0.set_led_mode(2, 10) # Auto-off after 10 seconds
- get_led_mode()
Get LED display mode.
The LED mode values:
0x00 : Always Off.
0xFE : Always On.
0x00 ~ 0xFD : Auto off times in seconds.
- Returns:
LED display mode.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.get_led_mode()
- set_led_brightness(brightness)
Set LED brightness (0~100).
- Parameters:
int (brightness) – Brightness level.
brightness (int)
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.set_led_brightness(80)
- get_led_brightness()
Get current LED brightness.
- Returns:
Brightness level.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
brightness = unit_step16_0.get_led_brightness() print("Brightness:", brightness)
- set_rgb_power(enable)
Turn the RGB light power ON or OFF.
- Parameters:
enable (bool) – True to turn on the RGB light, False to turn it off.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.set_rgb_power(True) # Turn ON RGB light unit_step16_0.set_rgb_power(False) # Turn OFF RGB light
- get_rgb_power()
Get the current power status of the RGB light.
- Returns:
True if the RGB light is ON, False if OFF.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
power_on = unit_step16_0.get_rgb_power()
- set_rgb_brightness(brightness)
Set the brightness of the RGB light (0~100%).
- Parameters:
brightness (int) – Brightness percentage (0~100).
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.set_rgb_brightness(80) # Set RGB brightness to 80%
- get_rgb_brightness()
Get the current RGB brightness level (0~100%).
- Returns:
Current RGB brightness percentage (0~100).
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
brightness = unit_step16_0.get_rgb_brightness() print("RGB Brightness:", brightness)
- set_rgb_value(color=0)
Set RGB LED color using a 24-bit integer.
- Parameters:
color (int) – A 24-bit integer representing the RGB color (e.g., 0xFF8040 for R=255, G=128, B=64). Format is (R << 16) | (G << 8) | B.
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.set_rgb_value()
- get_rgb_value()
Get current RGB LED color.
- Returns:
Tuple of (r, g, b)
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
r, g, b = unit_step16_0.get_rgb_value()
- save_led_config()
Save current LED mode and brightness settings.
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.save_led_config()
- Return type:
None
- save_rgb_config()
Save current RGB color settings.
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.save_rgb_config()
- Return type:
None
- set_addr(new_addr)
Set the device’s I2C address.
- Parameters:
new_addr (int) – New I2C address (0x08~0x77).
- Return type:
None
UiFlow2 Code Block:

MicroPython Code Block:
unit_step16_0.set_addr(0x49)
- get_addr()
Get the current I2C device address.
- Returns:
I2C address.
- Return type:
UiFlow2 Code Block:

MicroPython Code Block:
addr = unit_step16_0.get_addr()


