LEGO Boost Robot in Python

April 10 , 2021

Requirements:

  • Raspberry Pi (1/2) and USB Bluethooth
  • OR
  • Raspberry Pi (3/4)

Using Windows is not recommended, because Bluetooth access from Python does not seem to be reliable abd GPIO will not be available.

The Python scripts should run in any Python 3 environment, but for GPIO functionality, a Raspi (Raspberry Pi 2/3/4) is required.

Also the comminucation with the LEGO hub is done using Bluetooth Low Energy (BLE) and I was only able to get a connection using Linux and a USB-Bluetooth stick.

Raspberry Pi 3/4 have Bluetooth built in and will not require any further USB stick.

Installation:

Python ist installed on Raspi already. It is recommended to use Python 3 and virtual-environments to install any dependencies.

venv is not installed by default and should be installed with this command:

sudo apt install python3-venv

Initialize venv:

python3 -m venv .venv

Activate venv:

source .venv/bin/activate

 

Python Dependencies:

You will need to install these Python dependencies:

pip3 install pyserial

 

Plotter Robot

 

Robot in action:

 

 

CODE:

All sourcecode is available on Github:

https://github.com/robig/LegoRobot

Tags: Python | LEGO | Robot

Next Post >