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
import hub
port = hub.ports.A
hub.on("loop")
def loop():
if port.isDeviceConnected():
print("device:", port.getDeviceType())
break
hub.sleep_ms(10)
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.
Event-driven form
When a script is launched from the on-device menu the runner injects
hub.on — decorate setup and loop handlers instead of
writing your own while True:
import hub
@hub.on("setup")
def setup():
hub.led.setColor(0, 128, 0)
@hub.on("loop")
def loop():
...
The runner drives loop at roughly 10 ms per tick and also calls
hub.buttons.poll() for you.
What the modules do
Module |
Purpose |
|---|---|
|
Board singletons: |
|
|
|
Concrete |
|
|
|
Typed device wrappers ( |
|
Sub-port helpers for the LPF2 port expander accessory. |
Enum modules |
|