Introduction: 8x8 LED Matrix for RaspberryPi and 3 Programs
This is an 8x8 LED matrix for a RaspberryPi, and three programs to run on it:
1 - A "Hello World" program with a complete English font.
2 - A Dice game.
3 - A small 8x8 version of Conway's Game of Life.
You will need:
RaspberryPi (any model)
Adafruit Perma-Proto Raspberry Pi Breadboard PCB Kit http://www.adafruit.com/products/1135
One of these cables to connect the board to the RPi:
GPIO Ribbon Cable for Raspberry Pi Model A and B - 26 pin
Downgrade GPIO Ribbon Cable for Pi A+/B+/Pi 2 - 40p to 26p
Miniature 8x8 Red LED Matrix http://www.adafruit.com/product/454
8 resistors 330-560 Ohm 1/4 Watt.
1 resistor 10K Ohm 1/4 Watt.
Switch Button (12mm) http://www.adafruit.com/products/1119
22 ga hookup wire, red and black/
The RaspberryPi programs in this instructable use the wiringPi libraries, written by Gordon Henderson, for programming the GPIO in C.
wiringPi must be installed. Instructions for download, installation and use are located at http://wiringpi.com
wiringPi uses it's own pin numbering scheme.
All RaspberryPi pin numbers are wiringPi numbers unless otherwise specified.
Step 1: Mounting the Components
I am using a regular Adafruit Perma Proto full sized board and a cobbler in the illustrations because there is not a Fritzing part for the RaspberryPi board.The notch in the cable connector goes down, in the direction of the pink arrow.
There is not a Fritzing part for the LED matrix either. The pink lines are the solder points for the LED matrix. The writing on the side of the matrix goes down, in the direction of the pink arrow.
Solder the rest of the components as shown in the illustration.
Step 2: Start Wiring It
Solder the eight wires from the resistors to LED matrix, and the grounds for the switch and the ribbon connector.
Step 3: The First Layer of Wiring
Run eight black wires from the resistors to the ribbon connector. You will have to bend the wires around the LED matrix.
Step 4: The Top Layer of Wiring
Run eight wires from the LED matrix to the ribbon connector.
You will have to bend the wires around the LED matrix like in the photo in step 3.
Solder the red wire for the switch.
Step 5: The Program Files
Download the three program source files and the font data file for the "Hello World" program.
Rename the files back to the correct names. The filenames are on the first comment line in each file.
Use this command to compile the programs:
cc -o [FILENAME] -Wall -I/usr/local/include -L/usr/local/lib [FILENAME].c -lwiringPi -lpthread
The programs demonstrate the wiringPi ability to easily create a multi threaded program. All the work except for the actual display is done in the main thread which puts it in a global array. A second thread reads the array and turns the LEDs on or off in a continuous loop. Only one LED is actually lit at a time.
Step 6: Conway's Game of Life
Conway's game of life is a zero player game that simulates life. It is better on a bigger grid, but this shows how it works.
Put a pattern into the array in the program and compile it to see the result.
The program counts the adjacent LEDs that are on for all LEDs.
Then it turns on/off LEDs according to the following rules:
- If an LED is lit and less than two adjacent LEDs are lit it is turned off.
- If an LED is lit and more than three adjacent LEDs are lit it is turned off.
- If an LED is lit and two or three adjacent LEDs are lit it stays on.
- If an LED is not lit and exactly three adjacent LEDs are lit it is turned on.
Step 7: Dice Game
Start the program with the command:
Push the button and the LEDs will flash random. When the button is released you will see the numbers on two dice.
Step 8: Hello World
Start the program with the command:
The program displays the "Hello World" message and then the alphabet.
You can change the message to whatever you want it to say.