8*8 Led Matrix Help

hello , i'm new in using arduino .. i was trying to build 8*8 led matrix
i just followed the tutorial on the playground here
http://playground.arduino.cc/Main/DirectDriveLEDMatrix

as you can see in the code bellow it's using #define to give const patterns

and my Q is [ is there's any way to send these patterns using the serial monitor ? ]
sily example
make
int H = Serial.read();
instead of ..
#define H {
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0}
}
and send these patterns by serial monitor or any other software ..

/*
 * Show messages on an 8x8 led matrix,
 * scrolling from right to left.
 *
 * Uses FrequencyTimer2 library to
 * constantly run an interrupt routine
 * at a specified frequency. This
 * refreshes the display without the
 * main loop having to do anything.
 *
 */

#include <FrequencyTimer2.h>

#define SPACE { \
    {0, 0, 0, 0, 0, 0, 0, 0},  \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0}, \
    {0, 0, 0, 0, 0, 0, 0, 0} \
}

#define H { \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}  \
}

#define E  { \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}  \
}

#define L { \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 0, 0}, \
    {0, 1, 1, 1, 1, 1, 1, 0}  \
}

#define O { \
    {0, 0, 0, 1, 1, 0, 0, 0}, \
    {0, 0, 1, 0, 0, 1, 0, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 1, 0, 0, 0, 0, 1, 0}, \
    {0, 0, 1, 0, 0, 1, 0, 0}, \
    {0, 0, 0, 1, 1, 0, 0, 0}  \
}

byte col = 0;
byte leds[8][8];

// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};

// col[xx] of leds = pin yy on led matrix
int cols[8] = {pins[13], pins[3], pins[4], pins[10], pins[06], pins[11], pins[15], pins[16]};

// row[xx] of leds = pin yy on led matrix
int rows[8] = {pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};

const int numPatterns = 6;
byte patterns[numPatterns][8][8] = {
  H,E,L,L,O,SPACE
};

int pattern = 0;

void setup() {
  // sets the pins as output
  for (int i = 1; i <= 16; i++) {
    pinMode(pins[i], OUTPUT);
  }

  // set up cols and rows
  for (int i = 1; i <= 8; i++) {
    digitalWrite(cols[i - 1], LOW);
  }

  for (int i = 1; i <= 8; i++) {
    digitalWrite(rows[i - 1], LOW);
  }

  clearLeds();

  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(2000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);

  setPattern(pattern);
}

void loop() {
    pattern = ++pattern % numPatterns;
    slidePattern(pattern, 60);
}

void clearLeds() {
  // Clear display array
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = 0;
    }
  }
}

void setPattern(int pattern) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      leds[i][j] = patterns[pattern][i][j];
    }
  }
}

void slidePattern(int pattern, int del) {
  for (int l = 0; l < 8; l++) {
    for (int i = 0; i < 7; i++) {
      for (int j = 0; j < 8; j++) {
        leds[j][i] = leds[j][i+1];
      }
    }
    for (int j = 0; j < 8; j++) {
      leds[j][7] = patterns[pattern][j][0 + l];
    }
    delay(del);
  }
}

// Interrupt routine
void display() {
  digitalWrite(cols[col], LOW);  // Turn whole previous column off
  col++;
  if (col == 8) {
    col = 0;
  }
  for (int row = 0; row < 8; row++) {
    if (leds[col][7 - row] == 1) {
      digitalWrite(rows[row], LOW);  // Turn on this led
    }
    else {
      digitalWrite(rows[row], HIGH); // Turn off this led
    }
  }
  digitalWrite(cols[col], HIGH); // Turn whole column on at once (for equal lighting times)
}

Thans alot & sorry for my bad English :slight_smile:

What you really want to do is store the patterns in an array. In the interests of space saving you really want each row of each character to be a single byte and access the individual bits within that byte for the individual LEDs.

byte letters[26][8] = {
  { // A
    0b0000000000,
    0b0011111100,
    0b0100000010,
    0b0100000010,
    0b0111111110,
    0b0100000010,
    0b0100000010,
    0b0000000000,
  }, { // B
    // ....
  }
};

Then you can access the letters as letters_, and each row of the letters as letters*[j] (i = letter number, 0 - 25, j = row number, 0 - 7)._
Once you have a row byte you can access the individual bits with & and <<
_
```*_
*byte letterByte = letters[letterNum][row];

for (int col = 0; col < 8; col++) {
  digitalWrite(cols[col], letterByte & (1<<col)); // Create a bitmask from a 1 shifted into the right column and mask it.
}
_
```*_

hi, i bought starter kit, came with 8x8, cannot find datasheet on it, and pretty sure ive figured out that the pinout is the same as the DirectDriveLEDMatrix's 8x8 pinout, yet it appears the LEDS are reverse polarity :confused:
(assume i'll have to swap all the high/lows in the code, will try anyway)
im about to try it again, but the part i cant figure out, is how the analog pins become consecutively numbered after the digital pins.
can anyone help me with that knowledge ?
thanks in advance

damn frustrating, ive tried 3 different lots of code and none of them come close to working..
now, as a noob, seems im gonna have to start from the very god damn begginning, and reverse engineer the whole damn thing, so i can learn and understand my first project :frowning:
my arduino and parts are going to be worn out before i even get it working :confused:

googs:
but the part i cant figure out, is how the analog pins become consecutively numbered after the digital pins.
can anyone help me with that knowledge ?

What do you mean? They just are.

Look, if you have 20 chickens*, and 14 are white and 6 are brown, and you number the white ones 0 to 13, and the brown ones 14 to 19, how did that happen? You just did it that way.

  • chooks

Well thank you kindly for the responses, am i correct in assuming then, that pin A0 is equivalent to pin 14 ?

Excuse me for trying to take shortcuts and not start from scratch, i do have a fair bit of knowledge in electronics,
but ive stayed away from code all my life, and now am having to start to learn it (not a bad thing!).
I was hoping that i could fire this up, and then start tinkering with the code and teaching myself that way.
ie. I know what the Arduino is doing electronically, but i dont know how the software tells it to do it.
But it appears im going to have to start from the veeeery beginning.
When i get this, hopefully i have the motivation to put my efforts online, so others like me can do what i wanted to do.

googs:
Well thank you kindly for the responses, am i correct in assuming then, that pin A0 is equivalent to pin 14 ?

Yes, on the Uno. A0 is a constant. If you look it up it will be 14.

const static uint8_t A0 = 14;

Cheers Nick, i do apollogize, but i only been at this 2 days, and 'a0 is a constant' went over my head,
'look it up' ? is lot higher over my head (no idea what to look up and where),
and the code you've referenced, i don't know, has that come from where i should've looked it up ?

I'm trying to learn this, as i have a 13yo son there in Melbourne running riot.
Hoping i can get him interested once i get a grasp.

Please don't think I'm not trying, I've spent 90% of the last 2 days trying to 'get started'.

I would appreciate elaboration of your comments, but dont mind if it will take too much to explain, i will learn eventually.
(you werent in the SEC years ago were you? face looks familiar :p)

Thanks again.

googs:
Please don't think I'm not trying, I've spent 90% of the last 2 days trying to 'get started'.

I would appreciate elaboration of your comments, but dont mind if it will take too much to explain, i will learn eventually.
(you werent in the SEC years ago were you? face looks familiar :p)

It's taken me a couple (few?) years to get all these ideas into my head. :slight_smile:

Ah, the SEC, that was before the government sold everything off to make it "more efficient". However no, I didn't work for them.

SEC = State Electricity Commission, for those that are wondering.


and the code you've referenced, i don't know, has that come from where i should've looked it up ?

You weren't really supposed to guess, but there are a lot of files in the Arduino installation. In something like this file:

<install directory>\hardware\arduino\variants\standard\pins_arduino.h

You will find what the pin names "really are".

Oh very cool, had not thought of browsing the installation files, and i bet a lot of people dont.
I am sure i will find a lot more in there too.
Thanks for pointing me in the direction i need to travel.

googs:
hi, i bought starter kit, came with 8x8, cannot find datasheet on it,

Post a picture maybe.

I have some stuff on 8x8 LEDs here:

My 1588BS-H4 8x8 Red LED Matrix, attached to this post.

Notice on my part map there, my LEDs have reversed polarity compared to the other ones i see.

Sorry, will turn camera res. down next time.

I think there was a thread about this a little while back. If you connect one side of the LEDs to 5V rather than Gnd you reverse the sense of the current going into them. In other words, if you normally drive them high and ground the common side, you can drive them low, and connect the common side to 5V.

I can't see resistors in your photo, LEDs need a constant current driver, or series resistors.

That was just a picture of the 8x8 matrix for reference, i do use current limiting resistors, i pulled out the wires/resistors.
I dont understand "reverse the sense of the current", do you mean that im like driving the LEDs like with 0v and -5v ?
Though from my initial understanding we cant get negative voltages out can we ?
And i am confused now!

There are two ways you can make an LED light under program control:

Pin (HIGH) ---> resistor ---> LED  ---> Gnd

Pin (LOW)  <--- resistor <--- LED  <--- +5V

The second way lets you "put the LED in backwards" and still have it light up. Driving the pin low "sinks" current.

Yes, the LED in backwards, this is what i initially stated, and my mudmap shows, and is why i said i think i have to swap all the HIGH/LOWs in the code correct ?
I just find it odd that i have a matrix with leds in backwards!

Yes, try it and see.