Electrical – How to use Charlieplexing with common anode RGB LEDs

charlieplexingled

I've an ESP32-based dev board (LoLin32) which has 26 digital I/O pins. I want to connect 25 common anode RGB LEDs to it. Connecting them in the 'normal' way would require 75 I/O pins, which I don't have ofcourse. I've heard that you could use Charlieplexing to connect n*(n-1) LEDs to n pins, but I don't quite understand how I could use Charlieplexing with common anode RGB LEDs.

Edit: it doesn't neccessarily have to be Charlieplexing, other solutions are welcome too. I know about WS2812-ish things, but that's something I wanted to avoid.

Best Answer

You can't use Charlieplexing with common anode, nor common cathode. You need to have the anodes/cathodes across every pin.

A relatively simple solution in your case would be to acquire a couple of shift registers, the 74HC595 gives you 8 extra outputs at the cost of three pins on the ESP32. You can daisy chain the 74HC595 and have 16 extra outputs and still only paying a total of three pins on the ESP32.

In order to cover 75 LED's, you'd use 75/8 => 10x 74HC595.

If at any one time you will have just one LED activated (which Charlieplexing would force you to do), then you can get away with only one resistor, which would be between the common anode and your voltage supply.

If at any one time you will have several LED's activated (which you can do with 74HC595), then you should place a resistor for every LED. In other words, between every pin on your 74HC595's and their LED's. If you do what I first said, with only one resistor, then the LED's will get darker the more LED's you activate.But with a resistor for every LED, then the brightness will stay the same regardless if you have 1 or 30 LED's activated.


Update

After seeing Transistor's answer I realized that you obviously have 25 RGB LEDs = 4 pins each. It's not some large 5x5 matrix with only one common anode, which I first thought.

This means that you can actually solve this in a much better way than I first proposed.

Here's what I would do if I were you:

  • Connect every red pin of the 25 LEDs together
  • Connect every green pin of the 25 LEDs together
  • Connect every blue pin of the 25 LEDs together
  • Use 4x 74HC595 instead of 10, you will get 32 pins
  • Connect a 220 Ω resistor on 25 of the 32 outputs of the 4x 74HC595
  • Connect the anodes of the 25 LEDs to those resistors
  • Connect the red & green & blue to some remaining pins on the last 74HC595

This will again only take 3 pins on your ESP32, but only 4x 74HC595 instead of 10. And 25 resistors instead of 1 resistor, or 75, depending on how you'd do it.

A very important thing to note, as Transistor has mentioned, is that different LED's have different forward voltage. This means that 220 Ω will make the red LED too bright and the other two will be weaker because they have higher forward voltage drop. This in turn mean that whatever modulating scheme you will be implementing should give less time to red. And you should not use red or green or blue at the same time. You can only activate one LED (by powering its anode through its resistor) at a time.