16x16 RGB LED Matrix control with Atmega328

I am trying to build a 16x16 RGB LED matrix.
Or to be exact i already build it and now am trying to find out a good way to control it.
The matrix is divided into four 8x8 matrices to make it a bit easier.
My initial approach was to use 74HC959 shift registers to control the rows and columns.
The LEDs have a common cathode that i connected to NPN transistors (BC457B) which are activated with one of the shift registers to be able to multiplex through the rows.
The anodes are connected to three daisy chained shift registers, so i can light up the colors of each row at once. So each 8x8 segment needs just 4 shift registers.

To control all this i thought i can use a standalone Atmega328, so i wired one up, wrote a sketch for it and tried it out.
Since the whole wiring would take a lot of loose wires and more breadboards then i have i just hooked up one of the 8x8 segments and connected one color. But testing the sketch with a simple 1010101… pattern already showed that i have a lot of flickering.

Now i wonder if my sketch is just poor, the components i used are not fit for it or if it simply can’t be done this way.

Can anyone help me here ? I have attached the sketch i used so far.
(the sketch also seems to have a little bug, because the first two LEDs in each row are lit then i apply the 1010101… pattern, haven’t looked at that yet, but if anyone spots the error just yell)

I already looked at MAX7219 chips, but i don’t know if i could even use them. Either i use one of those for each color, so i need 3 per segment and 12 in total, but brings up the question if this would work at all since the LEDs have a common cathode. Or i could subdivide each segment in 4x4 matrices, so i need 4 chips per segment and 16 total but waste a lot of pins from each chip and brings up the question if i can properly send data to 16 chips.

matrixController74HC959.ino (9.04 KB)

I managed to get rid of the flickering by writing to the registers directly, but now it looks like the data i send to the chip gets corrupted. Only first 3-4 rows display something in a random pattern each time i send a 10101010… pattern.

Wonder if its because i disable interrupts and part of the serial message is lost or if the code now runs too fast for the shift registers to react to the data and clock.

Attached optimized sketch.

matrixController74HC959opt.ino (9.77 KB)

Sending data while the display loop runs and interrupts are turned off was the problem. I added a boolean to trigger if the display is on or off, when display is off the interrupts are not turned off either, so serial communication works.

Turning off the display before sending data and turning it back on afterwards works like a charm now.

The only problem i have now is that i wanted to use pin 9 connected to enable pin of the shift register to create a PWN. Pin 9 supports PWN according to the schematics, display is great when i set it to full brightness, but once i turn the brightness down i get flickering again. Is there anything i can do here ?



Can you post your sketch in code tags please, I can't read your .ino file on my android device (not near pc at the mo).


Multiple MAX7219 would work. You would need to add diodes to isolate the common cathode drivers:

"When the MAX7219 is in shutdown mode, the scan oscillator is halted, all segment current sources are pulled to ground, and all digit drivers are pulled to V+, thereby blanking the display... Data in the digit and control registers remains unaltered. Shutdown can be used to save power or as an alarm to flash the display by successively entering and leaving shutdown mode. For minimum supply current in shutdown mode, logic inputs should be at ground or V+ (CMOS-logic levels). Typically, it takes less than 250μs for the MAX7219/ MAX7221 to leave shutdown mode. The display driver can be programmed while in shutdown mode, and shutdown mode can be overridden by the display-test function."

Each chip drives one color of anodes, no separation problem there. Each chip wants to bring the same common cathode for each digit low tho - so a diode between digit output pins (diode cathode to MAX7219) with the 3 anodes connected to the matrix common cathode. Low voltage loss Schottky diodes would work, such as 0.45V, 1A, 1N5817. http://www.taydaelectronics.com/diodes/schottky/1n5817-diode-schottky-1a-20v.html

Then the multiplexing in your code becomes much easier, just cycling shutdown mode on/off thru the 3 colors.

Thanks, will take a look at using MAX7219 when they arrive. They are still on the way, so i have not had the chance to play around with those.

I can’t find 0.45V of those diodes tho, only finding some with 20V.
Also have a couple IN4007 DO-41 1A 1000V here, but i guess they are a bit overpowered and might drain too much voltage.

I fixed the PWN problem too, I was using pin 9 for it, but that pin has a low frequency, so i switched it to use pin 5 which has a much higher frequency. Now it only flickers a little bit when brightness is very low. Can prevent that in limiting the minimum brightness since in the setup i want to use it such a low brightness is useless anyways.

If anyone is interested in the code i attached it too.
I fixed a couple of minor bugs too and it looks like it works great now.
Controlling the matrix needs a few more commands now, but that is no problem. Opens up possibilities to enable and disable the display without clearing the internal arrays too, so adds a nice feature.

Code is too long to put it in a code tag, post exceeds maximum of 9000 characters if i try :wink:

matrixController74HC959opt.ino (8.62 KB)

Hello, everyone!

I wish to drive a 16x16 LED RGB matrix using ATtiny85. I wish to use Charlieplexing technique. Will it be feasible to use ATtiny or any other models of Arduino?

Also, are there printed 16x16 led modules? Help me with this

Hi Venkatraman

You should begin a new topic for your question. You should not post your question on a topic belonging to someone else.

You may be able to create a single color 16x16 matrix using attiny85 and two of these charlieplexing driver chips.