LEGO WeDo 2.0 BLE control library for Raspberry Pi using Bleak
Project description
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
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 wedo2py_rpi5-1.0.1.tar.gz.
File metadata
- Download URL: wedo2py_rpi5-1.0.1.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53f486d46bfb8f4f3dbd772115469d8efed5b23d91509de307c30e91f63f9ffd
|
|
| MD5 |
2e94157bf97e908feaa086ab40b585ce
|
|
| BLAKE2b-256 |
3d978ab933a94dad9461efb254f9bf3e1d78247785d44413927375feb33b305e
|
File details
Details for the file wedo2py_rpi5-1.0.1-py3-none-any.whl.
File metadata
- Download URL: wedo2py_rpi5-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b11a1832cadc6bae3b44be2fe912a8dfc33a910a1f8c469cfa9154829e28de8b
|
|
| MD5 |
88c900956be2ca416487bb6112655053
|
|
| BLAKE2b-256 |
c4d692806a8ee624db5baf56f7079db4c59fe267de98c141fba13d60fd38b219
|