# 74HC595 Multiplexing RGB LEDs

I have been working on trying to figure out how to code some RGB LEDs using Multiplexing using 2 74HC595 chips. I am planning on making a 8x8 matrix (I will probably need 4 chips for this) but currently trying to just figure out a 3x3 matrix so that 0,1,and 2 are for red and 3, 4, and 5 are for the green. Then on the second chip I will put the cathodes.

I am trying to figure out the code for this. Anyone have anything that would help me get started on this.

Suggest you use MAX7221/MAX7219

Can use SPI for efficient data transfer.

This is how I tackled the problem of a 4 by 4 RGB matrix and allowed for dimming and fine colour control:-
http://www.thebox.myzen.co.uk/Hardware/Mini_Monome.html

And how later I extended it to 8 by 8 :-
http://www.thebox.myzen.co.uk/Hardware/Hexome.html
Note how much wiring this took.

larryd:
Suggest you use MAX7221/MAX7219
Can use SPI for efficient data transfer.

But with the MAX7219, efficiency of data transfer is not a concern as that chip is performing the multiplexing for you.

But note - he specified RGB LEDs. You will need four MAX7219s for an 8 by 8 matrix, each one controlling two rows.

“But note - he specified RGB LEDs. ”

What can I say, must be going colour blind

I have been trying some different code to get this figured out. I already had some 74HC595 chips so I am trying to use those if possible. Not really getting anywhere so far. I found a similar code online but they are only using one chip (https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/)

I have made a 3x3 matrix with the columns connected to the + pins of the LEDs and the rows connected to the - pins. The negative pins are hooked into a second chip on pins Qa, Qb, and Qc. The columns are Qa, Qb, and Qc of the first chip.

Here is the code I used. I am getting the 3rd LED in the first column and the 3rd LED in the 3rd column to be mostly be on but the 2nd LED in each of those columns is blinking intermittently. Can't figure out why?

//pin connections- the #define tag will replace all instances of "latchPin" in your code with A1 (and so on)
#define latchPin 41
#define clockPin 40
#define dataPin 38

//looping variables
byte i;
byte j;

//storage variable
byte dataToSend, dataToSend2;

void setup() {
//set pins as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void loop() {

for (i=0;i<8;i++){

for (j=0;j<8;j++){

//bit manipulation (more info at << - Arduino Reference , ~ - Arduino Reference , and & - Arduino Reference)
//dataToSend = (1 << (i+4)) | (15 & ~(1 << j));//preprare byte (series of 8 bits) to send to 74HC595

//for example when i =2, j = 3,
//dataToSend = (1 << 6) | (15 & ~(1 << 3));
//dataToSend = 01000000 | (15 & ~(00001000));
//dataToSend = 01000000 | (15 & 11110111);
//dataToSend = 01000000 | (15 & 11110111);
//dataToSend = 01000000 | 00000111;
//dataToSend = 01000111;
//the first four bits of dataToSend go to the four rows (anodes) of the LED matrix- only one is set high and the rest are set to ground
//the last four bits of dataToSend go to the four columns (cathodes) of the LED matrix- only one is set to ground and the rest are high
//this means that going through i = 0 to 3 and j = 0 to three with light up each led once
dataToSend = 1111111000000001;//preprare byte (series of 8 bits) to send to 74HC595
dataToSend2 = 11111011;//preprare byte (series of 8 bits) to send to 74HC595

// setlatch pin low so the LEDs don't change while sending in bits
digitalWrite(latchPin, LOW);
// shift out the bits of dataToSend to the 74HC595
shiftOut(dataPin, clockPin, LSBFIRST, dataToSend);
//shiftOut(dataPin, clockPin, LSBFIRST, dataToSend2);
//set latch pin high- this sends data to outputs so the LEDs will light up
digitalWrite(latchPin, HIGH);

delay(10);//wait
}
}

}

Never try and learn anything off something with "instructables" in the URL unless you are confident that you can spot mistakes and correct them. These in the main are written by people who have just learned a bit, but not as much as they think.

How to use this forum

Please post a schematic of what you have wired up because code without a schematic is of little use.

I have made a 3x3 matrix with the columns connected to the + pins of the LEDs and the rows connected to the - pins. The negative pins are hooked into a second chip on pins Qa, Qb, and Qc. The columns are Qa, Qb, and Qc of the first chip.

Where are the current limiting resistors in this setup?

grangemd:
I have been trying some different code to get this figured out. I already had some 74HC595 chips so I am trying to use those if possible. Not really getting anywhere so far.

Well, you are making it difficult. I seriously advice you to start by ordering the MAX7219s. The simplest way is to buy - in your case four of - these modules

Actually, I tell you what! Order five of them now. It is not as if they are expensive! From China they will take a couple of weeks (generally 17 days for me).

In the meantime you can fiddle around with crude multiplexing, abusing your 74HC595s, you will learn a bit from "head-banging" along the way but it tends to be in the category of "gives you a warm feeling, but no-one notices". Then when you receive the modules, assemble one and learn to program it which will be dead easy.

Then you can part assemble the other four, leaving off the headers for the red matrices, instead soldering wires to the pin holes to your four RGB assemblies each with two rows of the same 8 cathodes and three anode lines to each row. So your four sets of two rows will go together to make 8 rows.

grangemd:
I found a similar code online but they are only using one chip (https://www.instructables.com/id/Multiplexing-with-Arduino-and-the-74HC595/)

Well, of course it uses only one chip as it is only a 4 by 4 and the 74HC595 has 8 outputs, 4 for rows and 4 for columns.

What is really bad, and indicative of the problem with "instructables", is that it is missing the 1k current limit resistors. As is the case with a number of 7-segment display modules on eBay which use 74HC595s in the same manner with correspondingly poor performance.

If you want something which looks impressive, bright, uniform in brightness and is easy to program, you need to use the MAX7219s.