Arduino Row Column Scanning not working

arduinoledmatrix

I tried to follow this tutorial but the whole matrix is always lit and only one row and one column does not light.

I am pretty sure I did the wiring correct; I only have slightly edited the code since I dont have those potentionmeters to modify the x and y coordinate.

Here is the code I am using:

// 2-dimensional array of row pin numbers:
const int row[8] = {
  2,3,4,5,6,7,8,9 };

// 2-dimensional array of column pin numbers:
const int col[8] = {
  10,11,12,13,16,17,18,19  };

// 2-dimensional array of pixels:
int pixels[8][8];           

// cursor position:
int x = 5;
int y = 5;

void setup() {
  Serial.begin(9600);
  // initialize the I/O pins as outputs:

  // iterate over the pins:
  for (int thisPin = 0; thisPin < 8; thisPin++) {
    // initialize the output pins:
    pinMode(col[thisPin], OUTPUT); 
    pinMode(row[thisPin], OUTPUT);  
    // take the col pins (i.e. the cathodes) high to ensure that
    // the LEDS are off: 
    digitalWrite(col[thisPin], HIGH);    
  }

  // initialize the pixel matrix:
  for (int x = 0; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
      pixels[x][y] = HIGH;
    }
  }
}

void loop() {
  // read input:
  readSensors();

  // draw the screen:
  refreshScreen();

  delay(500);
}

void readSensors() {
  // turn off the last position:
  pixels[x][y] = HIGH;
  // read the sensors for X and Y values:

  x++;
  x%=8;

  if (x==0)
  {
    y ++;
    y%=8;
  }


  pixels[x][y] = LOW;
}

void refreshScreen() {
  // iterate over the rows (anodes):
  for (int thisRow = 0; thisRow < 8; thisRow++) {
    // take the row pin (anode) high:
    digitalWrite(row[thisRow], HIGH);
    // iterate over the cols (cathodes):
    for (int thisCol = 0; thisCol < 8; thisCol++) {
      // get the state of the current pixel;
      int thisPixel = pixels[thisRow][thisCol];
      // when the row is HIGH and the col is LOW,
      // the LED where they meet turns on:
      digitalWrite(col[thisCol], thisPixel);
      // turn the pixel off:
      if (thisPixel == LOW) {
        digitalWrite(col[thisCol], HIGH);
      }
    }
    // take the row pin low to turn off the whole row:
    digitalWrite(row[thisRow], LOW);
  }
}

Here is a photo:
enter image description here

Best Answer

It lights up, so that's a good start!

The link you gave to the tutorial provides an example Arduino sketch, I assume this is the programme you are running to test your circuit?

If you are using the sketch provided you'll need to connect 2 potentiometers to the Arduino's analogue pins (Analog 0 and Analog 1). The picture you have provided does not seem to show these potentiometers. If you do not have them connected then the circuit will not behave as you expected.

I can't really tell if the rest of the circuit is wired up properly as it's quite hard to see from your image. The best way to display your circuit when asking questions like this is to draw up a schematic of your circuit, this makes it much clearer to read, it also gives you an opportunity to go over your circuit and double check all your connections.

If you still can't get it working after that you will need to check that all the connections are good. Often with breadboarding the wires and solder-less connectors don't connect up properly, it can be really annoying! The best way to check for this problem is to do a continuity test on all your connections. You can do this with a multi meter, or if you haven't got one you can rig up a basic tester with an LED and coin cell battery, here's a cool one on Instructables that fits inside a pen!

Good luck!

EDIT:

Now you've posted your code I can see why your not getting any movement/animation. It looks like you are not letting your refreshScreen(); function run for long enough to see the LED. When you run this function it scans through the rows and columns one step at a time, if you don't let it cycle a good few times the LEDs will only be on for a very brief period (too brief to see). The delay(500); is stopping the refreshScreen loop on each iteration and it's messing up your scanning.

I also recommend using millis() instead of delay(), with delay your LEDs will flicker.

PSEUDO CODE:

unsigned long currentMillis = 0;
unsigned long previousMillis = 0;    

void loop()
{
  // read input:
  readSensors();

  // millis() will return the time in milliseconds since the sketch started
  previousMillis = millis();
  currentMillis = previousMillis;

  while(currentMillis - previousMillis < 500)
  {    
    // draw the screen:
    refreshScreen();
    currentMillis = millis();
  }

}

2nd EDIT:

Judging by the problems you have been experiencing, I would suggest that you do not have your matrix connected correctly. Obtain the datasheet for your matrix so you can use it as a reference. Once you are certain of how the LEDs are set out inside your matrix, I would then go back to the tutorial and connect up the matrix from scratch. Please note that LED matrices are not all set out the same and they will differ from one manufacturer to the next.