8
\$\begingroup\$

I have a microcontroller with one available digital pin.

How can I control 25 LEDs?

\$\endgroup\$
  • 2
    \$\begingroup\$ Are the leds separately adressable or do you want to turn them all on/off at the same time? \$\endgroup\$ – Vincent Van Den Berghe Oct 27 '10 at 7:35
  • \$\begingroup\$ The leds are meant to be separately accessible. The microcontroller is not meant to be powering them, simply determining their state. Also, by "digital port" i mean pin. \$\endgroup\$ – archgoon Oct 27 '10 at 8:27
11
\$\begingroup\$

I2C IO Expander: - Some protocol overhead, but it should be expandable to a very large (thousands) number of LEDs.

Simple shift register - Dead Simple interface, the LEDs may flicker when updating if the shift register clock is not fairly fast. Using a double buffered shift register will fix this.

\$\endgroup\$
  • \$\begingroup\$ Thanks, this is exactly what I was looking for, but didn't know what they were called. \$\endgroup\$ – archgoon Oct 27 '10 at 8:25
  • 2
    \$\begingroup\$ That'll require at least one pin, tho. Don't shift registers require at least two pins, for clock and data? \$\endgroup\$ – blalor Oct 27 '10 at 17:11
  • \$\begingroup\$ @blalor - Yes, but these two pins are designed to be shared among multiple I2C devices. \$\endgroup\$ – Kevin Vermeer Oct 27 '10 at 19:49
  • \$\begingroup\$ I2C is also two lines. \$\endgroup\$ – XTL Oct 29 '10 at 21:39
  • 2
    \$\begingroup\$ Dallas 1-wire only needs one pin, expands to N devices. \$\endgroup\$ – Tim Williscroft Nov 19 '10 at 0:55
16
\$\begingroup\$

Shift Register and I2C is good, but only if there are at least 2 pins free. I suggest Dallas 1-wire port extender DS2408 will be an optimal solution. Code for Dallas 1-wire device access is not so complicated and there are plenty of examles on the web.

You may use several DS2408 connected to one pin or implement more logic after single DS2408 whichever you'd like.

\$\endgroup\$
  • 2
    \$\begingroup\$ I2C can be used if there are zero pins free, assuming that your I2C bus is being used as such and there are no address conflicts. \$\endgroup\$ – Kevin Vermeer Oct 27 '10 at 19:48
5
\$\begingroup\$

With only 1 IO pin, you can use a 1-wire expander/shift register or add another device to your I2C bus, as already pointed out. The only thing that hasn't been mentioned yet is the possibility of adding another slave to your SPI port.

SPI is called a 4-wire protocol - You have two data lines, a clock line, and a select line (as well as a common ground, but that doesn't usually count). However, the first three are shared among all the devices on the bus, so each device after the first one takes only one more trace/wire. SPI also increases your bus to full duplex, but that won't matter for this application.

\$\endgroup\$
1
\$\begingroup\$

I'd just chain a few shift registers together. (This reduces the frequency with which you can toggle the LEDs, of course..)

\$\endgroup\$
1
\$\begingroup\$

If you really have only 1 pin available the Dallas 1-wire bus looks like the most obvious thing. However, since this is output-only, there are cheaper solutions. A serial PWM bus which carries both data and clock is easy to set up; see for instance Roman Black's page as also mentioned by davidcary. You only need serial-in parallel-out shift registers like the 74VHC164, which you can cascade for as many outputs as you want (one '164 has 8 outputs).
In this solution LEDs are driven statically.

If you do have other I/O you can share, like SPI of I2C, you may go for more luxurious solutions, like Maxim's MAX6950. The MAX6950 has blinking and brightness control, and slew-rate limiting, to name a few features. LEDs are multiplexed, which means you only need one 16-pin driver.

\$\endgroup\$
0
\$\begingroup\$

The answer is probably "a series of shift registers," but can you be more specific in your question? What microcontroller? What do you mean by "digital port"? A single pin?

\$\endgroup\$
  • \$\begingroup\$ Thanks, I've made the clarification, and the shift registers are what I'm looking for. Thank you. \$\endgroup\$ – archgoon Oct 27 '10 at 8:29
0
\$\begingroup\$

25 LED's depending on size can draw a lot of power for a single digital IO pin on a micro-controller. Rather than driving them directly, you should probably use a simple FET switch (so the IO is tied to gate) to control the power to the LED chain.

Depending on your application, there are other more robust ways to accomplish this. But throwing in a fet will probably get you working the fastest.

For example, if you want to gate a variable signal, there more complicated devices, sometimes called digital relays, that give you a way to digitally switch it.

As for individually controlling 25 LED's with a single IO port. As others suggested, you can use a few shift registers. There are more complicated solutions involving communicating with another IC using a serial protocol (I2C for example).

\$\endgroup\$
0
\$\begingroup\$

Roman Black describes the shift1 system that allows you to independently control any number of LEDs from a single microcontroller pin.

@Fake Name, @Tim, @pingswept all suggest chaining some shift registers together, the DO data output pin on one feeding the DI data input pin on the next. The 74HC595 would work fine. (Perhaps some other chip would work slighly better).

(@reemrevnivek, with this kind of daisy-chained SPI, each device after the first does not require any more pins on the microcontroller, contrary to what many people claim -- why do you listen to them? :-).

Normally this requires 4 pins on the microcontroler -- MISO, MOSI, SCLK, and latch. Since you are only doing output, you don't need a MISO input pin.

Roman Black has figured out that with a some very careful timing on on a single microcontroller output, and with some careful tweaking of an analog circuit, a single microcontroller pin can drive a simple-looking analog circuit that separates out the common SCLK, the DI pin of the first chip in the chain (MOSI), and the common latch signal.

Then that microcontroller can control 25 LEDs from a single pin.

\$\endgroup\$
0
\$\begingroup\$

You can connect another microcontroller via that single pin, and talk to it via 1wire (or your own protocol if you need high speed). Then that other microcontroller deals with LEDs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.