Some notes on programming the Peggy 2.0. Basic example source code is included; we will be expanding this article soon with additional examples and libraries. Your own contributions will be welcome too, of course!
The Big Idea (or, how it works).
Peggy 2.0 is a multiplexed matrix display of 25×25 LEDs. That means that we turn on one row at a time, and write to that row which of its LEDs should be on. We then turn that row off, turn on selected LEDs in the next row and repeat, scanning through all 25 rows so quickly that there is no apparent flicker, just a continuous image.
This process is managed by the on-board microcontroller, an ATmega168, a type of AVR microcontroller. The row that is in use is picked by the PORTD I/O ports. Bits D0-D3 and D4-D7, respectively, are 4-bit output ports that go to two 74HC154 4-to-16 demultiplexers. Bits D0-D3 go to the first of these chips and the binary number that is sent, ranging from (decimal) 1 to 15 picks which of the rows 0-14 is powered on. A binary output of zero enables none of the rows. Similarly, bits D4-D7 pick which of rows 15-24 is powered on. Again, a binary output of zero on D4-D7 enables none of the rows.
An “enabled” row has power applied to the high side of each of the LEDs in that row. To determine which of the LEDs is turned on, we use two 16-bit LED driver chips (type STP16DP05) that are connected by a daisy-chained SPI output. Output four bytes on the SPI, of which the last 25 bits control the 25 columns of the LED display. To latch the SPI values in place, issue a brief pulse on pin PB1.
That’s a bit of a mouthful, and fortunately, you don’t have to do this all yourself, it’s written for you. We have several sample applications that demonstrate different ways to run the display, in varying degrees of complexity. We will continue to add additional code examples in the near future.
We have written a simple-function high-level Arduino library to control Peggy 2.0. You can download the library, along with examples, and read usage notes here.
Additional Arduino Environment Examples
The following code examples are meant to be run with the Arduino environment and a USB-TTL cable.
(Use the Arduino software environment and tell the Arduino software that you have a Diecimila.)
These are simple, highly functional, and ready to use, but use fairly low-level access to the Arduino (AVR) hardware to accomplish their goals; these are not written in the format of most Arduino programs that use libraries.
peggy2_GrayTest.pde: A simple application that demonstrates running a Peggy 2.0 display with 16 levels of grayscale. (Pictured above, on a display with 10 mm white diffused LEDs.) It’s slow software PWM and doesn’t leave much room for animation, but isn’t it cool? You could probably put your picture on Peggy and hang it on the wall. :)
peggy_life.pde: Conway’s life application; a more complex and computationally intensive routine with interactive editor (i.e., drawing program) and display refresh routines built in.
Some code examples meant to be run with the AVR-GCC toolchain and an ISP programmer
peggy2.zip: Default firmware; lights LEDs uniformly. Good to test for damaged LEDs, should that become necessary. Presents two unsigned int arrays that can be modified to change what’s on the display.
peggy2_Sweep.zip: Simple example showing one row and then one column lit at a time.
Peggy2Life.zip: Conway’s life application; a more complex and computationally intensive routine with interactive editor (i.e., drawing program) and display refresh routines built in.
(More coming soon!)