davidw087
Posts: 8
Joined: Fri Oct 11, 2013 10:48 pm
Location: London

Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 4:37 pm

Hi i was wondering how i could control multiple LEDS independently through a single GPIO pin
(I do realise i could just use another pin but this is to be scaled up to an amount more than the pins available)

Im quite new to this and have one LED lighting from a single pin by turning it high
But
For example 2 LEDS and one pin
So when something happens only one of the LEDS turn on and when something else the other will turn on.

Is this possible or is there any other equipment to allow me to

Thanks

ThomasS
Posts: 118
Joined: Thu Jan 23, 2014 7:05 pm
Location: Leeds
Contact: Website

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 5:09 pm

I don't think this is possible - simply from an electronics point of view - but I believe there is a way to add more GPIO pins to the Pi with the pin header. It's mentioned at http://www.cl.cam.ac.uk/projects/raspbe ... e/two.html under 'Expanding the Raspberry Pi Pin Header'.
ThomasS

User avatar
rpdom
Posts: 16732
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 5:15 pm

The best that you can do with just one pin is to have two LEDs.

Connect one LED (and resistor) from the pin to ground. That LED will come on when the pin is set high (1).
Connect the other LED (and resistor) from the pin to +3.3V. That LED will come on when the pin is set low (0).

But you can't have a state where both LEDs are on, or off, at the same time using this method.

Using more than one pin will allow you to multiplex the LEDs and you can turn them on and off quickly so they seem to be on all at once. Look up Charlieplex for a good way to do this.

klricks
Posts: 7025
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 5:20 pm

No you would need to use a decoder multiplexer chip.
Like a 3 to 8 decoder:
https://www.fairchildsemi.com/ds/74/74VHC138.pdf
This would use 3 GPIO to give 8 outputs (LED's) however you could only light 1 of the 8 LED's at a time

If you need to have more than 1 LED lit at a time then you would need a latching decoder mux:
http://www.onsemi.com/pub_link/Collater ... C259-D.PDF
With this to get 8 outputs you would need 5 GPIO. 3 for address, 1 data, and 1 to reset or clear. Though you may not have to use a GPIO for reset.

In either of the above if you need up to 16 outputs you could get a 4 to 16 version which would add only 1 extra GPIO pin.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

User avatar
ragnarjensen
Posts: 333
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 5:58 pm

A latching serial-to-parallel shift register. 3 GPIO to give 8 or 16 outputs.
http://maximumoctopus.com/electronics/shiftotron.htm
--
Ragnar

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12825
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 6:49 pm

You can use just two GPIO's to drive an unlimited number of LED's using daisy chained 74HC595 shift registers with output latches. Normally you would need a third GPIO for the shift serial data to parallel latches function, (ST_CP), besides the normal clock in (SH_CP) and data in (DS) inputs, but there is a trick you can use to do it without, and reduce the needed pins to just two. Simply use the last Q output of the shift-register string to (when it becomes "1") to reset all the shift registers to zeros, (using all the MR pins) and at the same time clock in the parallel data to the outputs, (using all the ST_CP pins) using a single inverter. To reset the string to all zeroes, and a known condition clock in a "1" and then the number of bits of the shift registers with "0"'s. The string will be cleared to zero, at the latest point that the initial "1" reaches the output, then simply clock in a "1" followed by the pattern of "1"'s and "0"'s you want.

I think it might even be possible to use a single GPIO bit by using a couple of RC delays, and an XOR for the clock generation. Delay the input data (DS) with an RC, and use another smaller RC to create a pulse whenever the data changes by delaying on input of the XOR with an RC and the other not. To clock in a 0 output a 0 for long enough to reach the DS input then either produce a very short 1 pulse if the next bit is again a zero, or simply transfer to one if the next bit is a one.
The idea is that in both cases the xor should produce a single clock pulse to clock in the DS data. if the XOR actually produces two pulses very close to each other, use a third RC so the pulses "flow together into one".

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 7:08 pm

Hi,
davidw087 wrote:i was wondering how i could control multiple LEDS independently through a single GPIO pin
The easiest way would be if you add a microcontroller.
davidw087 wrote:Is this possible or is there any other equipment to allow me to
Another option is to add an USB board and control LEDs with it (and GPIO pin remains available for another feature ;-) ).


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

davidw087
Posts: 8
Joined: Fri Oct 11, 2013 10:48 pm
Location: London

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 8:24 pm

Am i right in thinking a gertboard will allow me to do this? Assigning higher pin numbers (such as pin 35 etc)??
http://www.cnx-software.com/2012/08/09/ ... le-for-60/

mikerr
Posts: 2820
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Multiple LEDS from single GPIO pin

Sun Mar 09, 2014 11:11 pm

Charlieplexing can get you a lot of LEDs per GPIO at the expense of (very) complex wiring:

http://en.wikipedia.org/wiki/Charlieplexing
http://www.instructables.com/id/Charlie ... /?ALLSTEPS

Pi has 17 GPIO, through charlieplexing that would drive 17 * (17 -1) = 272 LEDs !
(but I wouldn't want to imageing the wiring nightmare!)

The real answer is to use shift registers, much simpler.
How many LEDs do you need to control ?
Android app - Raspi Card Imager - download and image SD cards - No PC required !

davidw087
Posts: 8
Joined: Fri Oct 11, 2013 10:48 pm
Location: London

Re: Multiple LEDS from single GPIO pin

Mon Mar 10, 2014 12:08 am

Only about 25 im just unsure how id address them

Return to “Beginners”