Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wedopython_rpi4-1.2.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wedopython_rpi4-1.2.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

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

Hashes for wedopython_rpi4-1.2.0.tar.gz
Algorithm Hash digest
SHA256 59a1320a7b4588001b31cc195fdd63703f13be2fbe0e90f2a97d71d520390cde
MD5 9999ae8bb9c7dd7210f657fd908f6bda
BLAKE2b-256 a013d4a3775a5cc7d2b50366abc991accbcfbe27be3624ee0552b9637c739a4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for wedopython_rpi4-1.2.0.tar.gz:

Publisher: python-publish.yml on eveanast/wedopython_rpi4

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wedopython_rpi4-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wedopython_rpi4-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b011769255c3b3cebf302750936b8c4d18eb435c39aa73c2ccaba678bc442d9
MD5 72057ce82c3fcfbcf3a36bf934a1970f
BLAKE2b-256 f74b5500f1376ceb451761e0a46269d73c778a3cc52033e608faad267fd90f48

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page