Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Python library for LEGO® PoweredUp devices

License

NotificationsYou must be signed in to change notification settings

undera/pylgbst

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Move Hub is central controller block ofLEGO® 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 intodemo.py file, and run it (assuming you have installed library).

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

Demonstrational Videos

Vernie ProgrammedLaser EngraverColor SorterFace TrackerColor Pin BotBB-8 Joystick

Dancing Vernie

Features

Usage

Please note that this library requires one of Bluetooth backend libraries to be installed, please read sectionhere 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:

frompylgbst.hubimportMoveHubhub=MoveHub()fordeviceinhub.peripherals:print(device)

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

Bluetooth Backend Prerequisites

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

  • pip install bleak -bleak lib, supports Linux/Windows/MacOS (recommended)
  • pip install pygatt -pygatt lib, works on both Windows and Linux
  • pip install gatt -gatt lib, supports Linux, does not work on Windows
  • pip install gattlib -gattlib - supports Linux, does not work on Windows, requiressudo
  • pip install bluepy -bluepy lib, supports Linux, including Raspbian, which allows connection to the hub from the Raspberry PI

Note thatpip 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 ofpygatt backend will only work with aBluegiga 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 Linuxsudo to be used when running Python.

Bluetooth Connection Options

There is an optional parameter forMoveHub class constructor, accepting instance ofConnection object. By default, it will try to use whateverget_connection_auto() returns. You have several options to manually control that:

  • useget_connection_auto() to attempt backend auto-detection
  • useget_connection_bluegiga() - if you use BlueGiga Adapter (pygatt library prerequisite)
  • useget_connection_gatt() - if you use Gatt Backend on Linux (gatt library prerequisite)
  • useget_connection_gattool() - if you use GattTool Backend on Linux (pygatt library prerequisite)
  • useget_connection_gattlib() - if you use GattLib Backend on Linux (gattlib library prerequisite)
  • useget_connection_bluepy() - if you use Bluepy backend on Linux/Raspbian (bluepy library prerequisite)
  • useget_connection_bleak() - if you use Bleak backend (bleak library prerequisite)

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 toMoveHub constructor. Like this:

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

Roadmap & TODO

  • validate operations with other Hub types (train, PUP etc)
  • make connections to detect hub by UUID instead of name
  • document all API methods

Links


[8]ページ先頭

©2009-2025 Movatter.jp