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.

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:

sudo 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


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.7.tar.gz (151.4 kB view details)

Uploaded Source

Built Distribution

buildhat-0.5.7-py3-none-any.whl (52.3 kB view details)

Uploaded Python 3

File details

Details for the file buildhat-0.5.7.tar.gz.

File metadata

  • Download URL: buildhat-0.5.7.tar.gz
  • Upload date:
  • Size: 151.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for buildhat-0.5.7.tar.gz
Algorithm Hash digest
SHA256 dcf4e41d8ce5a42a354dabfa1b7523aba4708b4a545cbc54258dc46dff36b7d7
MD5 fb0b49902551a29c85c6a7797c2f89e7
BLAKE2b-256 14e84aa88c9e020a70b68a9dd946d22be7d9eb08f19e1a9b52eff758558381cd

See more details on using hashes here.

File details

Details for the file buildhat-0.5.7-py3-none-any.whl.

File metadata

  • Download URL: buildhat-0.5.7-py3-none-any.whl
  • Upload date:
  • Size: 52.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2

File hashes

Hashes for buildhat-0.5.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1ddccbb92c4728b76807c22e7659b7f4f354c0c89599ed2c6e217cb02eb823d6
MD5 44a66f8c608058dae315f26e7a4ee581
BLAKE2b-256 356db0f41cce0b981f17617908d059cf71c3e3cf1687470e59d59e3794859557

See more details on using hashes here.

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