LED MATRIX 8X8

Hi i just bought a LED matrix 8x8 and set it up like this

oomlout.com/8X8M/8X8M-Guide.pdf

my aim is to get a smiley face displayed as a still image on the LED matrix however i am having trouble doing the code. my code so far is this.

int r1 = 2;
int r2 = 3;
int r3 = 4;
int r4 = 5;
int r5 = 6;
int r6 = 7;
int r7 = 8;
int r8 = 9;
int c1 = 10;
int c2 = 11;
int c3 = 12;
int c4 = 13;
int c5 = 14;
int c6 = 15;
int c7 = 16;
int c8 = 17;

int xArray[8][8] = {
{
0,0,0,0,0,0,0,0 }
,{
0,0,0,0,0,0,0,0 }
,{
0,0,1,0,0,1,0,0 }
,{
0,0,0,0,0,0,0,0 }
,{
0,1,0,0,0,0,1,0 }
,{
0,0,1,1,1,1,0,0 }
,{
0,0,0,0,0,0,0,0 }
,{
0,0,0,0,0,0,0,0 }
};

void setup()
{
pinMode(r1,OUTPUT);
pinMode(r2,OUTPUT);
pinMode(r3,OUTPUT);
pinMode(r4,OUTPUT);
pinMode(r5,OUTPUT);
pinMode(r6,OUTPUT);
pinMode(r7,OUTPUT);
pinMode(r8,OUTPUT);
pinMode(c1,OUTPUT);
pinMode(c2,OUTPUT);
pinMode(c3,OUTPUT);
pinMode(c4,OUTPUT);
pinMode(c5,OUTPUT);
pinMode(c6,OUTPUT);
pinMode(c7,OUTPUT);
pinMode(c8,OUTPUT);

}

void loop()
{
for (int i=0;i<10;i++) {
for (int j = 0; j<18;j++)
{
allOff();
if (xArray*[j] == 1) {*

  • digitalWrite(i+2,HIGH);*
  • digitalWrite(j+10,LOW);*
  • } *
  • }*
  • }*
    }
    void allOff()
    {
  • digitalWrite(r1,LOW);*
  • digitalWrite(r2,LOW);*
  • digitalWrite(r3,LOW);*
  • digitalWrite(r4,LOW);*
  • digitalWrite(r5,LOW);*
  • digitalWrite(r6,LOW);*
  • digitalWrite(r7,LOW);*
  • digitalWrite(r8,LOW);*
  • digitalWrite(c1,HIGH);*
  • digitalWrite(c2,HIGH);*
  • digitalWrite(c3,HIGH);*
  • digitalWrite(c4,HIGH);*
  • digitalWrite(c5,HIGH);*
  • digitalWrite(c6,HIGH);*
  • digitalWrite(c7,HIGH);*
  • digitalWrite(c8,HIGH);*
    }
    Im not very good programmer so help would be useful.
    Thanks!

It may be easier if you use an array of pins so your row and column variables in the for loops can start from 0

Here are the arrays and setup code, the loop code is left as an exercise.

const int rowPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
const int columnPins[]   = { 10,11,12,15,16,17,18,19}; 


void setup() {
  for (int i = 0; i < 8; i++)
  {
    pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
    pinMode(columnPins[i], OUTPUT);  
  }
}

The following should turn on an LED at the given row and column
digitalWrite(rowPin(row, HIGH));
digitalWrite(columnPin(column, LOW));

First off modify that posting to use the # icon in the post box.

Next you are using current limiting resistors on the matrix or some form of current drivers?

Last you are not multiplexing the display correctly which is by columns and rows. You are just lighting one individual LED at a time, also you are not giving that LED any time to shine before you change it to something else.

am having trouble doing the code.

What's wrong? How are we supposed to tell just from a listing?

The 10x18 loop limits probably don't help, given that xArray is only defined to be 8x8.

hi thanks for the help guys. i'm not very good at programming myself so i'm just having trouble finding a solution or how to get it to work. to the first post, how am i able to control the individual leds? does the digital write part go into the void loop?

also to the 2nd post, what do you mean by multiplexing it?

sorry if i have been unclear about the problem.

This is what I've got so far but it comes up with an error saying the rowPin is not declared in this scope. Im not too sure whats wrong here! Thanks

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

void setup() {
for (int i = 0; i < 8; i++)
{
pinMode(rowPins*, OUTPUT); // make all the LED pins outputs*
_ pinMode(columnPins*, OUTPUT); _
_
}_
_
}_
void loop()
_
{_
_
for (int i=0;i<18;i++)_
_
{*_
digitalWrite(rowPin(2, HIGH));
digitalWrite(columnPin(10, LOW));

}}

Look I have asked you once already.
When posting code click on the # icon in the reply box and paste the code between what pops up.
Please modify your previous posts.

error saying the rowPin is not declared

const int rowPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};

digitalWrite(rowPin(2, HIGH));

see what you have done?

int r1 = 2;
int r2 = 3;
int r3 = 4;
int r4 = 5;
int r5 = 6;
int r6 = 7;
int r7 = 8;
int r8 = 9;
int c1 = 10;
int c2 = 11;
int c3 = 12;
int c4 = 13;
int c5 = 14;
int c6 = 15;
int c7 = 16;
int c8 = 17;


int xArray[8][8]  = {
 {
   0,0,0,0,0,0,0,0  }
 ,{
   0,0,0,0,0,0,0,0  }
 ,{
   0,0,1,0,0,1,0,0  }
 ,{
   0,0,0,0,0,0,0,0  }
 ,{
   0,1,0,0,0,0,1,0  }
 ,{
   0,0,1,1,1,1,0,0  }
 ,{
   0,0,0,0,0,0,0,0  }
 ,{
   0,0,0,0,0,0,0,0  }  
};




void setup()
{
 pinMode(r1,OUTPUT);
 pinMode(r2,OUTPUT);
 pinMode(r3,OUTPUT);
 pinMode(r4,OUTPUT);
 pinMode(r5,OUTPUT);
 pinMode(r6,OUTPUT);
 pinMode(r7,OUTPUT);
 pinMode(r8,OUTPUT);
 pinMode(c1,OUTPUT);
 pinMode(c2,OUTPUT);
 pinMode(c3,OUTPUT);
 pinMode(c4,OUTPUT);
 pinMode(c5,OUTPUT);
 pinMode(c6,OUTPUT);
 pinMode(c7,OUTPUT);
 pinMode(c8,OUTPUT);




}


void loop()
{
 for (int i=0;i<10;i++) {
   for (int j = 0; j<18;j++)
   {
     allOff();
     if (xArray[i][j] == 1) {
       digitalWrite(i+2,HIGH);
       digitalWrite(j+10,LOW);
     }      
   }
 }
}


void allOff()
{

 digitalWrite(r1,LOW);
 digitalWrite(r2,LOW);
 digitalWrite(r3,LOW);
 digitalWrite(r4,LOW);
 digitalWrite(r5,LOW);
 digitalWrite(r6,LOW);
 digitalWrite(r7,LOW);
 digitalWrite(r8,LOW);
 digitalWrite(c1,HIGH);
 digitalWrite(c2,HIGH);
 digitalWrite(c3,HIGH);
 digitalWrite(c4,HIGH);
 digitalWrite(c5,HIGH);
 digitalWrite(c6,HIGH);
 digitalWrite(c7,HIGH);
 digitalWrite(c8,HIGH);

}

That was the code in the first post

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


void setup() {
 for (int i = 0; i < 8; i++)
 {
   pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
   pinMode(columnPins[i], OUTPUT);  
 }
}



void loop()
{
 for (int i=0;i<18;i++)

{

digitalWrite(rowPin(2, HIGH));
digitalWrite(columnPin(10, LOW));

}}

I apologise for not posting correctly

for (int i=0;i<18;i++)
digitalWrite(rowPin(2, HIGH));

And you've repeated the same mistakes.

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



void setup() {
 for (int i = 0; i < 8; i++)
 {
   pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
   pinMode(columnPins[i], OUTPUT);  
 }
}



void loop()
{
 for (int i=0;i<20;i++)

{

digitalWrite(8, HIGH);
digitalWrite(15, LOW);


}}

This is the code I have done now. However some of the columns are not lighting up correctly. When i column 7 there are two columns are lighting up. Im not sure where the problem is because the wiring is fine. IT might be the for the for loop I have. also i cant get the rows to light up too or individual leds

Without seeing your wiring, it is all but impossible to comment.
Please delete your duplicate post.

im not trying to be rude or annoying im just asking for assitance so please dont be rude. i relise im not the best at programming but i am trying.

so you dont think it is to do with the code because i wired it up like this:

http://oomlout.com/8X8M/8X8M-Guide.pdf

also is my digitalWrite code correct? the code hasnt changed from my previous post

thanks

It isn't being rude to ask a user to "please" delete a post that duplicates another post.
It just wastes people's time to read and answer one post, when the question may already have been answered in another thread.

I'd double and triple check your wiring, maybe even take it one column or row at a time.

In the last code you posted then
digitalWrite(8, HIGH);
digitalWrite(15, LOW);

gets continuously executed. This will light up only one LED. Is that what you are seeing?
You normally have to change what LEDs you light up.
As I said before you are not letting the LED have any time to shine. Do a delay(20); in the loop.

narh when i done that (colums numbered 1-8) when i do digitalWrite8 columns 6 and 8 come on. and they stay on regardless of the delay too. i cant get an individual led to light up when i do it. the whole column lights up. and even if i try to light up a whole row the rows dont even turn on!

when i do digitalWrite8 columns 6 and 8 come on

Then your wiring is defiantly wrong.

you can try this test code to see if it is wired up correctly.
The code lights sequentel leds untill all the leds are lit, then it clears and starts over again.

use the arrays and setup code you already have but replace loop with this:

int pixel       = 0;        // 0 to 63 leds in the matrix
int columnLevel = 0;        // pixel value converted into led column
int rowLevel    = 0;        // pixel value converted into led row

void loop() {
//  int sensorValue = analogRead(analogInPin);            // read the analog in value      
//    pixel =   map(sensorValue, 0, 1023, 0, 63);    // map  sensor value to pixel (LED)    

  
  pixel = pixel + 1;
  if(pixel > 63)
     pixel = 0;
  
  columnLevel = pixel / 8;                           // map to the number of columns
  rowLevel = pixel % 8;                              // get the fractional value
  for (int column = 0; column < 8; column++)
  {
    digitalWrite(columnPins[column], LOW);         // connect this column to Ground
    for(int row = 0; row < 8; row++)
    {
      if (columnLevel > column)
      {
        digitalWrite(rowPins[row], HIGH);          // connect all leds in the row to +5 volts
      } 
      else if (columnLevel == column && rowLevel >= row)
      {
          digitalWrite(rowPins[row], HIGH);   
      }
      else
      {
        digitalWrite(columnPins[column], LOW);      // turn off all leds in this row
      }
      delayMicroseconds(300);                      // a delay for each led gives frame time of 20ms for 64 LEDs
      digitalWrite(rowPins[row], LOW);             // turn off led
    }
                                
    digitalWrite(columnPins[column], HIGH);         // disconnect this column from Ground  
  }
}

thanks for that it was wired incorrectly. I am still not able to however light up single leds. this is the problem facing me. ive tryed:

{


{

digitalWrite(10, LOW);
digitalWrite(2, HIGH);

delay(1000);

}}

this was in the void loop part. however this only lights up the column. i dont know how to control single leds in the matrix¬!

Try the code in post #16, it uses multiplexing to control the number of leds that are lit. In that example, the leds are lit in sequence, but it should help in understanding the principle of lighting an LED by selecting the intersection of the row and column.