LED Matrix

When it come to outputs from microchips, you just about can’t beat LEDs. So what better way we use what we learned in the shift register post than to learn about LED Matrix displays!

If you didn’t read the Arduino tutorial last time, now might be a good time (particularly “example 2”) [here].
Also for a quick revision on the shift register concept here is an animation.

So this time we are hooking up two shift registers to the Arduino and using the 16 outputs to drive the rows and columns for an LED Matrix.

How do we do this?

We go ahead and setup one shift register as before, then we add another one beside it. We use a common clock and latch between the two, but feed the data into the first and feed the overflow of the first into the second.

This means if we “shiftout” the column data first (active has as it is fed into the anode); then “shiftout” the row data (inverted to active low – cathode); we will get control of each individual led.

The circuit diagram for the matrix is under “SZ 20788” [here].

See the code for more!

This is the result:

Some pictures (might help – its a mess due to the LED Matrix’s pin layout.):

The Code:

int latchPin = 8;
int clockPin = 12;
int dataPin = 11;

byte column[8] = {128,64,32,16,8,4,2,1};
byte row[8];

void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {
for (int character = 0; character < 11; character ++){
switch (character) {
case 0:
row[0] = 0b00000000;
row[1] = 0b00011000;
row[2] = 0b00100100;
row[3] = 0b00101100;
row[4] = 0b00110100;
row[5] = 0b00100100;
row[6] = 0b00011000;
row[7] = 0b00000000;
break;
case 1:
row[0] = 0b00000000;
row[1] = 0b00010000;
row[2] = 0b00110000;
row[3] = 0b00010000;
row[4] = 0b00010000;
row[5] = 0b00010000;
row[6] = 0b00111000;
row[7] = 0b00000000;
break;
case 2:
row[0] = 0b00000000;
row[1] = 0b00011000;
row[2] = 0b00100100;
row[3] = 0b00000100;
row[4] = 0b00011000;
row[5] = 0b00100000;
row[6] = 0b00111100;
row[7] = 0b00000000;
break;
case 3:
row[0] = 0b00000000;
row[1] = 0b00111000;
row[2] = 0b00000100;
row[3] = 0b00011000;
row[4] = 0b00000100;
row[5] = 0b00000100;
row[6] = 0b00111000;
row[7] = 0b00000000;
break;
case 4:
row[0] = 0b00000000;
row[1] = 0b00100000;
row[2] = 0b00101000;
row[3] = 0b00101000;
row[4] = 0b00111100;
row[5] = 0b00001000;
row[6] = 0b00001000;
row[7] = 0b00000000;
break;
case 5:
row[0] = 0b00000000;
row[1] = 0b00111100;
row[2] = 0b00100000;
row[3] = 0b00111000;
row[4] = 0b00000100;
row[5] = 0b00000100;
row[6] = 0b00111000;
row[7] = 0b00000000;
break;
case 6:
row[0] = 0b00000000;
row[1] = 0b00011100;
row[2] = 0b00100000;
row[3] = 0b00111000;
row[4] = 0b00100100;
row[5] = 0b00100100;
row[6] = 0b00011000;
row[7] = 0b00000000;
break;
case 7:
row[0] = 0b00000000;
row[1] = 0b00111100;
row[2] = 0b00000100;
row[3] = 0b00001000;
row[4] = 0b00010000;
row[5] = 0b00010000;
row[6] = 0b00010000;
row[7] = 0b00000000;
break;
case 8:
row[0] = 0b00000000;
row[1] = 0b00011000;
row[2] = 0b00100100;
row[3] = 0b00011000;
row[4] = 0b00100100;
row[5] = 0b00100100;
row[6] = 0b00011000;
row[7] = 0b00000000;
break;
case 9:
row[0] = 0b00000000;
row[1] = 0b00011000;
row[2] = 0b00100100;
row[3] = 0b00100100;
row[4] = 0b00011100;
row[5] = 0b00000100;
row[6] = 0b00111000;
row[7] = 0b00000000;
break;
case 10:
row[0] = 0b00000000;
row[1] = 0b00100100;
row[2] = 0b00100100;
row[3] = 0b00000000;
row[4] = 0b00000000;
row[5] = 0b00100100;
row[6] = 0b00011000;
row[7] = 0b00000000;
break;
}
for (int refreshed = 0; refreshed < 255; refreshed++){
for (int count = 0; count < 8; count ++){
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, column[count]);
shiftOut(dataPin, clockPin, MSBFIRST, 0b11111111-row[count]);
digitalWrite(latchPin, HIGH);
}
}
}
}
Advertisements

7 responses to “LED Matrix

  1. Your tutorials are very helpful. I’m working on an 8x8x8 LED cube. All my leds and components are on the way, but in the meantime I’m trying to figure out how to use shift registers on a prototype 3x3x3 cube. It would be interesting if you did a small LED cube like a 3x3x3 with shift registers.

    Thanks

    • Yeh i could definately do that. It won’t be for a little while though as i am a few weeks out of my uni exams. The next tut I was going to do is using the MAX7219 LED driver, that could also be useful for you. Again I will be publishing that when I’m less busy. If you subscribe, you will be notified when I get them done. Cheers!

  2. Nice job man, this tutorial this tutorial is very good nad helpful. I wanted to ask u can I make one larger display with same logic, using one 74HC595 for Row and more 74HC595 for columns and scroll text trough? maybe 32×8 Led display

    tnx.

  3. Yes you can certainly do that Alex.
    You just add enough shift registers so that you have enough outputs for the rows and columns.
    For a 32×8 matrix, you would need 5 shift registers each being fed data from the previous.
    Be aware that with more and more shift out commands, the refresh rate will slow down.
    I recently made a table tennis scoreboard with a 32×8 matrix display but used a pre designed serial controlled display which was great.
    [link]
    You can get them at “sure electronics” for cheap.
    Good Luck.

  4. it is GREAT ,,can u help me to get a code to a scrolling msg on this 8*8 dot matrix plzzzz ???

  5. Thanks for this post, I’ve been looking for an example of LED matricies with only 74HC595s since I don’t have any MAX7219s on hand. One question though – how come only the second register’s pins have resistors on them?

    • The reason that only one shift register has resistors is that each led only needs one resistor. The register that hasn’t got the LEDs is cycling through one output at a time. This means that at any point, there can only be 8 LEDs on at once (8 resistors). This happens so quickly that you cannot see it happening…

      I hope this is correct. It has been a long time since I did this and I can’t remember if this is refreshed quickly or the LEDs are on constantly.. Anyway I would work with that answer above as you generally don’t want them all on at once due to current issues…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s