Help with trying to control a DIY RGB LED 8x8 matrix

So I'm trying to make an 8x8 RGB led matrix that I control using an Arduino. To control the LEDs I was looking at using shift registers to control more LEDs with PWM than the Arduino would allow. I'm testing it on Tinkercad so I can get the concept down before I build it, but I'm having a bit of trouble with getting the code to work, and the shift registers say they have too much voltage, I may not need to worry about that one as the product sheet says it can support values between 2-6 volts but is anyone willing to take a look at my code and see if they can help me out with it?

Excuse the spaghetti wires, but I'm trying to get it to scroll across the screen one column at a time, using the cathodes to control which row it is on. I have one cord going to the latch switch on each shift register (figured it's okay as it only needs it when it needs to update), and each shift register is dedicated to only one color right now.

Here is a screenshot of my current setup (The code is pretty basic right now as I try to get it to work, right now I'm working towards generating a static image)

// C++ code


int clockPin = 2;
int latchPin = 3;
int dataCathode = 4;
int dataRed = 5;
int dataBlue = 6;
int dataGreen = 7;
byte lights[8][8][3] = {
  {
    { 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 }
  },
  {
    { 1, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 }
  },
  {
    { 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 }
  },
  {
    { 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 }
  },
  {
    { 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 }
  },
  {
    { 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 }
  },
  {
    { 1, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 0, 0, 0 },{ 1, 0, 0 }
  },
  {
    { 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 },{ 1, 0, 0 }
  }
};
void setup()
{
  
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataCathode, OUTPUT);  
  pinMode(dataRed, OUTPUT);  
  pinMode(dataBlue, OUTPUT);  
  pinMode(dataGreen, OUTPUT);  
  Serial.begin(10);

}

void loop()
{
  delay(500);
  delay(10); // Delay a little bit to improve simulation performance

  updateShiftRegister();
  
};
/*
 * updateShiftRegister() - This function sets the latchPin to low, then calls the Arduino function 'shiftOut' to shift out contents of variable 'leds' in the shift register before putting the 'MSBFIRST' high again.
 */
void updateShiftRegister()
{
   for (int i = 0; i < 8; i++){
    for (int j = 0; j < 8; j++){
      pushbit(dataRed, lights[j][i][0]);
      //pushbit(dataBlue, lights[j][i][1]);
      //pushbit(dataGreen, lights[j][i][2]);
    }
    if (i == 0){
      pushbit(dataCathode, 1);
    } else {
      pushbit(dataCathode,0);
    }
    delay(1000);
    digitalWrite(latchPin, LOW);
    digitalWrite(latchPin, HIGH);

  }
  
  delay(5000000);
}
int pushbit(int pin, byte data){
  digitalWrite(clockPin, LOW);
  if (data==0){
    digitalWrite(pin, LOW);
  } else {
    digitalWrite(pin, HIGH);
  }
  digitalWrite(pin, data);
  digitalWrite(clockPin, HIGH);
};

It is posted incorrectly. Please edit that post and put in code tags. Also please read the forum guide, so you can avoid breaking other forum rules.

You current design is wrong in so many ways it would take too long to explain them all. Forget shift registers. Use ws2812 or apa106 LEDs instead of ordinary RGB LEDs.

1 Like

Thank you, I fixed the code styling now

1 Like

I currently own all of the parts shown in the diagram, and as far as I'm aware the LEDs you linked use shift registering as well to get things to display

True. But the chip inside each led contains 3x shift registers, so for 64 LEDs that is 192 shift registers in total. Your design uses 4 shift registers in total. So although both designs use shift registers, they are completely different in every other way.

74hc595 is a general purpose logic chip. It wasn't designed for powering LEDs. With LEDs, the amount of light depends on the amount of current. Logic chips are not designed for more than small amounts of current.

As pointed out, the 74HC595 is quite unsuitable for your application.

To drive an 8 by 8 matrix of those RGB LEDs, you need four MAX7219 matrix driver chips.

These are readily available (with a few weeks wait) from Aliexpress in the form of (partially) assembled modules which use 8 by 8 red miniature LED matrices but the modules in the partially assembled form are so cheap that you might as well use them and ignore the supplied matrices.

I am assuming that you have common cathode LEDs - that is as much as I can determine from your code. To do this you divide up your matrices into pairs of rows where each cathode in a column goes to a corresponding "digit" pin on the MAX7219 and the four anodes of each LED in the first row go to four "segment" pins on the MAX7219 and the four anodes of each LED in the second row go to the other four "segment" pins on the MAX7219.

The four MAX7219s are chained to the three control pins on the Arduino and you just have to figure out the code from there. Only the four resistors in the four MAX7219 modules needed, excellent brightness from the display.

@Paul_B this is the reason I did not also recommend max7219. I interpreted the above to mean @8ByteRemmargorp wants to control the brightness of the r,g,b channels in each led, to mix any colour independantly for each led. Max7219 would not allow that. It would allow overall brightness control of the matrix, but each individual led could only be one of 7 basic colours. Hence my ws2812/apa106 suggestion.

I guess we could be more open with our explanation of why 74hc595 is unsuitable.

In reality, your matrix can be driven by 74hc595. Not exactly using the circuit in your diagram and the code you posted, there are some serious errors there. But once those errors are fixed, it would work. The problem would be that it would only light up disappointingly dimly. This would happen because of the limitations of the 74hc595 chips. I guess it would look ok in a dark room, but it would not look good with the room lights on, and it might not be visible at all in daylight. These limitations include: 1. a maximum of 35mA for any one of the chip's outputs, whether sourcing or sinking current; 2. a maximum of 70mA for each chip in total. These limits can be found in the data sheet.

To overcome the limitations of the 74hc595, extra components would need to be added. How many extra components would depend on what level of brightness you would be happy with. This would make the circuit far more complex and advanced than in your diagram.

Your code would also need to be significantly enhanced to allow both multiplexing and pwm dimming so that colour mixing can be done. So your code would also need to become complex and advanced.

This is why I would recommend swapping to ws2812 or apa106 LEDs. Your circuit would become very simple, and, by using either the NeoPixel or FastLED libraries, your code will be much simpler also.

That is going to be extremely difficult with shift registers! :face_with_raised_eyebrow:

1 Like

Thank you! I didn't realize the limitations that were included with the shift register. I'll take a look at the other Leads and hopefully find a way to use the shift registers and LEDs in the future. Your later comments helped me a lot more.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.