Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Duplicate of this question

I'm trying to drive an 8x8 LED matrix with an arduino nano, but I can't get the LEDs to display what I tell it to.

I'm using this LED Matrix

Here's my code:

int row1 = 2;
int row2 = 3;
int row3 = 4;
int row4 = 5;
int row5 = 6;
int row6 = 7;
int row7 = 8;
int row8 = 9;

int col1 = 10;
int col2 = 11;
int col3 = 12;
int col4 = 18;
int col5 = 14;
int col6 = 15;
int col7 = 16;
int col8 = 17;

void setup() {
  int i;
  for(i = 2; i <= 18; i++) {
    pinMode(i,OUTPUT);
  }
  for(i = 2; i <= 9; i++) {
    digitalWrite(i, HIGH);
  }
}

void loop() {

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

  updateScreen(display);
}

void updateScreen(int screen[8][8]) {

  Serial.begin(9600);
  int i;
  for (i = row1; i <= row8; i++) {
    Serial.println(i-1); 
    digitalWrite(i, LOW);
      digitalWrite(col8, screen[i-2][0]);
      Serial.print(screen[i-2][0]); Serial.print("|"); 
      digitalWrite(col7, screen[i-2][1]);
      Serial.print(screen[i-2][1]); Serial.print("|"); 
      digitalWrite(col6, screen[i-2][2]);
      Serial.print(screen[i-2][2]); Serial.print("|"); 
      digitalWrite(col5, screen[i-2][3]);
      Serial.print(screen[i-2][3]); Serial.print("|"); 
      digitalWrite(col4, screen[i-2][4]);
      Serial.print(screen[i-2][4]); Serial.print("|"); 
      digitalWrite(col3, screen[i-2][5]);
      Serial.print(screen[i-2][5]); Serial.print("|"); 
      digitalWrite(col2, screen[i-2][6]);
      Serial.print(screen[i-2][6]); Serial.print("|"); 
      digitalWrite(col1, screen[i-2][7]);
      Serial.println(screen[i-2][7]);
      delay(1);
      blank();
    digitalWrite(i, HIGH);
  }

}

void blank() {
  digitalWrite(col1, LOW);
  digitalWrite(col2, LOW);
  digitalWrite(col3, LOW);
  digitalWrite(col4, LOW);
  digitalWrite(col5, LOW);
  digitalWrite(col6, LOW);
  digitalWrite(col7, LOW);
  digitalWrite(col8, LOW);
}

And here is the output:

1 
1|0|0|0|0|0|0|0 
2 
0|1|0|0|0|0|0|0 
3 
0|0|1|0|0|0|0|0 
4 
0|0|0|1|0|0|0|0 
5 
0|0|0|0|1|0|0¾j 
6 
0|0|0|0|0|1|0|0 
7 
0|0|0|0|0|0|1|0 
8 
0|0|0|0|0|0|0|1

So I can tell that the error (probably) isn't my wiring, because those array values are clearly wrong, I have no idea where the ¾j is coming from.

share|improve this question
    
What do they display/what do you expect them to display? –  sachleen Mar 8 '14 at 4:22
    
Did you try a longer delay? –  AsheeshR Mar 8 '14 at 4:29
    
With that code as it is works fine, but if I try to display an alternating pattern of LEDs (i.e. like a chess board) like this: {1,0.1,0,1,0,1,0}, {0.1,0,1,0,1,0,1}, {1,0.1,0,1,0,1,0}, {0.1,0,1,0,1,0,1}, {1,0.1,0,1,0,1,0}, {0.1,0,1,0,1,0,1}, {1,0.1,0,1,0,1,0}, {0.1,0,1,0,1,0,1} –  user168057 Mar 8 '14 at 4:34
    
@user168057 If you mean an alternating on-off pattern, then its displaying fine for me. Do you mean on the actual LEDs or only serial monitor? –  AsheeshR Mar 8 '14 at 4:38
3  
Nevermind found the issue, I used a few . instead of , in my array declaration. Thanks anyways :) –  user168057 Mar 8 '14 at 4:39

2 Answers 2

up vote 1 down vote accepted

Because of my psychic abilities*, I am able to tell that you actually used . in a few places you should have used , in your array initialization. Replacing the ,s with .s should fix the problem.

*Okay, okay, not really.

share|improve this answer

Your initial problem can be sorted out by using a longer delay.

void updateScreen(int screen[8][8]) {

  Serial.begin(9600);
  int i;
  ........
      delay(100); //Longer time duration
      blank();
    digitalWrite(i, HIGH);
  }

}

As far as the chess pattern is concerned, it displays correctly for me.

void loop() {

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

  updateScreen(display);
}

Check your array declarations for errors.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.