Code Monkey home page Code Monkey logo

jam-hat's Introduction

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.

Assembly

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.
jamhat.on()
sleep(1)
jamhat.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 lights_1.red
LED2 GPIO 6 Pin 31 lights_2.red
LED3 GPIO 12 Pin 32 lights_1.yellow
LED4 GPIO 13 Pin 33 lights_2.yellow
LED5 GPIO 16 Pin 36 lights_1.green
LED6 GPIO 17 Pin 11 lights_2.green
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
GPIO.setmode(GPIO.BCM)

# Set LED1 to be an output.
GPIO.setup(5,GPIO.OUT)

# Turn LED1 on.
GPIO.output(5,1)

Example Scripts

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

button_led_piezo.py

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

button_piezo.py

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

buttons.py

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

led_ants.py

Walk through the LEDs on the board.

mario.py

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.

jam-hat's People

Contributors

tuftii avatar mmp-dave avatar lurch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.