8x8 LED Matrix on Arduino Nano

Hi there,

I’ve had a spare Arduino Nano lying around for years and wanted to hook it up to an LED Matrix.
I don’t have a MAX7219, but I thought the Nano should have enough outputs to handle this anyway.

This is how I hooked it up:

I made an array that maps the pins of the matrix to the corresponding pins of the Nano. I also created to arrays to map rows and columns to the pins of the led matrix.

int ROWS[8] = { 9, 14,  8, 12,  1,  7,  2,  5};
int COLS[8] = {13,  3,  4, 10,  6, 11, 15, 16};

int PINS[16] = {12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
                13, 14, 15, 16, 17};

I am then trying to light up the top left LED using the following code:

void setup() 
{
  for (int i = 0; i < sizeof(PINS) / sizeof(int); i++)
  {
    int pin = PINS[i];
    pinMode(pin, OUTPUT);
  }
}

void loop() 
{
  int row = 0;
  int col = 0;

  for (int i = 0; i < sizeof(ROWS) / sizeof(int); i++)  
  {
    int rowPin = PINS[ROWS[i]-1];
    digitalWrite(rowPin, i == row);
    
    for (int j = 0; j < sizeof(COLS) / sizeof(int); j++)  
    {    
      int colPin = PINS[COLS[j]-1];
      digitalWrite(colPin, j != col);
    }
  }
}

And this is the result:

I fiddled around a little bit, but got more and more confused. I must be doing something fundamentally wrong. Any ideas?

Greetings

I hope I didn’t mess this up too much (haven’t tried to compile it)

Instead of your loop() I would do something like this:

int data[8] = {
  0b10000000,
  0b01000000,
  0b00100000,
  0b00010000,
  0b00000110,
  0b00001001,
  0b00001001,
  0b00000110
};

int currentRow = 0;
void loop()
{
  digitalWrite(ROWS[currentRow], 0); // Prevent ghost image

  currentRow++;
  currentRow = currentRow % 8; // Wrap around to first row

  // Prepare columns for the active row
  int value = data[currentRow];
  for(int col = 0; col < 8; col++)
  {
    digitalWrite(COLS[col], (value & 1) == 0);
    value = value >> 1;
  }

  // Activate the row
  digitalWrite(ROWS[currentRow], 1);

  delay(10);
}

Anodes should connect to the rows, cathodes to the columns.

SecondSun:
I fiddled around a little bit, but got more and more confused. I must be doing something fundamentally wrong. Any ideas?

There are two basic types of 8x8 LED matrices.

row anode column cathode
row cathode column anode

which one do you have?

You also don't have any current limiting resistors for your LEDs. Not good.

.

had a spare Arduino Nano lying around for years

and now you want to destroy it? You are on the right track.

There are two basic types of 8x8 LED matrices.

row anode column cathode
row cathode column anode

What if you took the first type, and rotated it by 90 degrees?

PaulRB:
What if you took the first type, and rotated it by 90 degrees?

Tried this with a 7-segment display a few weeks ago… You can make it work, but you end up with a lot of fiddling to set the bits right.

Rintin:
Tried this with a 7-segment display a few weeks ago… You can make it work, but you end up with a lot of fiddling to set the bits right.

You are missing my point. With an 8x8 single colour led matrix, if you have anode rows and cathode columns, and you rotate it by 90 degrees, it becomes anode columns and cathode rows. Electrically (and visually) there is no difference. Physically, of course, the pins on the back will be in different places.

If you turn a 7-seg display by 90 degrees, you’ll get a crick in the neck trying to read it. Perhaps I am missing your point.

It looks to be one of these: http://uk.farnell.com/kingbright/ta23-11gwa/display-2-3-8x8-green-com-anode/dp/2290404

PaulRB:
What if you took the first type, and rotated it by 90 degrees?

Yes I have done that.

SecondSun:
It looks to be one of these: http://uk.farnell.com/kingbright/ta23-11gwa/display-2-3-8x8-green-com-anode/dp/2290404

If that is what you have, then it is a row cathode common anode.

You can still use the tutorial I linked above in reply #2.
Physically you rotate the display 90 degrees

.

If you use the tutorial I linked above in reply #2,

what is used in the tutorial:

what you have rotated:

pin 9 of your 8x8 would go to where pin 13 of the other type of display would be connected to on the Arduino
pin 14 of your 8x8 would go to where pin 3 of the other type of display would be connected to on the Arduino

and so forth

I hope that makes sense.

Yeah it looks like I have to set the column to HIGH and the row to LOW for the LED to light up.
I also seemed to have had some cables swapped in my wiring.
Still, when I try to power a single LED, I always get multiple LEDs to light up (not even limited to the same row or column).

My current program looks like this:

int ROWS[8] = { 9, 14,  8, 12,  1,  7,  2,  5};
int COLS[8] = {13,  3,  4, 10,  6, 11, 15, 16};

int PINS[16] = {12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
                13, 14, 15, 16, 17};

void setup() 
{
  for (int i = 0; i < sizeof(PINS) / sizeof(int); i++)
  {
    int pin = PINS[i];
    pinMode(pin, OUTPUT);
  }

  // Set all rows to HIGH so that no LED would light up
  for (int i = 0; i < sizeof(ROWS) / sizeof(int); i++)
  {
    digitalWrite(PINS[ROWS[i]], HIGH); 
  }
}

void loop() 
{
  digitalWrite(PINS[COLS[0]-1], HIGH);
  digitalWrite(PINS[ROWS[0]-1], LOW);
}

You need to put resistors in your circuit or you will blow out your LEDs eventually.

You are not allowing for delays in human eye's reaction time in your code.

I don't have the patience to wire up a 8x8 again, so I won't be able to go further with you on this.
Good luck.

.

It looks like the values in the ROWS and COLS arrays are indices into the PINS array (plus one), not pin numbers themselves.

It's not clear what you're doing in loop() but the '-1' in there seems appropriate as the values in ROWS and COLS are 1-based, not zero-based.

In your setup() where you want to set all rows high, the '-1' is not there.

Also, make sure you have the pins wired up correctly. The indirection makes it non-obvious.

Your rows are:
PINS[ROW[0]-1] = 4
PINS[ROW[1]-1] = 15
PINS[ROW[2]-1] = 5
PINS[ROW[3]-1] = 13
etc..

Your columns are:
PINS[COLS[0]-1] = 14
PINS[COLS[1]-1] = 10
PINS[COLS[2]-1] = 9
PINS[COLS[3]-1] = 3
etc..

Or... the problem could be that the Nano's pins are damaged by sourcing or sinking too much current, what with no current limiting resistors and no transistors or buffer chips to deal with all that current... Depending how they have been abused, they could be low when they have been set to high, or vice-versa, or... But the OP is studiously ignoring these criticisms!

Unfortunately the tutorial that I linked which is on the Arduino website also ignores resistors.
Very bad!

.

PaulRB:
Or... the problem could be that the Nano's pins are damaged by sourcing or sinking too much current, what with no current limiting resistors and no transistors or buffer chips to deal with all that current... Depending how they have been abused, they could be low when they have been set to high, or vice-versa, or... But the OP is studiously ignoring these criticisms!

Go blame the guy who put that tutorial on the official arduino website.

Though if the board had been damaged, it would have occured at the very beginning, before I even posted here. Your snide comment about how I am going to destroy the arduino without any explanation is by far the least productive thing in this entire thread. How about you come off your high horse and talk eye-to-eye with a puny uninformed peasant like myself?

SecondSun:
Go blame the guy who put that tutorial on the official arduino website.

Though if the board had been damaged, it would have occured at the very beginning, before I even posted here. Your snide comment about how I am going to destroy the arduino without any explanation is by far the least productive thing in this entire thread. How about you come off your high horse and talk eye-to-eye with a puny uninformed peasant like myself?

I linked that tutorial.

You did not tell us what you were doing including which tutorial, if any, you were reading.

It wasn’t until #15 that you mentioned it. I suggest that you stop with the indignation routine.

.

Though if the board had been damaged, it would have occured at the very beginning, before I even posted here.

That is simply not true, which you would know if you weren’t so arrogant.

It is hard to help someone so resistant to learning.

Why do you think we say such things? We are not jerking you arround, we are given good solid advice.

SecondSun:
Your snide comment about how I am going to destroy the arduino without any explanation is by far the least productive thing in this entire thread.

You are right, it has, until now, been completely unproductive. That was post #3. Here we are 15 posts later and only now, after several repeat prompts, are you finally asking what I meant. Like many forum members, I am fed up with writing long explanations only to have them ignored. So I posted a short and hopefully provoking post to see what reaction it got. Then I could judge the level of attention the OP was going to give the thread they started. All too often, newbies give up as soon as they realise electronics, as a hobby, takes concentration, determination and willingness to learn.

So, still interested to find out why you are damaging the Nano and/or matrix?

ieee488:
I linked that tutorial.

You did not tell us what you were doing including which tutorial, if any, you were reading.

It wasn't until #15 that you mentioned it. I suggest that you stop with the indignation routine.

Yes, I had a look at quite a few tutorials before posting here and that was the one that convinced me that I could hook up the matrix directly to the board.
I also don't have any resistors lying around that I could use for current limiting purposes. I also don't have the time to order the parts I would need, because what I intend to do with it, needs to be done in a few days or not at all. If I had the time, I would have ordered a pre-assembled matrix with a MAX7219 and resistors on a chip.

Also you don't think there is a problem with that tutorial being there if it's such bad practice??

Grumpy_Mike:
That is simply not true, which you would know if you weren’t so arrogant.

It is hard to help someone so resistant to learning.

Why do you think we say such things? We are not jerking you arround, we are given good solid advice.

You were, I was merely criticising PaulRB, who was not. As he himself stated, he only wanted to "provoke". That isn't arrogance on my part. I was really trying hard and testing all of your suggestions thouroughly.

PaulRB:
You are right, it has, until now, been completely unproductive. That was post #3. Here we are 15 posts later and only now, after several repeat prompts, are you finally asking what I meant. Like many forum members, I am fed up with writing long explanations only to have them ignored. So I posted a short and hopefully provoking post to see what reaction it got. Then I could judge the level of attention the OP was going to give the thread they started. All too often, newbies give up as soon as they realise electronics, as a hobby, takes concentration, determination and willingness to learn.

So, still interested to find out why you are damaging the Nano and/or matrix?

I do not plan to pick up electronics as a hobby. I just wanted to get something done. Call me foolish for that or even lazy, but one cannot learn everything. I do have some basic knowledge in electronics, which led me to believe that trying to light up a single LED without a resistor wouldn't be much of a problem. Again call me whatever for thinking that.

I thank you guys for all the effort you have made in trying to answer my question and I am really sorry that the thread has derailed in such a way. I never wanted to come across as arrogant. I was very excited to solve this with the limited tools I had, but it just wasn't meant to be, I guess. Have a nice day.