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.
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
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
File details
Details for the file buildhat-0.5.11.tar.gz
.
File metadata
- Download URL: buildhat-0.5.11.tar.gz
- Upload date:
- Size: 156.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14e62298c460764ef0c6e62f1389f9171e13646b3225e0c7c7f366b971e9f1ea |
|
MD5 | d901c25be6f1408857062aad6bcde270 |
|
BLAKE2b-256 | e7feae869f5bfe9228a7a4f45337e322133d95a7acc35aa0004bab95f84d24eb |
File details
Details for the file buildhat-0.5.11-py3-none-any.whl
.
File metadata
- Download URL: buildhat-0.5.11-py3-none-any.whl
- Upload date:
- Size: 57.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 583b0eddf323eb4f879023f83f5b5ce1c068fa2954f0002f8d6ec2f52693ff18 |
|
MD5 | fad9b3a358cdccd620c574ba6521b347 |
|
BLAKE2b-256 | fa26b0e73ce00c81c265186b685f8fa1f9a15511fe57dc46ac1034431d3c6a48 |