0
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ To answer your question properly we will need some more information. Can you please post the exact code you are currently running on your Arduino. Can you also post a list of your connections to the matrix, list each connected Arduino pin next to which row or column it is connected to, and note if it's an anode or cathode. \$\endgroup\$ – Jim Feb 15 '12 at 13:53
  • \$\begingroup\$ Remove delay(500). It turns of the row in the end so you don't manage to see the lights turn on before you turn them off again because of this delay. \$\endgroup\$ – chwi Dec 17 '14 at 8:16
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ thanks! well instead of the potentiometers i just set the x and y coordinte programmatically. and that is the only difference between my setup and the one in the tutorial. i have double checked the wiring and also the connections should be fine, since i can get all leds to light up individually with such a continuity test. \$\endgroup\$ – clamp Feb 13 '12 at 10:18
  • \$\begingroup\$ Hummm I see. Make sure you have the same LED matrix, and that you haven't connected it in back to front, it's easy to get them backwards. Do you have a link to the datasheet for your matrix? \$\endgroup\$ – Jim Feb 13 '12 at 10:29
  • \$\begingroup\$ The problem you describe makes it sound like you have your matrix in backwards. I take it your matrix should be lighting the row and column that's not lit? \$\endgroup\$ – Jim Feb 13 '12 at 10:33
  • \$\begingroup\$ that is actually a good question. i dont know this myself. and from the tutorial it is hard to find out if the row and column should be lit or if everything else should be lit. \$\endgroup\$ – clamp Feb 13 '12 at 10:40
  • \$\begingroup\$ The tutorial is supposed to light an individual LED. Instead of moving your connections you could always change the pin assignments in your sketch, but it's a good idea to get the matrix's datasheet so you have a reference for how the LEDs are set out \$\endgroup\$ – Jim Feb 13 '12 at 10:45
0
\$\begingroup\$

Using the code above with the inputs set as :

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

Worked for me after turning the matrix around

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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