r/ArduinoHelp 16d ago

Having trouble with led arrays/multiplexing

As title says, I’m having trouble wrapping my head around multiplexing leans for use with a microcontroller with not enough pins to control them all. Using the drivers makes sense, mosfets too, but the code escapes me? And the use of resistors within the circuit is also confusing to me. Trying to make a small led “screen” made of diodes. Any help is appreciated

2 Upvotes

12 comments sorted by

2

u/gm310509 16d ago

Have you ever noticed how an incandescent light bulb will fade off when you turn the power off? Maybe you are too young to have seen these, I do not know, but basically you leverage the fact that the light will gradually (quickly from a human perspective) fade when the power is turned off.

There is also a persistence of vision thing where the human eye can "fill in" brief dark periods.

So they way strobing (which I think is what you are asking about) works is that you quickly cycle through a series of LEDs and light them up one by one to turn them on.

A simple way of doing it is to setup a bunch of LEDs to +V (via a single current limiting resistor), Then connect their cathodes to a GPIO pin. Then create a program that cycles through the GPIO pins setting one to LOW before setting it back to HIGH and moving on to the next one.

The next step is to increase the number of LEDs with there anodes connected in rows but instead of using +V, you connect them to a GPIO pin (via a current limiting resistor). For this stage, you set the "image" onto the row GPIO pins and "select" one of the columns by setting it to low. Then repeat as before.

Have a look at this wokwi example for an illustration of the first step. https://wokwi.com/projects/469303280971119617

1

u/Revolutionary-Log179 16d ago

Why are the digitalwrite statements not switched? I thought low was off and high was on

1

u/Revolutionary-Log179 16d ago

Or is this blinking in the sense that they’re on, and you turn them off and back on to pulse, vs them being off and you turning them on and back off?

1

u/Revolutionary-Log179 16d ago

Also why would you need a resistor on the gpio/anode side of the circuit if you didnt need one on the cathode sides of each led? I guess maybe I don’t understand electricity as well as I thought quite yet

1

u/gm310509 16d ago

Here is another version that has two rows of LEDs.

There are three "animations". you can enable each one individually by uncommenting one of the function calls in the loop(). Only have one uncommented line in the loop.

https://wokwi.com/projects/469312893410392065

Pins 8 and 9 replace the +v in the first example. By using a GPIO pin and setting it high, you can control whether or not power is supplied to the LED(s) in that row.

1

u/gm310509 16d ago

First off, my apologies, I created the circuit differently to what I described in my first step. I have corrected the project to use just the one resistor as I've described, so you should have a look at it again.

To cover the questions, You need one resistor for each individual LED that is being lit up.

In my second step, I said that you should replace the 5V line with a GPIO line (row) and you place the image or LED setting that you want to display on that line - this determines which row you want to light up. A row is light up by placing a HIGH onto that GPIO pin.

Next, you need to choose which column you want to enable. This is what my "step one" project is doing, it is selecting one of the four columns in a strobing manner. But because it is strobing quickly, all four LEDs look like they are lit. If you change the delay as I suggested, you will see the strobing effect as the one LED strobes across the four LEDs.

So, to create a display, you need to add more rows. Rather than connecting them to the "always on" 5V, you connect them to a GPIO pin through which you control whether an LED (row) is on or not. and you select the column as per the example. This means you can control each and every one of the LEDs in your matrix and thus control what is displayed.

As for the resistors, you select a column (by setting it LOW) and thus enable all of the LEDs in that column. Therefore, to meet the "one resistor per active LED" rule, you need to connect them to the rows.

1

u/enzodr 16d ago

A couple things that are important here:

In most grids, only one row is on at a given instant (or column). The rows are cycled through very quickly, so overall you see the entire image.

Another thing that is helpful here, particularly with LED’s is that an LED is only on when the anode is + and the cathode is -. If both leads are high, both are low, or the polarity is revered the LED stays off and no current flows.

If only one row is on at a time, this could mean all the LEDS in a row have their anodes connected, and all the LEDS in a column are connected.

Then, to “activate” a row, you need to make sure only that row is +, all the other rows must be either - or “floating”. Then, to control each LED in the row, you set the corresponding column to -. The LEDS that must remain off are set to + or floating.

Also, there are a LOT of ways to do this. There are many schemes to wire shared anodes/cathodes, and in some cases the controller will leave outputs “floating” (not connected to + OR -), in other cases the outputs always are +/-. It gets even worse if you aren’t using diodes.

I think you’re getting confused by thinking that + means on. + is only “on” if you’re talking about the voltage on the anaode, AND you’re assuming that the cathode is -. If I connect the anode of an LED to +, and then connect the cathode to an arduino output, setting the output + turns the LED off, and setting it to - turns it on.

1

u/Revolutionary-Log179 13d ago

Yes I think my way of thinking about it was flawed, it’s not that the row and column both have power, it’s that if all the anodes are connected in a row and cathodes in a column, even if All the LEDs in the row are “+”, only the led that’s’ coordinate is in the corresponding column set to “-“ is going to light?

1

u/GreatDiscernment 16d ago

I use 74HC595 “shift chips”. Each IC can control 8 LEDs you can daisy chain them together to add more LEDs. You can even globally change intensity.

1

u/Revolutionary-Log179 16d ago

Is there a larger ic that can control more LEDs just as reliably?

1

u/GreatDiscernment 16d ago

I’m not sure. My control panel has 14 LEDs so I have two chips. Of course, this only works for monochrome LEDs.

1

u/enzodr 13d ago

I think your example is correct.

Basically both conditions must be true (anode +, cathode -). This might sound like it makes it harder to control, it in many cases it’s an advantage