# 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](https://buildhat.readthedocs.io/en/latest/buildhat/index.html) for the Python objects available.
```python
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](https://github.com/asdf-vm/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`
Raw data
{
"_id": null,
"home_page": "https://github.com/RaspberryPiFoundation/python-build-hat",
"name": "buildhat",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Raspberry Pi Foundation",
"author_email": "web@raspberrypi.org",
"download_url": "https://files.pythonhosted.org/packages/d2/8d/6b1f4db036d8afaa09adf55eeefc673c63fd4bd0d9e2f21fa04b625b13d3/buildhat-0.7.0.tar.gz",
"platform": null,
"description": "# Build HAT\n\nThe 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\u00ae TECHNIC\u2122 motors and sensors included in the SPIKE\u2122 Portfolio.\n\n## Hardware\n\nThe Build HAT provides four connectors for LEGO\u00ae Technic\u2122 motors and sensors from the SPIKE\u2122 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.\n\nThe Build HAT fits all Raspberry Pi computers with a 40-pin GPIO header, including\u2009\u2014\u2009with the addition of a ribbon cable or other extension device\u2009\u2014\u2009Raspberry Pi 400. Connected LEGO\u00ae Technic\u2122 devices can easily be controlled in Python, alongside standard Raspberry Pi accessories such as a camera module.\n\n## Documentation\n\nLibrary documentation: https://buildhat.readthedocs.io\n\nHardware documentation: https://www.raspberrypi.com/documentation/accessories/build-hat.html\n\nProjects and inspiration: https://projects.raspberrypi.org/en/pathways/lego-intro\n\n## Installation\n\nTo install the Build HAT library, enter the following commands in a terminal:\n\n pip3 install buildhat\n\n## Usage\n\nSee the [detailed documentation](https://buildhat.readthedocs.io/en/latest/buildhat/index.html) for the Python objects available.\n\n```python\nimport time\nfrom signal import pause\nfrom buildhat import Motor\n\nmotor = Motor('A')\nmotor.set_default_speed(30)\n\nprint(\"Position\", motor.get_aposition())\n\ndef handle_motor(speed, pos, apos):\n print(\"Motor\", speed, pos, apos)\n\nmotor.when_rotated = handle_motor\n\nprint(\"Run for degrees\")\nmotor.run_for_degrees(360)\n\nprint(\"Run for seconds\")\nmotor.run_for_seconds(5)\n\nprint(\"Run for rotations\")\nmotor.run_for_rotations(2)\n\nprint(\"Start motor\")\nmotor.start()\ntime.sleep(3)\nprint(\"Stop motor\")\nmotor.stop()\n\npause()\n```\n\n## Building locally\n\nUsing [asdf](https://github.com/asdf-vm/asdf):\n\n```\nasdf install\n```\n\nThen:\n\n```\npip3 install . --user\n```\n\n### Building the documentation\n\nInstructions for regenerating the documentation can be found in\n`docs/README.md`. Briefly, assuming you have the appropriate python\nmodules installed:\n\n```\n$ (cd docs; make html)\n```\n\nwill rebuild the documentation. The doc tree starts at `docs/build/html/index.html`\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Build HAT Python library",
"version": "0.7.0",
"project_urls": {
"Bug Tracker": "https://github.com/RaspberryPiFoundation/python-build-hat/issues",
"Homepage": "https://github.com/RaspberryPiFoundation/python-build-hat"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ab9f7fc4f3b954431ff136f6d49d188ed0e0648a2faf444b22fde747cc2b51c9",
"md5": "7adb9a5bc00e45eb486fe1a3b5147f73",
"sha256": "f06d555eabce4647a82c4de13fe1cded44c8906d8534bcdd7279f78190306799"
},
"downloads": -1,
"filename": "buildhat-0.7.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7adb9a5bc00e45eb486fe1a3b5147f73",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 61508,
"upload_time": "2023-12-19T13:51:19",
"upload_time_iso_8601": "2023-12-19T13:51:19.026302Z",
"url": "https://files.pythonhosted.org/packages/ab/9f/7fc4f3b954431ff136f6d49d188ed0e0648a2faf444b22fde747cc2b51c9/buildhat-0.7.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d28d6b1f4db036d8afaa09adf55eeefc673c63fd4bd0d9e2f21fa04b625b13d3",
"md5": "cff76b052dba9ae7c866b427e6173bfa",
"sha256": "a0c30a9b9318a6e391afff971e99cdd8fb862e544941a0473f281fb11ff5c354"
},
"downloads": -1,
"filename": "buildhat-0.7.0.tar.gz",
"has_sig": false,
"md5_digest": "cff76b052dba9ae7c866b427e6173bfa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 160743,
"upload_time": "2023-12-19T13:51:20",
"upload_time_iso_8601": "2023-12-19T13:51:20.427783Z",
"url": "https://files.pythonhosted.org/packages/d2/8d/6b1f4db036d8afaa09adf55eeefc673c63fd4bd0d9e2f21fa04b625b13d3/buildhat-0.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-19 13:51:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "RaspberryPiFoundation",
"github_project": "python-build-hat",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "buildhat"
}