Home

Awesome

Python library to interact with Move Hub / PoweredUp Hubs

Move Hub is central controller block of LEGO® Boost Robotics Set.

In fact, Move Hub is just a Bluetooth hardware piece, and all manipulations with it are made by commands passed through Bluetooth Low Energy (BLE) wireless protocol. One of the ways to issue these commands is to write Python program using this library.

The best way to start is to look into demo.py file, and run it (assuming you have installed library).

If you have Vernie assembled, you might run scripts from examples/vernie directory.

Demonstrational Videos

Vernie Programmed Laser Engraver Color Sorter Face Tracker Color Pin Bot BB-8 Joystick

Dancing Vernie

Features

Usage

Please note that this library requires one of Bluetooth backend libraries to be installed, please read section here for details.

Install library like this:

pip install -U pylgbst[bleak]

Then instantiate MoveHub object and start invoking its methods. Following is example to just print peripherals detected on Hub:

from pylgbst.hub import MoveHub

hub = MoveHub()

for device in hub.peripherals:
    print(device)

Each peripheral kind has own methods to do actions and/or get sensor data. See features list for individual doc pages.

Bluetooth Backend Prerequisites

You have following options to install as Bluetooth backend (some of them might require sudo on Linux):

Note that pip install -U pylgbst[bleak] command indicates which backend to install. So you can install it backend-less, or with some backend from above.

Windows users may first turn to the Bleak backend, which should support any internal or external Bluetooth adapter recognized by the OS. The Windows version of pygatt backend will only work with a Bluegiga BLED112 Bluetooth Smart Dongle.

Please let author know if you have discovered any compatibility/preprequisite details, so we will update this section to help future users

Depending on backend type, you might need Linux sudo to be used when running Python.

Bluetooth Connection Options

There is an optional parameter for MoveHub class constructor, accepting instance of Connection object. By default, it will try to use whatever get_connection_auto() returns. You have several options to manually control that:

All the functions above have optional arguments to specify adapter name and Hub name (or mac address). Please take a look at functions source code for details.

If you want to specify name for Bluetooth interface to use on local computer, you can pass that to class or function of getting a connection. Then pass connection object to MoveHub constructor. Like this:

from pylgbst.hub import MoveHub
from pylgbst import get_connection_gatt

conn = get_connection_gatt(hub_mac='AA:BB:CC:DD:EE:FF')
hub = MoveHub(conn)

Roadmap & TODO

Links