Home / Raspberry Pi Addons / Using the PiDie Raspberry Pi Addon Board

Using the PiDie Raspberry Pi Addon Board

Overview

There are 9 LEDs arranged in a 3×3 matrix:

  • 1, 2, 3 down left side (Red, Yellow, Green – ideal for use as traffic lights)
  • 4 in centre (Green)
  • 5, 6, 7 down right side (Yellow, White, Blue)

These 7 LEDs then form the dots on a dice. The matrix is completed with LED8 (Red – top centre) and LED9 (White – bottom centre)

1  8  5
2  4  6
3  9  7

The Buttons are Red (top left), Green (bottom left), Yellow (top right), Blue (bottom right) and the colours match the colours of the LEDs in the same corners. Ideal for use in the Simon game,

 

Pin Connections

These refer to the physical pin numbers on the GPIO header. If using gpio module in python, then set the mode to “board”.

LEDs:

  • Led1: 7
  • Led2: 11
  • Led3: 12
  • Led4: 13
  • Led5: 15
  • Led6: 16
  • Led7: 18
  • Led8: 22
  • Led9: 8

Buttons:

  • Red: 21
  • Green: 19
  • Yellow: 24
  • Blue: 26

 

Use in ScratchGPIO

Download the excellent ScratchGPIO by Simon Walters from here.

  • Create a variable called “AddOn”. In the green flag black, set the variable to “PiDie”
  • The LEDs are named Led1 to Led9
  • To switch a LED on or off, you can send a broadcast message, or use variables.
  • Using broadcasts. Create a new message specifying what you want to happen. The syntax is “Led1On” or “Led1Off”. Change the number to select a different LED:
  • Using variables. You should create variables called Led1 to Led9. You can use the variable setting blocks to switch them on or off:
  • You can also set them all on or all off with a broadcast “AllOff” or “AllOn”

 

Use in Python

  • Import the GPIO library: import RPi.GPIO as GPIO
  • Set the GPIO mode to board: GPIO.setmode(GPIO.BOARD)
  • Set the LED pins as outputs: GPIO.setup(7, GPIO.OUT) // 7 is the for LED1. You need to do this for each LED, or use lists, etc
  • Set the Button pins as inputs: GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) // 21 is the for the Red button. You need to do this for each button, or use lists, etc
  • Note that in the line above we are using the internal pullup resistors. This is mandatory for the buttons to work.
  • You can then set an LED On or Off by setting the output to 0 (ON) or 1 (OFF): GPIO.output(7, 0)
  • You can check if a button is pressed with an IF statement: if GPIO.input(21):

Comments are closed.