EricLathrop.com
Arduino 5x7 LED Maxtrix
I purchased a bunch of surplus parts from Electronic Goldmine and one of the parts I recieved was a Kingbright TA12-22GWA 5x7 LED matrix (datasheet). I was able to drive the display directly from my Arduino. I followed the example from this Arduinuo playground page.
Parts:
- 1x Arduino Diecimilia
- 1x Solderless breadboard
- 5x 100ohm resistor (brown, black, brown)
- 22AWG solid wire
Wiring It Up
Hook up Ardunio pins 0, 1, 2, 3, and 10 to the 100ohm resistors. The resistors limit the current to the LEDs so they don't burn out. Then hook up the resistors to pins 6, 3, 10, 11, and 13 of the display. These 5 pins control the columns of the display.
Next, hook up Arduino pins 6, 7, 8, 9, 11, 12, and 13 to pins 7, 5, 2, 1, 14, 9, and 8 of the display. These 7 pins control the rows of the display. The final wiring is shown below. The blue rectangles are where the pins of the display go, with pin 1 in the lower right of the picture.
The Code
First, you must install the FrequencyTimer2 library into your Ardunio development environment.
The FrequencyTimer2 library allows you to set a function to be called whenever a timer expires.
When the timer expires, it interrupts the currently executing code in loop() which can emulate two simultaneous threads of execution.
We will use one thread to read a screen buffer and light up the correct LEDs.
Another thread will alter the screen buffer to display animation.
The setup() function sets up all the pins as outputs, and sets them LOW.
Next, it uses the FrequencyTimer2 library to call displayByRows() every 2000 microseconds.
displayByRows() turns on the LEDs in a single row, enabling a different row each time it is called.
displayByRows() reads the state of each LED from the screen buffer.
Because displayByRows() is called very fast, it appears that all rows are lit at the same time.
Note: the code contains an alternate displayByCols() function which will loop through the columns of the display instead of the rows.
displayByRows() produced more even brightness for me.
The main loop() function calls scrollString() to scroll the alphabet and numbers across the screen.
scrollString() loops through each character calling getPattern() to get the correct Pattern for it.
The Pattern type is defined in Pattern.h as a 5x7 bitmap stored in the Arduino's flash memory.
The Patterns for all the characters must be stored in flash because they are too big to all fit into SRAM.
If you run out of SRAM the Arduino will behave erratically.
Once the correct patterns have been found, scrollString() calls scrollPattern() to scroll from one pattern to the next.
scrollPattern() loads the actual Pattern data from flash memory into the screen buffer in SRAM.
Download the code as an Arduino sketch released into the public domain.