Step16 for MicroPython
MIT-licensed I²C driver for the M5Stack Unit Step16↗ (opens in a new tab). Read the encoder's absolute detent (0–15) and firmware version, and control its RGB LED.
Install
mpremote mip install github:mattytrentini/micropython-step16
On a network-connected MicroPython board:
import mip
mip.install("github:mattytrentini/micropython-step16")
Read the encoder
Pass an initialized machine.I2C or machine.SoftI2C bus and power the unit
before reading. Use the pins and bus number for your board. The default
7-bit I²C address is 0x48.
from step16 import Step16
encoder = Step16(i2c)
print("Firmware:", encoder.firmware_version())
print("Detent: {:X}".format(encoder.position()))
The firmware refreshes the detent about every 100 ms. The CoreMatrix application↗ (opens in a new tab) installs this driver as a dependency and provides a demo that powers Grove Port A and displays the detent on its matrix.
Control the RGB LED
encoder.led.on = True
encoder.led.brightness = 100
encoder.led.rgb = (255, 0, 255) # Magenta
All three properties can also be read. on controls RGB power independently
of brightness (an integer percentage from 0 to 100) and rgb (three unscaled
integers from 0 to 255, in red, green, blue order). The firmware may take
about 50 ms to display the color after enabling RGB power.
These settings are not saved to flash and do not affect the detent indicator.
Protocol: M5Stack Unit Step16 I²C register map↗ (opens in a new tab).