Best way to multiplex RGB leds.

Hello!!! I´m trying to build a 5x8 RGB led matrix. I intended to drive 5 rgb leds rows with a ATmega328 and two 4051 multiplexers. And multiplex the 8 columns with a 4051 connected to an Attiny 85. Wich would be an i2c slave of the mega.
I tested the 4051 analog multiplexing and I can´t make it work as I intend. I attach the wiring of only one led and the code I´m testing.

Searching a bit I found that the TLC5940 would be a better choice. But it´s not easy to find in my country. I´d have to have it sent from China.

Thank you in advance.

master_writer328ColoresPureba.ino (604 Bytes)

You have not posted a real schematic. Schematics are the written language of electronics. The reason that is so, is because they are designed to clearly convey the functional aspects of the circuit, as opposed to the physical layout which has not so much to do with how the circuit actually works. The layout of a schematic usually follows certain patterns, which can be quickly recognized and compared with other circuits. This aids immensely in the understanding of the circuit. The labeling of components and conductors may include labels which also exist in a physical diagram, but also explicitly and implicitly includes additional information which helps to explain the functionality of the circuit, and is not visible in the physical layout. Lack of a proper schematic creates work for anyone that works on a circuit. For this reason, anyone that designs a circuit should make one. If you expect other people to work with your circuit, the lack of a schematic usually places a huge burden on them, as they have to do the work of creating their own schematic, either in their mind, or on paper. This discourages people from helping you.

Thank you for your response! As I´m external to this field I don´t what´s really needed to understand the circuit.
Let me know if this schematic is what it´s needed to understand it little bit better.

OP’s image
97731af1c240474c37084bda3a806f786a0636a5.png

See this page for instructions on how to post an image.

The LED seems to be wired wrong. The common cathode should go to ground, not 5V.
Do you have current limit resistors for the LED(s).

Multiplexers like the 4051 should not be used to drive LEDs they are totally unsuitable for this sort of thing, despite being used in a stupid tutorial on this site.

You´re right groundFungus! It´s wired backwards and it doesn´t have resistors. However, I tried again and it´s not working how I intend. But it´s doing better nonetheless.
Thank you very much!

1080glitch:
You´re right groundFungus! It´s wired backwards and it doesn´t have resistors. However, I tried again and it´s not working how I intend. But it´s doing better nonetheless.
Thank you very much!

Interesting. In what way is it working, but not how you intend? Better in what way? :slight_smile:

Grumpy_Mike:
Multiplexers like the 4051 should not be used to drive LEDs they are totally unsuitable for this sort of thing, despite being used in a stupid tutorial on this site.

If I really had to do this, I would use a 74HC139.

Grumpy_Mike:
Multiplexers like the 4051 should not be used to drive LEDs they are totally unsuitable for this sort of thing, despite being used in a stupid tutorial on this site.

So using a TLC5940 is the way to go. Does anybody knows another chip for multiplexing analog values?

You may have a misunderstanding of PWM using the analogWrite function. The analogWrite function does not output an analog voltage. It is a digital pulse train with the duty cycle (% on to % off) encoded in the pulse width.

So you don't need a "chip for multiplexing analog values", you could use a chip for multiplexing LEDs. Like the TLC5940, Max7219 or TPIC6B595 to name a few.

1080glitch:
So using a TLC5940 is the way to go. Does anybody knows another chip for multiplexing analog values?

Why do you want to multiplex analog values? Your signals are digital. If you use a 74HC139 you will get 2 selectors in one package and so you can drive 2 RGBs, each from its own PWM pin.

My favorite chip for producing a PWM signal for RGB LEDs is a PCA9685. It is a set and forget device unlike the others than need constant feeding. You get 16 PWM outputs at 12 bits for each chip, and many chips can be on the I2C bus at the same time ( up to 64 ).