hub

Everything built into the hub.

Start your program with import hub. Then use hub.ports for motors and sensors, hub.led for the light, hub.buttons, hub.imu (motion sensor), hub.lcd (screen), hub.audio (sound), hub.battery and more.

Submodules

Attributes

accelerometer

measures pushes and gravity along x, y and z.

fw_version

Which firmware version the hub is running, e.g. "2.1.0".

gyro

measures how fast the hub spins around x, y and z.

i2c

The I2C connection on the hub's Grove connector, for extra sensors and gadgets.

led

The hub's built-in colored light. Try hub.led.setColor(255, 0, 0) for red.

Functions

exit() → NoReturn

Stop your program right here.

powerOff() → NoReturn

Turn the hub off.

sd_card() → Optional[machine.SDCard]

The SD card, or None if there is no card.

sd_remount() → None

Re-connect the SD card at /sd.

set_usb_msc(enabled) → None

Show (True) or hide (False) the SD card as a USB drive on your computer.

stop_callbacks() → int

Stop every button callback (hub.buttons.on()) that is still

usb_msc_mode() → bool

True while the SD card is shown as a USB drive on your computer.

Package Contents

hub.exit() → NoReturn[source]

Stop your program right here.

The hub shows “Done”, just like when a program reaches its end.

hub.powerOff() → NoReturn[source]

Turn the hub off.

If a USB cable keeps it powered, the hub stops motors, the screen and Bluetooth and goes to sleep instead; press the center button to wake it.

hub.sd_card() → machine.SDCard | None[source]

The SD card, or None if there is no card.

Files on the card are found under /sd, e.g. /sd/song.mid.

hub.sd_remount() → None[source]

Re-connect the SD card at /sd.

Use it after turning off USB drive mode (see set_usb_msc()) so your program can use the card again.

hub.set_usb_msc(enabled: bool) → None[source]

Show (True) or hide (False) the SD card as a USB drive on your computer.

While it’s shown as a drive, your program can’t use the card. After hiding it, call sd_remount() to use it again.

hub.stop_callbacks() → int[source]

Stop every button callback (hub.buttons.on()) that is still running.

Each one stops at its next line of Python or inside its current time.sleep_ms. Returns how many were told to stop. Calling it from inside a callback stops all the others, not the caller. Registered callbacks stay registered and run again on the next press.

hub.usb_msc_mode() → bool[source]

True while the SD card is shown as a USB drive on your computer.

hub.accelerometer: lpf2.devices.accelerometer[source]

measures pushes and gravity along x, y and z.

Type:

The built-in accelerometer

hub.fw_version: str[source]

Which firmware version the hub is running, e.g. "2.1.0".

hub.gyro: lpf2.devices.gyroscope[source]

measures how fast the hub spins around x, y and z.

Type:

The built-in gyroscope

hub.i2c: machine.I2C[source]

The I2C connection on the hub’s Grove connector, for extra sensors and gadgets.

It is a ready-to-use machine.I2C — try hub.i2c.scan() to list what’s connected. Some built-in parts of the hub share this connection.

hub.led: lpf2.devices.hub_led[source]

The hub’s built-in colored light. Try hub.led.setColor(255, 0, 0) for red.