0

I need to control 12 leds through 4 GPIO pins. I did some reading online and saw we can use Charlieplexing method to control leds with fewer gpio pins. But is it possible to make two or more leds to glow at the same time in this method. Those 12 leds are grouped into 4 groups(3 leds in a group) and 1 led would be lit in each group at a time.

Anybody used this method or any other method please provide some guidance on how to go about this implementation. I'll try it. Thanks.

  • 1
    Basically you want one GPIO per group of 3 LEDs, and each GPIO can have three states (hi, lo, and tristate). You want one LED to be on and the others off per state. Logically this can be done, but not with only resistors and LEDs, you will need some transistors too. This is not a software question, so it will be closed on stackoverflow. You will have to ask again at electronics.stackexchange.com – Tom V Jan 06 '23 at 06:45
  • This question is on topic (tagged renesas-rx, a microcontroller) if a solution can be implemented via software, like I say in my reply. – linuxfan says Reinstate Monica Jan 06 '23 at 15:21

2 Answers2

1

You can accomplish this by using external shift registers with latched outputs (e.g. MC74HCT595A) and resistors. The GPIO pins can provide the data, shift clock, and latch clock. Also, the shift registers can be daisy chained so that you can go beyond 12 LEDs if you wish. Be sure that the logic family of the shift registers chosen matches that of your MCU.

Asa
  • 161
  • 1
  • 4
1

You can turn on more than one led, using 4 GPIOs (let's alone the current limiting problems - hardware problem), but not in any combination.

BUT: if you manage to turn on any single led at a time, you can fool the user by turning on multiple leds, one after the other, in a quick loop. At any given moment only a LED is on, but the human eye continues to see it lit for about 1/20th of second.

Have a interrupt run every ms (or so), and a mask of 12 bit indicating which leds have to be on. The interrupt handler continuosly "rotates" the GPIOs in order to touch every combination of rows and columns, and in the same time rotates a bit in an internal register (1000b, 0100b, 0010b 0001b, then reload 1000). When the AND of the internal register and the LEDs mask is not zero, the GPIO configuration must be left active, otherwise set the GPIO to off.

Update: forgot to mention, keeping the LEDS on for so short time, will make them less bright than normal. You can partly correct this by allowing more current (up to a safe limit), and/or by choosing brighter LEDs...

  • Thank you for the inputs. I did a lil bit of reading about the points you mentioned and realized about the effect called persistence of vision (POV). I configured a timer ISR for 1ms and wrote a common function which glows one led in a row at a time and called inside ISR. Those led's must glow based on the buttons presses which updates the state of the button in a structure. I mapped the rows and columns accordingly and it is working. But the brightness is less as you told. I'm trying to reduce the resistor values to make it bright. But i think i might have to get brighter LEDs. – aspiring_programmer Jan 12 '23 at 07:36
  • 1
    @aspiring_programmer, happy it worked. You can check what is the maximum current the leds can accept, and go for it. Take a look at the datasheet. – linuxfan says Reinstate Monica Jan 12 '23 at 08:01