LEDs lit at lower brightness in corners

Hello

I wrote this test code for my led matrix. It works, but there are 2 leds at full brightness and 2 leds at low brightness in the corners. What's the reason?

// Datasheet and ledmatrix I used
//http://www.farnell.com/datasheets/1631380.pdf
//Source: http://www.local-guru.net/blog/2009/04/03/5x7-led-matrix-on-my-arduino


/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
---Diagram of led matrix---
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The numbers are the pins of the led matrix. The "O" are the leds.

  14 13  12  11  10 9 8 
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
  1  2  3  4  5  6  7 

%%%%%%%%%%%%
---Wiring---
%%%%%%%%%%%%
This is the syntax:
==> Arduino Digital OUT | MATRIX Pin in (row/column *number*) <==
2|9 (row 1)
3|14 (row 2)
4|8 (row 3)
5|12 OR 5, they're connected! (row 4)
6|1 (row 5)
7|7 (row 6)
8|2 (row 7)
9|13 (col 1)
10|3 (col 2)
11|4 OR 11, they're connected!(col 3)
12|10 (col 4)
13|6 (col 5)

You have to connect for example pin 2 with pin 9 of the led matrix (watch the diagram), that's the second from right
*/

int c1 = 9; //column 1, pin 9 of arduino
int c2 = 10;
int c3 = 11;
int c4 = 12;
int c5 = 13;

int r1 = 2; //row 1, pin 2 of arduino
int r2 = 3;
int r3 = 4;
int r4 = 5;
int r5 = 6;
int r6 = 7;
int r7 = 8;


//%%%%%%%%%%%%
//---Setup---
//%%%%%%%%%%%%

void setup() {
  //These are the columns
  pinMode( 9, OUTPUT );
  pinMode( 10, OUTPUT );
  pinMode( 11, OUTPUT );
  pinMode( 12, OUTPUT );
  pinMode( 13, OUTPUT );

  //These are the rows
  pinMode( 2, OUTPUT );
  pinMode( 3, OUTPUT );
  pinMode( 4, OUTPUT );
  pinMode( 5, OUTPUT );
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  pinMode( 8, OUTPUT );

}


// the loop routine runs over and over again forever:
void loop() {
  
  digitalWrite(r1,LOW);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  digitalWrite(r5,HIGH);
  digitalWrite(r6,HIGH);
  digitalWrite(r7,HIGH);
  
  digitalWrite(c1, HIGH);
  digitalWrite(c2, LOW);
  digitalWrite(c3, LOW);
  digitalWrite(c4, LOW);
  digitalWrite(c5, LOW);
  
  delay(10);
  
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4, LOW);
  digitalWrite(r5,HIGH);
  digitalWrite(r6,HIGH);
  digitalWrite(r7,HIGH);
  
  digitalWrite(c1, LOW);
  digitalWrite(c2, LOW);
  digitalWrite(c3, HIGH);
  digitalWrite(c4, LOW);
  digitalWrite(c5, LOW);
  
  delay(10);
  
}

Kind regards

You haven't mentioned the resistors.

Rows are cathodes.

The first cycle of your code would appear to activate one corner LED, whilst the second cycle would light the centre LED.

The only thing I can see is that if you have left out the resistors, the sudden excess loading of having two rows instantaneously active as the loop begins the second time may cause the MCU to reset.

Paul__B:
You haven't mentioned the resistors.

Rows are cathodes.

The first cycle of your code would appear to activate one corner LED, whilst the second cycle would light the centre LED.

The only thing I can see is that if you have left out the resistors, the sudden excess loading of having two rows instantaneously active as the loop begins the second time may cause the MCU to reset.

Hello

Thanks for the very fast respons. I use 5 resistors of 100 ohm at the top for the columns.

Where should the resistors be? Does it matter?

I have moved the resistors and tried various options, but it didn't work. Is my Funduino Nano V3.0 causing problems? Is my board too slow?

Kind regards

Hi, can you post a circuit diagram, looks like lots of resistors..
Tom.

TomGeorge:
Hi, can you post a circuit diagram, looks like lots of resistors..
Tom.

The diagram is explained in the comments of the code.

I tried to move the resistors of 100 ohm. The resistors on the columns, rows, both; but that didn't work. For now, I have resitors on both rows and columns. A previous reply mentioned the resistors, so i tried severals ways of placing them.

Hi, try this:

// Datasheet and ledmatrix I used
//http://www.farnell.com/datasheets/1631380.pdf
//Source: http://www.local-guru.net/blog/2009/04/03/5x7-led-matrix-on-my-arduino


/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
---Diagram of led matrix---
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The numbers are the pins of the led matrix. The "O" are the leds.

  14 13  12  11  10 9 8 
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
  1  2  3  4  5  6  7 

%%%%%%%%%%%%
---Wiring---
%%%%%%%%%%%%
This is the syntax:
==> Arduino Digital OUT | MATRIX Pin in (row/column *number*) <==
2|9 (row 1)
3|14 (row 2)
4|8 (row 3)
5|12 OR 5, they're connected! (row 4)
6|1 (row 5)
7|7 (row 6)
8|2 (row 7)
9|13 (col 1)
10|3 (col 2)
11|4 OR 11, they're connected!(col 3)
12|10 (col 4)
13|6 (col 5)

You have to connect for example pin 2 with pin 9 of the led matrix (watch the diagram), that's the second from right
*/

int c1 = 9; //column 1, pin 9 of arduino
int c2 = 10;
int c3 = 11;
int c4 = 12;
int c5 = 13;

int r1 = 2; //row 1, pin 2 of arduino
int r2 = 3;
int r3 = 4;
int r4 = 5;
int r5 = 6;
int r6 = 7;
int r7 = 8;


//%%%%%%%%%%%%
//---Setup---
//%%%%%%%%%%%%

void setup() {
  //These are the columns
  pinMode( 9, OUTPUT );
  pinMode( 10, OUTPUT );
  pinMode( 11, OUTPUT );
  pinMode( 12, OUTPUT );
  pinMode( 13, OUTPUT );

  //These are the rows
  pinMode( 2, OUTPUT );
  pinMode( 3, OUTPUT );
  pinMode( 4, OUTPUT );
  pinMode( 5, OUTPUT );
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  pinMode( 8, OUTPUT );

}


// the loop routine runs over and over again forever:
void loop() {
  
  digitalWrite(r1,LOW);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4,HIGH);
  digitalWrite(r5,HIGH);
  digitalWrite(r6,HIGH);
  digitalWrite(r7,HIGH);
  
  digitalWrite(c1, HIGH);
  digitalWrite(c2, LOW);
  digitalWrite(c3, LOW);
  digitalWrite(c4, LOW);
  digitalWrite(c5, LOW);
  
  delay(10);

  digitalWrite(c1, LOW); // Line Added by PaulRB
  
  digitalWrite(r1,HIGH);
  digitalWrite(r2,HIGH);
  digitalWrite(r3,HIGH);
  digitalWrite(r4, LOW);
  digitalWrite(r5,HIGH);
  digitalWrite(r6,HIGH);
  digitalWrite(r7,HIGH);
  
  digitalWrite(c1, LOW);
  digitalWrite(c2, LOW);
  digitalWrite(c3, HIGH);
  digitalWrite(c4, LOW);
  digitalWrite(c5, LOW);
  
  delay(10);

  digitalWrite(c3, LOW); // Line Added by PaulRB
  
}

PaulRB:
Hi, try this:

// Datasheet and ledmatrix I used

//http://www.farnell.com/datasheets/1631380.pdf
//Source: http://www.local-guru.net/blog/2009/04/03/5x7-led-matrix-on-my-arduino

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
---Diagram of led matrix---
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The numbers are the pins of the led matrix. The "O" are the leds.

14 13  12  11  10 9 8
  O   O   O   O   O
  O   O   O   O   O
  O   O   O   O   O
  O   O   O   O   O
  O   O   O   O   O
 1  2  3  4  5  6  7

%%%%%%%%%%%%
---Wiring---
%%%%%%%%%%%%
This is the syntax:
==> Arduino Digital OUT | MATRIX Pin in (row/column number) <==
2|9 (row 1)
3|14 (row 2)
4|8 (row 3)
5|12 OR 5, they're connected! (row 4)
6|1 (row 5)
7|7 (row 6)
8|2 (row 7)
9|13 (col 1)
10|3 (col 2)
11|4 OR 11, they're connected!(col 3)
12|10 (col 4)
13|6 (col 5)

You have to connect for example pin 2 with pin 9 of the led matrix (watch the diagram), that's the second from right
*/

int c1 = 9; //column 1, pin 9 of arduino
int c2 = 10;
int c3 = 11;
int c4 = 12;
int c5 = 13;

int r1 = 2; //row 1, pin 2 of arduino
int r2 = 3;
int r3 = 4;
int r4 = 5;
int r5 = 6;
int r6 = 7;
int r7 = 8;

//%%%%%%%%%%%%
//---Setup---
//%%%%%%%%%%%%

void setup() {
 //These are the columns
 pinMode( 9, OUTPUT );
 pinMode( 10, OUTPUT );
 pinMode( 11, OUTPUT );
 pinMode( 12, OUTPUT );
 pinMode( 13, OUTPUT );

//These are the rows
 pinMode( 2, OUTPUT );
 pinMode( 3, OUTPUT );
 pinMode( 4, OUTPUT );
 pinMode( 5, OUTPUT );
 pinMode( 6, OUTPUT );
 pinMode( 7, OUTPUT );
 pinMode( 8, OUTPUT );

}

// the loop routine runs over and over again forever:
void loop() {
 
 digitalWrite(r1,LOW);
 digitalWrite(r2,HIGH);
 digitalWrite(r3,HIGH);
 digitalWrite(r4,HIGH);
 digitalWrite(r5,HIGH);
 digitalWrite(r6,HIGH);
 digitalWrite(r7,HIGH);
 
 digitalWrite(c1, HIGH);
 digitalWrite(c2, LOW);
 digitalWrite(c3, LOW);
 digitalWrite(c4, LOW);
 digitalWrite(c5, LOW);
 
 delay(10);

digitalWrite(c1, LOW); // Line Added by PaulRB
 
 digitalWrite(r1,HIGH);
 digitalWrite(r2,HIGH);
 digitalWrite(r3,HIGH);
 digitalWrite(r4, LOW);
 digitalWrite(r5,HIGH);
 digitalWrite(r6,HIGH);
 digitalWrite(r7,HIGH);
 
 digitalWrite(c1, LOW);
 digitalWrite(c2, LOW);
 digitalWrite(c3, HIGH);
 digitalWrite(c4, LOW);
 digitalWrite(c5, LOW);
 
 delay(10);

digitalWrite(c3, LOW); // Line Added by PaulRB
 
}

Thanks. It works. I applied it to my real code, but the middle three columns blink fast. I try to display the character "H".

The datasheet mentions a response time of 250 ns. Could this be the reason causing these problems? http://www.farnell.com/datasheets/1631380.pdf

This is the code with for-loops.

// Datasheet and ledmatrix I used
//http://www.farnell.com/datasheets/1631380.pdf
//Source: http://www.local-guru.net/blog/2009/04/03/5x7-led-matrix-on-my-arduino


/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
---Scematic of led matrix---
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The numbers are the pins of the led matrix. The "O" are the leds.

  14 13  12  11  10 9 8 
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
   O   O   O   O   O
  1  2  3  4  5  6  7 

%%%%%%%%%%%%
---Wiring---
%%%%%%%%%%%%
This is the syntax:
==> Arduino Digital OUT | MATRIX Pin in (row/column *number*) <==
2|9 (row 1)
3|14 (row 2)
4|8 (row 3)
5|12 OR 5, they're connected! (row 4)
6|1 (row 5)
7|7 (row 6)
8|2 (row 7)
9|13 (col 1)
10|3 (col 2)
11|4 OR 11, they're connected!(col 3)
12|10 (col 4)
13|6 (col 5)

You have to connect for example pin 2 with pin 9 of the led matrix (watch the scematic), that's the second from right
*/

int c1 = 9; //column 1, pin 9 of arduino
int c2 = 10;
int c3 = 11;
int c4 = 12;
int c5 = 13;

int r1 = 2; //row 1, pin 2 of arduino
int r2 = 3;
int r3 = 4;
int r4 = 5;
int r5 = 6;
int r6 = 7;
int r7 = 8;

//character H
byte array [7][5] ={
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 1, 1, 1, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1},
  {1, 0, 0, 0, 1}
};

//%%%%%%%%%%%%
//---Setup---
//%%%%%%%%%%%%

void setup() {
  // Initialize serial communication at 9600 bps:
  Serial.begin(9600); 
  //These are the columns
  pinMode( 9, OUTPUT );
  pinMode( 10, OUTPUT );
  pinMode( 11, OUTPUT );
  pinMode( 12, OUTPUT );
  pinMode( 13, OUTPUT );

  //These are the rows
  pinMode( 2, OUTPUT );
  pinMode( 3, OUTPUT );
  pinMode( 4, OUTPUT );
  pinMode( 5, OUTPUT );
  pinMode( 6, OUTPUT );
  pinMode( 7, OUTPUT );
  pinMode( 8, OUTPUT );

  

  for (int r = 0; r < 7; r++)
  {
    Serial.println(" ");
    for (int c = 0; c <5; c++)
    {
      Serial.print(array[r][c]);
      //test purposes      
    }
  }

}


// the loop routine runs over and over again forever:
void loop() {
  
  for (int r = 0; r < 7; r++)
  {
    Serial.println(" ");
    for (int c = 0; c <5; c++)
    {
      Serial.print(array[r][c]);
      if(array[r][c] == 1)
      {
        digitalWrite(r+2,LOW);
        //the first row is on pin 2, so 0+2=2
        digitalWrite(c+9, HIGH);
        //the first column is on pin 9, so 0+9=9
        delay(1);
        digitalWrite(c+9,LOW); //I have tried this, but it doesn't work
        digitalWrite(r+2,HIGH);
      }
      else
      {
        digitalWrite(r+2,HIGH);
        digitalWrite(c+9,LOW);
        delay(1);
      }
      
    }
  }

}

This code works but the leds blink very fast.

Arduinoboy123:
The datasheet mentions a response time of 250 ns. Could this be the reason causing these problems?

No, that's not really relevant.

Arduinoboy123:
This code works but the leds blink very fast.

The problem is that you are only lighting one led at a time. This means each led will only be lit for 1/35 of the time. We call this a "1:35 multiplex ratio".

1:35 is not a good ratio and it will flicker, no matter what kind of Arduino or led matrix you use.

Because your matrix is 5 x 7, you would be better aiming for a multiplex ratio of either 1:5 or 1:7. This means you must light up to 5 or 7 leds at a time, in other words a whole row or whole column. Either way, your Arduino pins will have to "source" or "sink" enough current to light several leds at once. An Arduino pin should be able to source or sink 25mA, so you could light 5 leds at 5mA each for example.

Assuming the "Forward Voltage" of the leds in your matrix is around 2V, your current limiting resistors need to be about 600R for 5mA of current (so that they "drop" the other 3V).

Your code would be something like:

Set all row outputs to low
for each row:
set row to high
for each column:
set column to high or low depending on the required pattern for this row
next column
delay
for each column:
set column to high
next column
set row to low
next row

Hope that makes sense!

Paul

Because your matrix is 5 x 7, you would be better aiming for a multiplex ratio of either 1:5 or 1:7. This means you must light up to 5 or 7 leds at a time, in other words a whole row or whole column. Either way, your Arduino pins will have to "source" or "sink" enough current to light several leds at once. An Arduino pin should be able to source or sink 25mA, so you could light 5 leds at 5mA each for example.

Assuming the "Forward Voltage" of the leds in your matrix is around 2V, your current limiting resistors need to be about 600R for 5mA of current (so that they "drop" the other 3V).

Your code would be something like:

Set all row outputs to low
for each row:
set row to high
for each column:
set column to high or low depending on the required pattern for this row
next column
delay
for each column:
set column to high
next column
set row to low
next row

Hope that makes sense!

Paul

OK, I will try this.

Do not put print statements in your refresh loops they slow things down a lot.
Also digitalWrite is quite slow for this sort of thing you will need to use direct port bit manipulation.

Grumpy_Mike:
Do not put print statements in your refresh loops they slow things down a lot.

Agreed Mike.

Grumpy_Mike:
Also digitalWrite is quite slow for this sort of thing you will need to use direct port bit manipulation.

Mike, I would not agree with that statement. I think digitalWrite will be plenty fast enough for this application. I used digialWrite to update a 128x64 graphic LCD displaying Conway's game of Life at 10 frames per second! OK, I put some optimisations in to reduce the number of calls to digitalWrite, but it must still have been doing at least 10,000 calls per second.

The first post in this link shows the difference between direct port manipulation and digitalWrite is around 20 times, but digitalWrite can be repeated 200,000 times per second!

http://forum.arduino.cc/index.php/topic,4324.0.html

Paul

I think digitalWrite will be plenty fast enough for this application.

Could be, I wouldn't disagree.

But given the title of the topic and that first piece of code there was a bunch of digital writes and very little delay then the LEDs that were turned on first were being on for longer than those turned on last. It makes for a more evenly lit display if you can minimise the transition time.

Is that single color or bi-color matrix?

1ChicagoDave:
Is that single color or bi-color matrix?

Single color: red