wedo2py-rpi5 - LEGO WeDo 2.0 BLE Python Library
Control LEGO WeDo 2.0 over Bluetooth Low Energy (BLE) using Python and the Bleak library. This package is designed primarily for Raspberry Pi 5 / Raspberry Pi OS Bookworm, but works on most modern Linux systems with BLE support.
Features
- Motor control (Port A / B)
- Tilt sensor (read orientation)
- Distance / Motion sensor
- LED color control
- Piezo / Sound tones
- Battery level readout
- GATT-based BLE communication (Bleak)
Requirements
- Python 3.9+
- Linux with BlueZ + Bluetooth LE
- Recommended device: Raspberry Pi 5
- BLE library: Bleak
Installation
1. Install System Dependencies (Raspberry Pi)
sudo apt update
sudo apt install bluetooth bluez python3-dbus
2. Create and Activate a Virtual Environment
python3 -m venv venv
source venv/bin/activate
3. Install the Package
pip install --upgrade pip
pip install wedo2py-rpi5
Note: Running outside a virtual environment may cause errors like:
error: externally-managed-environmentModuleNotFoundError: No module named 'bleak'
Quick Example
from wedo2python.app import WeDo2Python
hub = WeDo2Python("AA:BB:CC:DD:EE:FF") # Replace with your WeDo Hub MAC
hub.connect()
hub.set_color("green")
hub.motor_this_way(hub.port("B"))
hub.set_motor_power(hub.port("B"), 60)
hub.motor_on(hub.port("B"))
hub.disconnect()
LED Colors Supported
| Name | Value |
|---|---|
| off | 0 |
| pink | 1 |
| purple | 2 |
| blue | 3 |
| lightblue | 4 |
| cyan | 5 |
| green | 6 |
| yellow | 7 |
| orange | 8 |
| red | 9 |
| white | 10 |
Motor Example
hub.motor_this_way(hub.port("B")) # direction right
hub.motor_that_way(hub.port("B")) # direction left
hub.set_motor_power(hub.port("B"), 80) # power 0�100
hub.motor_on(hub.port("B"))
hub.motor_off(hub.port("B"))
Tilt Sensor
hub.tilt_sensor(hub.port("A"))
tilt = hub.read_tilt_value()
print(tilt)
Distance Sensor
hub.distance_sensor(hub.port("A"))
dist = hub.read_distance_value()
print(dist, "cm")
Sound (Piezo Tone)
The hub supports 16 internal tones:
hub.sound(1) # tone A
hub.sound(12) # tone cSH
hub.sound(16) # long tone
hub.sound_off()
Full List of Tones
| Tone ID | Description |
|---|---|
| 1 | A |
| 2 | F |
| 3 | cH |
| 4 | A (1000Hz) |
| 5 | eH |
| 6 | fH |
| 7 | gS |
| 8 | fS |
| 9 | G |
| 10 | aS |
| 11 | dH |
| 12 | cSH |
| 13 | B |
| 14 | fSH |
| 15 | A (500Hz) |
| 16 | cH (Long) |
Finding the Hub's MAC Address
bluetoothctl
scan on
Example output:
LEGO Hub 04:EE:03:16:ED:1D
Troubleshooting
| Issue | Solution |
|---|---|
| Cannot connect | Restart Hub, press button until LED flashes |
| Works once then disconnects | Wait 3 seconds before next connection |
| Motor doesn't run | Check correct port A/B |
| Tilt sensor gives wrong value | Ensure tilt sensor is on Port A |
| BLE permission denied | Run: sudo usermod -a -G bluetooth $USER && reboot |
License
This project is licensed under the Apache 2.0 License.
Credits
Developed by Evangelia Anastasaki
BLE Python library for LEGO WeDo 2.0, optimized for Raspberry Pi 5.
Project Links
- ?? PyPI Project
Metadata
Release files for wedo2py-rpi5 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wedo2py_rpi5-1.0.1.tar.gz | 13.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wedo2py_rpi5-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.6 kB
Release files / wedo2py_rpi5-1.0.1.tar.gz
| Download URL | wedo2py_rpi5-1.0.1.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
53f486d46bfb8f4f3dbd772115469d8efed5b23d91509de307c30e91f63f9ffd
|
|
BLAKE2b-256 checksum How to use checksums |
3d978ab933a94dad9461efb254f9bf3e1d78247785d44413927375feb33b305e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / wedo2py_rpi5-1.0.1-py3-none-any.whl
| Download URL | wedo2py_rpi5-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b11a1832cadc6bae3b44be2fe912a8dfc33a910a1f8c469cfa9154829e28de8b
|
|
BLAKE2b-256 checksum How to use checksums |
c4d692806a8ee624db5baf56f7079db4c59fe267de98c141fba13d60fd38b219
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|