LED MATRIX

In this project, we're going to introduce a new component that can be used for a variety of purposes, including building games.  It's called an LED Matrix, and like the name implies, it is basically a small device that contains lots of little LEDs (64 of them, to be exact).  This is what an LED Matrix looks like (though yours won't have the smiley face just yet):

Included with the RaspberrySTEM Kit is a bag labeled, LED Matrix RaspberrySTEM Cell.  This bag contains all the parts that you'll need to build and program with an LED Matrix.  In that bag you should find the following:

Installing the Mounting Posts

The LED Matrix comes with two small mounting posts and screws that used to allow the LED Matrix display to attach to the breadboard.  The mounting posts should be installed prior to using the LED Matrix.  To install the mounting posts, follow these steps:

Step #1:  Remove the LED Display from the Circuit Board

The LED Matrix display is actually two parts, connected together by 16 pins (8 on each side).  To install the mounting posts, you'll will need to pull the top part (the LED Display) from the bottom part (the circuit board).  This is done by gripping the edges of the LED Display gently in one hand, gripping the edges of the circuit board gently in the other hand and lightly carefully the display from the board.  Try to apply equal pressure all around the display to avoid bending or breaking any pins.

Once the display is separate from the circuit board, set the display aside.

Step #2:  Attach the Mounting Posts to the Circuit Board

On the circuit board corners are four holes, two labeled "A" and two labeled "B".  You can attach the mounting posts either in the "A" holes or the "B" holes, but you will want to ensure that both mounting posts are attached to holes with the same label.  The mounting posts are attached with the screws coming down through the holes from the top and the pointy parts of the posts facing down from the bottom of the circuit board.  Use the triangular plastic piece (a guitar pick) to tighten the mounting post screws.

Step #3:  Re-Attach the LED Display to the Circuit Board

Once the mounting posts are secured and tightened, you'll need to re-attach the LED Display to the circuit board.  Holding the circuit board in one hand and the LED Display in the other, carefully align the 16 pins on the LED Display with the 16 holes on the circuit board.  Once the pins and holes are aligned, gently press the LED Display into the circuit board, applying equal pressure around the display to avoid damaging it.

Note:  There is a specific orientation for the LED display to be mounted on the LED Matrix circuit board.  You will want to ensure that the serial number on the LED display is facing up when the metal pins on the LED Matrix circuit board are facing to the left.  As another check to ensure the display is oriented correctly, the circuit board says "Matrix Top" on one side -- the serial number of the LED display should be facing this direction.

Power Up the LED Matrix

Note: For the next several projects, we'll be introducing new components that will require at least one-third of the breadboard space.  If you have enough room remaining on the breadboard, you can use that empty space; otherwise, we recommend removing some or all of the circuits you currently have on the breadboard to allow enough space for the next set of projects.

The first step in using the LED Matrix is to provide it power and ground.  While this won't be enough to do anything interesting with it, by doing this, we can at least verify that it's working properly.  Before you get started, you'll want to ensure that the breadboard has power (3.3V) and ground (GND) coming from the connector board.


Step #1:  Place the LED Matrix on the breadboard

Once the binding posts are attached to the LED Matrix, attaching it to the breadboard is as simple as inserting the binding posts into the breadboard anywhere you'd like.  You'll want to keep in mind that the LED Matrix doesn't connect to the breadboard electrically -- meaning it doesn't need to be attached to the breadboard to work.  All of the signals going between the RaspberrySTEM and the LED Matrix will be going over the LED Matrix cable, and not through the breadboard.

Step #2:  Attach LED Matrix Cable to the LED Matrix

Once the LED Matrix is situated on the breadboard, you're going to attach the LED Matrix cable.  This cable has two sides -- on one side is a connector that has five wires coming out it (though it is big enough to hold six wires).  On the other side of the cable are the loose ends of each of the five wires.  The side of the connector that has a six-wire connector will be attached to the side of the LED Matrix, with the empty wire hole align with the pin labeled RST.

Here is the correct positioning of the LED Matrix cable:

  

Note:  The LED Matrix cable may not have the same color wires indicated in the picture above.  The cable should be wired based on the location of the wires and pins, not the color of the wires.

Step #3:  Attach the 3.3V Pin to Power and GND to Ground

Once the cable is attached to the LED Matrix, you'll want to connect the 3.3V wire and the GND wire -- located at either end of the cable.  3.3V should attach to a point where 3.3V is coming into the breadboard and GND should attach to a point where GND is coming into the breadboard.  

Here is what your breadboard should look like at this point:

Once power and ground are correctly attached, you should see vertical and horizontal bars sweep across the display a single time.  This is indication that the LED Matrix is powered up and working correctly. 

If the LED Matrix powered up correctly, let's keep going...

Step #4:  Attach SCLK, MOSI, CE & MISO Pins to Connector Board

Now that we've verified that the LED Matrix can be powered up and is working properly, we can finish wiring it so that we can start controlling it with our software.  To finish wiring the LED Matrix we need to make four other connections, as follows:

  1. The wire running through the LED Matrix cable and connected to SLCK on the LED Matrix should be attached to the SLCK pin on the connector board

  2. The wire running through the LED Matrix cable and connected to MOSI on the LED Matrix should be attached to the SLCK pin on the connector board

  3. The wire running through the LED Matrix cable and connected to CE on the LED Matrix should be attached to the SLCK pin on the connector board

  4. Finally, a separate jumper wire (not included in the LED Matrix bag) should be connected from the MISO pin on the other side of the LED Matrix to the MISO pin on the connector board

Here is what the breadboard should look like with the LED Matrix fully connected:

Note:  If you have a wire attached to the RST pin on the LED Matrix, you have likely attached the LED Matrix cable upside down.  You will need to remove the cable and start over.

Testing the LED Matrix

In order to display graphics on our LED Matrix, we use a set of functions that allows us to create, draw, display and erase a framebuffer.

Framebuffers

A framebuffer is a piece of memory within a computer that is laid out in a similar fashion to whatever display you are using.  You can think of a framebuffer as a canvas that matches the size of whatever you are using to display graphics -- a monitor, a game console, a television set, an LED Matrix display, etc.  Generally speaking, framebuffers are used to display an entire window of graphics on the display at one time.

The typical sequence in which framebuffers are used is as follows:

  1. Erase the framebuffer so it is ready to be used

  2. Draw your graphics on the framebuffer behind the scenes (while it isn't being shown)

  3. Display your framebuffer with the drawn graphics

  4. Repeat

Even for tiny little displays like our 8x8 LED Matrix, a framebuffer provides a simple and efficient way to draw graphics.

Here is the basic code we'll use to initialize our LED Matrix and draw a single dot to it:


Let's take a look at what our code is doing:

When you run this code, you should see a dot appear on the LED Matrix towards the middle of the display.

prev| next