Skip to content
Sample code for the Jam HAT
Branch: master
Clone or download
Latest commit 4e02a28 Apr 25, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitattributes 🎉 Added .gitattributes Sep 26, 2018 Update Apr 25, 2019 Add comments to all GPIO Zero examples. Apr 8, 2019 Add comments to all GPIO Zero examples. Apr 8, 2019 Add comments to all GPIO Zero examples. Apr 8, 2019
jamhat_github.png Add files via upload Mar 21, 2019 Initial commit Sep 26, 2018

Jam HAT Sample Code

Jam Hat Sample Code

Welcome to the Jam HAT repo! Here you'll find example code to get you started with the Jam Hat.


For assembly instructions please refer to our Getting Started Guide.

GPIO Zero Class Available

The Jam Hat has been included in version 1.5 of GPIO Zero.

Ensure your version of GPIO Zero is up to date by opening a terminal window and typing:

sudo apt-get update
sudo apt-get install python3-gpiozero python-gpiozero

From there you can add the Jam Hat into your Python script by using.

# Import the JamHat from gpiozero along with sleep from time.
from gpiozero import JamHat
from time import sleep

# Make the JamHat object.
jamhat = JamHat()

# Turn on the JamHat lights and buzzer, wait for 1 second and then turn it off.

For more usage please refer to the Getting Started Guide or the GPIO Zero docs.

Pin Usage

For other projects you may want to use a library like RPi.GPIO in which case you will need to set up the pins by hand. The table below shows the pin numbers for BCM, Board and the matching GPIO Zero objects.

Component GPIO.BCM GPIO.BOARD GPIO Zero object Notes
LED1 GPIO 5 Pin 29
LED2 GPIO 6 Pin 31
LED3 GPIO 12 Pin 32 lights_1.yellow
LED4 GPIO 13 Pin 33 lights_2.yellow
LED5 GPIO 16 Pin 36
LED6 GPIO 17 Pin 11
Button 1 GPIO 19 Pin 35 button_1 Connected to R8/R10
Button 2 GPIO 18 Pin 12 button_2 Connected to R7/R9
Buzzer GPIO 20 Pin 38 buzzer

For example to set up the Red LED using RPi.GPIO:

# mport the library
import RPi.GPIO as GPIO

# Set the pin mode to be BCM

# Set LED1 to be an output.

# Turn LED1 on.

Example Scripts

There are several scripts here to show you what you can do with the Jam Hat.

This sample script shows you how to cycle through the leds, each led having a set pitch, then playing the pitch on the buzzer.

This sample script shows you how to make the buzzer buzz with the push of a button.

This sample script shows you how to use the buttons to create a simple counter.

Walk through the LEDs on the board.

Play the Mario Theme tune via the Buzzer. This currently uses RPi.GPIO but will be transferred over into GPIO Zero soon.

Submitting Issues

If you have an issue with the Jam Hat, please open an issue. When opening an issue please provide:

Setup information including

  • Raspbian version
  • GPIO Zero version
  • How you have connected the Jam Hat (on the Raspberry Pi, controlling pins over daemon etc.)
  • A sample of the code you've used
  • The error being presented.

Issues opened without this information will be closed off until this information can be provided.

You can’t perform that action at this time.