Skip to main content

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.

Hardware

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.

Documentation

Library documentation: https://buildhat.readthedocs.io

Hardware documentation: https://www.raspberrypi.com/documentation/accessories/build-hat.html

Projects and inspiration: https://projects.raspberrypi.org/en/pathways/lego-intro

Installation

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

pip3 install buildhat

Usage

See the detailed documentation for the Python objects available.

import time
from signal import pause
from buildhat import Motor

motor = Motor('A')
motor.set_default_speed(30)

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")
motor.run_for_degrees(360)

print("Run for seconds")
motor.run_for_seconds(5)

print("Run for rotations")
motor.run_for_rotations(2)

print("Start motor")
motor.start()
time.sleep(3)
print("Stop motor")
motor.stop()

pause()

Building locally

Using asdf:

asdf install

Then:

pip3 install . --user

Building the documentation

Instructions for regenerating the documentation can be found in docs/README.md. 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

Release files for buildhat 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for buildhat 0.9.0
File Size Uploaded
buildhat-0.9.0.tar.gz 159.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for buildhat 0.9.0
File Interpreter ABI Platform
buildhat-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 219.7 kB

Release files / buildhat-0.9.0.tar.gz

Download URL buildhat-0.9.0.tar.gz
Size 159.7 kB
Tags Source
SHA-256 checksum
How to use checksums
87b197b22a10664038cfe1f6f9d46cdb4ce52185936ba0276d028de15157dff7
BLAKE2b-256 checksum
How to use checksums
6c5954645876256c3b02b893baccfb6c69d0a4ebdc937c404284a9cd82220216
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.7

Release files / buildhat-0.9.0-py3-none-any.whl

Download URL buildhat-0.9.0-py3-none-any.whl
Size 59.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b3dfb0ff8679cc59a1420ed14068afef73b1ebd37d27040fed5af2d1d55a35f
BLAKE2b-256 checksum
How to use checksums
1198c0982d03314692f123d705174d5dc5d7cfdec2084ba8b90b45588b1d0919
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.12

2 release files

0.5.10

2 release files

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page