Skip to main content

Build HAT Python library

Project description

Build HAT

The Python Build HAT library supports the Raspberry Pi Build HAT, an add-on board for the Raspberry Pi computer, which allows control of up to four LEGO® TECHNIC™ motors and sensors included in the SPIKE™ Portfolio.


The Build HAT provides four connectors for LEGO® Technic™ motors and sensors from the SPIKE™ Portfolio. The available sensors include a distance sensor, a colour sensor, and a versatile force sensor. The angular motors come in a range of sizes and include integrated encoders that can be queried to find their position.

The Build HAT fits all Raspberry Pi computers with a 40-pin GPIO header, including — with the addition of a ribbon cable or other extension device — Raspberry Pi 400. Connected LEGO® Technic™ devices can easily be controlled in Python, alongside standard Raspberry Pi accessories such as a camera module.


Library documentation:

Hardware documentation:

Projects and inspiration:


To install the Build HAT library, enter the following commands in a terminal:

pip3 install buildhat


See the detailed documentation for the Python objects available.

import time
from signal import pause
from buildhat import Motor

motor = Motor('A')

print("Position", motor.get_aposition())

def handle_motor(speed, pos, apos):
    print("Motor", speed, pos, apos)

motor.when_rotated = handle_motor

print("Run for degrees")

print("Run for seconds")

print("Run for rotations")

print("Start motor")
print("Stop motor")


Building locally

Using asdf:

asdf install


pip3 install . --user

Building the documentation

Instructions for regenerating the documentation can be found in docs/ Briefly, assuming you have the appropriate python modules installed:

$ (cd docs; make html)

will rebuild the documentation. The doc tree starts at docs/build/html/index.html

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

buildhat-0.5.12.tar.gz (156.9 kB view hashes)

Uploaded Source

Built Distribution

buildhat-0.5.12-py3-none-any.whl (57.8 kB view hashes)

Uploaded Python 3

Supported by

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