Quickstart
The two user-facing MicroPython modules are:
hub— on-board peripherals (ports A–D, hub LED, IMU, buttons, LCD, power).lpf2— the LEGO Powered-Up (LPF2) protocol primitives: ports, devices, hub emulation, remote-hub client, enumerations.
Minimal program
Programs are plain Python scripts. The C firmware polls every port’s
update() for you each tick — device detection and
value parsing happen in the background, so scripts just read state. See
Automatic polling for details.
import hub
import time
port = hub.ports.A
while True:
if port.isDeviceConnected():
print("device:", port.getDeviceType())
time.sleep_ms(10)
Use hub.exit() to exit cleanly from anywhere, or hold the centre
button for 2 s to stop the running script.
What the modules do
Module |
Purpose |
|---|---|
|
Board singletons: |
|
|
|
Concrete |
|
|
|
Typed device wrappers ( |
|
Sub-port helpers for the LPF2 port expander accessory. |
Enum modules |
|