8x8 LED RGB Matrix

Hi,

I'm currently trying to program a 8x8 LED RGB Matrix without a backpack on it. The diagram gives an idea of what I'm using. I'm trying to create a library and I'm having a problem with actually displaying the LEDs. I can't really think of more efficient way to turn on the LEDS. I've seen ways to display one color LED Matrixes, that's basically what I'm doing but three times. Is there a more efficient way of displaying the Matrix with what I have?

The following files below are the: library that I made(both header and cpp) with some example code in the Arduino file, and a diagram of the project itself.

Thanks

8x8_RGB_LED_MATRIX.ino (295 Bytes)

8x8RGBMatrix.cpp (4.26 KB)

8x8RGBMatrix.h (1.2 KB)

Sorry, ".zip" files from emails and random websites (such as posts here) are a major security risk and we do not open them. :astonished:


Thank you for correcting that problem. :grinning:

Sorry about that, I had no idea. I will fix that immediately.

That "schematic" tells little or nothing about how you have wired things up. What are all those numbers that the total mess of wires are going into?


You need resistors on the red, green and blue wires, not the common wires, so that you can use higher values for the red, compared to the green and blue, because the red LEDs have a lower forward voltage. Otherwise it will be very difficult to achieve white colour (it will appear somewhat pink, because more current will follow through the red LEDs compared to green & blue).

You also need some driver circuits, such as transistors, on the common wires to prevent the high currents following through those wires from damaging the Arduino pins. They have to source or sink current from 8, perhaps 24 LEDs at once.

I can't open your sketch & library files on my phone, can you post them in code tags please?

(it will appear somewhat pink, because more current will follow through the red LEDs compared to green & blue).

Well what will happen is that if a red LED is on then the other two LEDs can not turn on because there will not be enough voltage to turn them on. In effect the red shorts out the voltage leaving the other two only the voltage across the red.

Grumpy_Mike:
Well what will happen is that if a red LED is on then the other two LEDs can not turn on because there will not be enough voltage to turn them on.

Agreed, Mike, if the r, g, & b are illuminated at the same time. But if they are illuminated in sequence in the multiplexing strategy, then the voltage would not be a problem, but white would still look pink. I have not read the OP's code, so don't know what strategy is being used. Have you figured that out from the OP's code?

Have you figured that out from the OP's code?

No I haven't read it either as I am on my iPad.

8x8_RGB_LED_MATRIX.ino:

#include "8x8RGBMatrix.h"

Matrix8x8 matrix;

void setup() 
{
  matrix.begin();
  matrix.clearBoard();
  
  for (int i = 0; i < 8; i ++)
  {
    for (int j = 0; j < 8; j ++)
    {
      matrix.drawPixel(j,i,0,0,255);
    }
  }
}

void loop() 
{
  matrix.activateBoard();
}

8x8RGBMatrix.h:

#ifndef rgbm
#define rgbm


#include "Arduino.h"
#include <TimedAction.h>


#define V1 12
#define V2 11
#define V3 10
#define V4 9
#define V5 8
#define V6 7
#define V7 6
#define V8 5

#define G1 30
#define G2 31
#define G3 32
#define G4 33
#define G5 34
#define G6 35
#define G7 36
#define G8 37

#define R1 38
#define R2 39
#define R3 40
#define R4 41
#define R5 42
#define R6 43
#define R7 44
#define R8 45

#define B1 46
#define B2 47
#define B3 48
#define B4 49
#define B5 50
#define B6 51
#define B7 52
#define B8 53

class Matrix8x8 {
  public:
    //Constructor
    Matrix8x8();
    
    //Methods
    static void begin();//Sets the ports needed for the matrix
    static void drawPixel(int posx, int posy, int r, int b, int g);//Turns on or off the LED to a certain x or y value
    static void clearBoard();//Turns all of the LEDs on the board off
    static void activateBoard();
    
  private:
    //Variables
    static int Volt[];
    static int Red[];
    static int Green[];
    static int Blue[];
    static int matrixRed[8][8];
    static int matrixBlue[8][8];
    static int matrixGreen[8][8];
    static void LED_Delay(int d);
};

#endif

8x8RGBMatrix.cpp:

#include "8x8RGBMatrix.h"



int Matrix8x8::Volt[] = {V1, V2, V3, V4, V5, V6, V7, V8};
int Matrix8x8::Red[] = {R1, R2, R3, R4, R5, R6, R7, R8};
int Matrix8x8::Green[] = {G1, G2, G3, G4, G5, G6, G7, G8};
int Matrix8x8::Blue[] = {B1, B2, B3, B4, B5, B6, B7, B8};

int Matrix8x8::matrixRed[8][8] = {
                            {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}
};
int Matrix8x8::matrixBlue[8][8] = {
                            {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}
};
int Matrix8x8::matrixGreen[8][8] = {
                            {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}
};

Matrix8x8::Matrix8x8()
{
  
}

void Matrix8x8::begin()//Sets the ports needed for the matrix
{
  //Sets all of the Volt pins
  for (int i = 5; i <= 12; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }

  //Sets all of the RGB ground pins
  for (int i = 30; i <= 53; i ++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH);
  }
}

void Matrix8x8::activateBoard()
{
  for (int i = 0; i < 8; i ++)
  { 
    //Red LEDS
    digitalWrite(Red[i], LOW);
    for (int j = 0; j < 8; j ++)
    {
      analogWrite(Volt[j], matrixRed[i][j]);
      delayMicroseconds(100);
      digitalWrite(Volt[j], LOW);
    }
    digitalWrite(Red[i], HIGH);


    
    //Green LEDS
    digitalWrite(Green[i], LOW);
    for (int j = 0; j < 8; j ++)
    {
      analogWrite(Volt[j], matrixGreen[i][j]);
      delayMicroseconds(100);
      digitalWrite(Volt[j], LOW);
    }
    digitalWrite(Green[i], HIGH);


    
    //Blue LEDS
    digitalWrite(Blue[i], LOW);
    for (int j = 0; j < 8; j ++)
    {
      analogWrite(Volt[j], matrixBlue[i][j]);
      delayMicroseconds(100);
      digitalWrite(Volt[j], LOW);
    }
    digitalWrite(Blue[i], HIGH);
  }
}
  
void Matrix8x8::drawPixel(int posx, int posy, int r, int g, int b)//Turns on or off the LED to a certain x or y value
{
  if (r >= 0)
  {
    if (r > 255)
    {
      matrixRed[posx][posy] = 255;
    }
    else if (r < 0)
    {
      matrixRed[posx][posy] = 0;
    }
    else
    {
      matrixRed[posx][posy] = r;
    }
  }
  
  
  if (g >= 0)
  {
    if (g > 255)
    {
      matrixGreen[posx][posy] = 255;
    }
    else if (g < 0)
    {
      matrixGreen[posx][posy] = 0;
    }
    else
    {
      matrixGreen[posx][posy] = g;
    }
  }
    
  if (b >= 0)
  {
    if (b > 255)
    {
      matrixBlue[posx][posy] = 255;
    }
    else if (b < 0)
    {
      matrixBlue[posx][posy] = 0;
    }
    else
    {
      matrixBlue[posx][posy] = b;
    }
  }
    
}
  
  
void Matrix8x8::clearBoard()//Turns all of the LEDs on the board off
{
  
  for (int i = 0; i < (sizeof(matrixRed)/sizeof(matrixRed[0])); i ++)
  {
    for (int j = 0; j < (sizeof(matrixRed[0])/sizeof(matrixRed[0][0])); j++)
    {
      matrixRed[i][j] = 0;
    }
  }
  
  for (int i = 0; i < (sizeof(matrixBlue)/sizeof(matrixBlue[0])); i ++)
  {
    for (int j = 0; j < (sizeof(matrixBlue[0])/sizeof(matrixBlue[0][0])); j++)
    {
      matrixBlue[i][j] = 0;
    }
  }
  
  for (int i = 0; i < (sizeof(matrixGreen)/sizeof(matrixGreen[0])); i ++)
  {
    for (int j = 0; j < (sizeof(matrixGreen[0])/sizeof(matrixGreen[0][0])); j++)
    {
      matrixGreen[i][j] = 0;
    }
  }
}

void Matrix8x8::LED_Delay(int d)
{
  int y;
  y = d * 10;
  while(y--);
}

So, reading the code, I believe:

  • The matrix is common-anode
  • Red, Green and Blue leds are not lit simultaneously
  • Only one led in the matrix is lit at any instant
  • Overloading Arduino pins with too much current is not an issue
  • For the red leds the instantaneous current will be around (5-1.8 )/100R = 32mA
  • Current limit of the red leds is probably exceeded, shortening their life
  • For the blue/green leds the instantaneous current will be around (5-3.2 )/100R = 18mA
  • Average led current for red leds will be 32mA/(64*3) = 0.16mA
  • Average led current for blue/green leds will be 18mA/(64*3) = 0.09mA
  • The matrix will be quite dim!