{"id":16800481,"url":"https://github.com/undera/pylgbst","last_synced_at":"2025-05-16T11:06:26.481Z","repository":{"id":38804405,"uuid":"103387892","full_name":"undera/pylgbst","owner":"undera","description":"Python library for LEGO® PoweredUp devices","archived":false,"fork":false,"pushed_at":"2025-01-04T11:50:14.000Z","size":367,"stargazers_count":566,"open_issues_count":30,"forks_count":124,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-05-12T04:46:33.521Z","etag":null,"topics":["lego","lego-boost","python","robotics"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/undera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-13T10:46:13.000Z","updated_at":"2025-04-25T07:41:26.000Z","dependencies_parsed_at":"2024-06-21T19:06:25.635Z","dependency_job_id":"64a578d3-a853-467f-8b70-90f58bfa799a","html_url":"https://github.com/undera/pylgbst","commit_stats":{"total_commits":322,"total_committers":20,"mean_commits":16.1,"dds":0.1490683229813664,"last_synced_commit":"d7bfb73458866f60f9800c3a138d8f2392b05a9f"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/undera%2Fpylgbst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/undera%2Fpylgbst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/undera%2Fpylgbst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/undera%2Fpylgbst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/undera","download_url":"https://codeload.github.com/undera/pylgbst/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518383,"owners_count":22084374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lego","lego-boost","python","robotics"],"created_at":"2024-10-13T09:33:28.359Z","updated_at":"2025-05-16T11:06:21.472Z","avatar_url":"https://github.com/undera.png","language":"Python","readme":"# Python library to interact with Move Hub / PoweredUp Hubs\n\n_Move Hub is central controller block of [LEGO® Boost Robotics Set](https://www.lego.com/themes/boost)._\n\nIn 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.\n\nThe best way to start is to look into [`demo.py`](examples/demo.py) file, and run it (assuming you have installed library).\n\nIf you have Vernie assembled, you might run scripts from [`examples/vernie`](examples/vernie) directory.\n\n## Demonstrational Videos\n\n[![Vernie Programmed](http://img.youtube.com/vi/oqsmgZlVE8I/0.jpg)](http://www.youtube.com/watch?v=oqsmgZlVE8I)\n[![Laser Engraver](http://img.youtube.com/vi/ZbKmqVBBMhM/0.jpg)](https://youtu.be/ZbKmqVBBMhM)\n[![Color Sorter](http://img.youtube.com/vi/829RKT8v8M0/0.jpg)](https://youtu.be/829RKT8v8M0)\n[![Face Tracker](http://img.youtube.com/vi/WUOa3j-6XfI/0.jpg)](https://youtu.be/WUOa3j-6XfI)\n[![Color Pin Bot](http://img.youtube.com/vi/QY6nRYXQw_U/0.jpg)](https://youtu.be/QY6nRYXQw_U)\n[![BB-8 Joystick](http://img.youtube.com/vi/55kE9I4IQSU/0.jpg)](https://youtu.be/55kE9I4IQSU)\n\n[Dancing Vernie](https://youtu.be/Cp2gDleP8_M)\n\n\n## Features\n\n- auto-detect and connect to [Move Hub](docs/MoveHub.md) device\n- auto-detects [peripheral devices](docs/Peripherals.md) connected to Hub\n- constant, angled and timed movement for [motors](docs/Motor.md), rotation sensor subscription\n- [vision sensor](docs/VisionSensor.md): several modes to measure distance, color and luminosity\n- [tilt sensor](docs/TiltSensor.md) subscription: 2 axis, 3 axis, bump detect modes\n- [RGB LED](docs/LED.md) color change\n- [Headlight](docs/Headlight.md) brightness change\n- [push button](docs/MoveHub.md#push-button) status subscription\n- [battery voltage and current](docs/VoltageCurrent.md) subscription available\n\n\n## Usage\n\n_Please note that this library requires one of Bluetooth backend libraries to be installed, please read section [here](#bluetooth-backend-prerequisites) for details._\n\nInstall library like this: \n```bash\npip install -U pylgbst[bleak]\n```\n\nThen instantiate MoveHub object and start invoking its methods. Following is example to just print peripherals detected on Hub:  \n\n```python\nfrom pylgbst.hub import MoveHub\n\nhub = MoveHub()\n\nfor device in hub.peripherals:\n    print(device)\n```\n\nEach peripheral kind has own methods to do actions and/or get sensor data. See [features](#features) list for individual doc pages.\n\n## Bluetooth Backend Prerequisites\n\nYou have following options to install as Bluetooth backend (some of them might require `sudo` on Linux):\n\n- `pip install bleak` - [bleak](https://github.com/hbldh/bleak) lib, supports Linux/Windows/MacOS (__recommended__)\n- `pip install pygatt` - [pygatt](https://github.com/peplin/pygatt) lib, works on both Windows and Linux  \n- `pip install gatt` - [gatt](https://github.com/getsenic/gatt-python) lib, supports Linux, does not work on Windows\n- `pip install gattlib` - [gattlib](https://bitbucket.org/OscarAcena/pygattlib) - supports Linux, does not work on Windows, requires `sudo`\n- `pip install bluepy` - [bluepy](https://github.com/IanHarvey/bluepy) lib, supports Linux, including Raspbian, which allows connection to the hub from the Raspberry PI\n\nNote 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.\n\nWindows 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](https://www.silabs.com/products/wireless/bluetooth/bluetooth-low-energy-modules/bled112-bluetooth-smart-dongle).\n\n_Please let author know if you have discovered any compatibility/preprequisite details, so we will update this section to help future users_\n\nDepending on backend type, you might need Linux `sudo` to be used when running Python.\n\n### Bluetooth Connection Options\nThere 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:\n\n- use `get_connection_auto()` to attempt backend auto-detection \n- use `get_connection_bluegiga()` - if you use BlueGiga Adapter (`pygatt` library prerequisite)\n- use `get_connection_gatt()` - if you use Gatt Backend on Linux (`gatt` library prerequisite)\n- use `get_connection_gattool()` - if you use GattTool Backend on Linux (`pygatt` library prerequisite)\n- use `get_connection_gattlib()` - if you use GattLib Backend on Linux (`gattlib` library prerequisite)\n- use `get_connection_bluepy()` - if you use Bluepy backend on Linux/Raspbian (`bluepy` library prerequisite)\n- use `get_connection_bleak()` - if you use Bleak backend (`bleak` library prerequisite)\n\nAll 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.\n\nIf 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:\n```python\nfrom pylgbst.hub import MoveHub\nfrom pylgbst import get_connection_gatt\n\nconn = get_connection_gatt(hub_mac='AA:BB:CC:DD:EE:FF')\nhub = MoveHub(conn)\n```\n\n## Roadmap \u0026 TODO\n\n- validate operations with other Hub types (train, PUP etc)\n- make connections to detect hub by UUID instead of name\n- document all API methods\n\n## Links\n\n- https://github.com/LEGO/lego-ble-wireless-protocol-docs - true docs for LEGO BLE protocol\n- https://github.com/JorgePe/BOOSTreveng - initial source of protocol knowledge\n- https://github.com/nathankellenicki/node-poweredup - JavaScript version of library\n- https://github.com/spezifisch/sphero-python/blob/master/BB8joyDrive.py - example with another approach to bluetooth libs\n- https://github.com/virantha/bricknil - for the lovers of async Python, alternative implementation of library to control PoweredUp Hubs\n- https://virantha.github.io/bricknil/lego_api/lego.html - good infor about modes by BrickNil","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fundera%2Fpylgbst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fundera%2Fpylgbst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fundera%2Fpylgbst/lists"}