Python BLE library for LEGO WeDo 2.0 using gattlib (Raspberry Pi 4)
Project description
wedopython_rpi4
Python library for controlling LEGO® WeDo 2.0 devices using Bluetooth Low Energy (BLE) via gattlib.
This library is optimized for Raspberry Pi 4 running Linux (e.g. Raspberry Pi OS Buster).
Features
- Connect to LEGO WeDo 2.0 Smart Hub
- Control motors (start, stop, power, direction)
- Read distance sensor values
- Read tilt sensor values
- Play internal piezo sound tones
- Monitor battery level
Requirements
- Raspberry Pi 4 with built-in Bluetooth or external BLE dongle
- Linux OS with BLE support (tested on Raspberry Pi OS Buster)
- Python 3.7 or higher
gattlib==0.20210616
Installation
⚠ It is strongly recommended to use a virtual environment for installing this library.
sudo apt update
sudo apt install libbluetooth-dev python3-dev
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install gattlib manually (may require build tools)
pip install gattlib==0.20210616
# Then install this library
pip install wedopython_rpi4
Quick Example
from wedo2python.app import WeDo2Python
device = WeDo2Python("04:EE:03:16:ED:1D") # Replace with your WeDo Hub MAC
device.connect()
# Control motor on port B
device.motor_on("B")
device.set_motor_power("B", 70)
# Read tilt sensor on port A
device.tilt_sensor("A")
print("Tilt:", device.read_tilt_value())
# Disconnect
device.disconnect()
Finding the MAC address
Run:
bluetoothctl
scan on
Look for a device named LEGO Hub or similar. The MAC address should look like: 04:EE:03:16:ED:1D
License
This project is licensed under the GNU GPL v2 License.
You are free to use, modify, and distribute it under the terms of the license.
Author
Developed by Evangelia Anastasaki
Email: eveanast@gmail.com
Notes
This library was originally developed for research and educational use.
If you are looking for Raspberry Pi 5 support using bleak, see the companion project: wedo2py-rpi5
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wedopython_rpi4-1.2.0.tar.gz.
File metadata
- Download URL: wedopython_rpi4-1.2.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59a1320a7b4588001b31cc195fdd63703f13be2fbe0e90f2a97d71d520390cde
|
|
| MD5 |
9999ae8bb9c7dd7210f657fd908f6bda
|
|
| BLAKE2b-256 |
a013d4a3775a5cc7d2b50366abc991accbcfbe27be3624ee0552b9637c739a4d
|
Provenance
The following attestation bundles were made for wedopython_rpi4-1.2.0.tar.gz:
Publisher:
python-publish.yml on eveanast/wedopython_rpi4
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wedopython_rpi4-1.2.0.tar.gz -
Subject digest:
59a1320a7b4588001b31cc195fdd63703f13be2fbe0e90f2a97d71d520390cde - Sigstore transparency entry: 851693999
- Sigstore integration time:
-
Permalink:
eveanast/wedopython_rpi4@7824032472a43c303572b1122e661f4d9a5934eb -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/eveanast
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7824032472a43c303572b1122e661f4d9a5934eb -
Trigger Event:
release
-
Statement type:
File details
Details for the file wedopython_rpi4-1.2.0-py3-none-any.whl.
File metadata
- Download URL: wedopython_rpi4-1.2.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b011769255c3b3cebf302750936b8c4d18eb435c39aa73c2ccaba678bc442d9
|
|
| MD5 |
72057ce82c3fcfbcf3a36bf934a1970f
|
|
| BLAKE2b-256 |
f74b5500f1376ceb451761e0a46269d73c778a3cc52033e608faad267fd90f48
|
Provenance
The following attestation bundles were made for wedopython_rpi4-1.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on eveanast/wedopython_rpi4
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wedopython_rpi4-1.2.0-py3-none-any.whl -
Subject digest:
2b011769255c3b3cebf302750936b8c4d18eb435c39aa73c2ccaba678bc442d9 - Sigstore transparency entry: 851694038
- Sigstore integration time:
-
Permalink:
eveanast/wedopython_rpi4@7824032472a43c303572b1122e661f4d9a5934eb -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/eveanast
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7824032472a43c303572b1122e661f4d9a5934eb -
Trigger Event:
release
-
Statement type: