Mario Hub

class MarioHub(name=None, timeout=10000, connect=True)

LEGO® Super Mario hub (sets 71360, 71387, 71441 and similar).

Connect a supported hub running Pybricks to a LEGO Mario, Luigi, or Peach figure and reads its color sensor.

Parameters:
  • name (str) – Bluetooth name of the hub. If no name is given, the hub connects to the first Mario hub it finds.

  • timeout (Number, ms) – How long to search for the hub. Choose None to wait indefinitely.

  • connect (bool) – Choose False to skip connecting. connect() can be called later to connect.

Raises:

OSError – If the connection attempt fails or times out.

awaitconnect()

Connects to the device. Only needed if you disconnected or initialized with connect=False.

Raises:

OSError – If the connection attempt fails or times out.

awaitdisconnect()

Disconnects the device.

Raises:

OSError – If disconnecting fails.

color() Color

Reads the color detected by the color sensor from the latest received notification.

Returns:

Detected color.

Raises:

OSError – If the hub is not connected.

hsv() Color

Reads the hue, saturation, and brightness of the color detected by the color sensor from the latest received notification, as a Color object.

Returns:

Measured color.

Raises:

OSError – If the hub is not connected.

detectable_colors(colors)

Configures the list of colors that color() may return.

Only the colors in this list will be returned. This helps reduce false positives when you only care about a specific subset of colors.

Parameters:

colors (list) – List of Color objects to detect, or None to restore the default list.