abojiuc
Posts: 4
Joined: Sun Jul 15, 2018 11:57 pm

Controlling 100 LEDs?

Mon Jul 16, 2018 12:01 am

I would like to be able to turn on and off 100 LEDs.
The problem is that there isn't enough pins to control each one.
How can I solve this?

Thanks in advance.

Heater
Posts: 9463
Joined: Tue Jul 17, 2012 3:02 pm

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 3:00 am

Typically many LEDS are driven from few outputs using a technique called "multiplexing". Google can find thousands of articles about "multiplexing LEDS". Like this one: http://www.instructables.com/id/Multipl ... e-74HC595/

In modern times LEDS can be obtained that have some digital logic built in such that hundreds of them can be driven in a chain from just two pins. For example the WS2812 LEDS https://cdn-shop.adafruit.com/datasheets/WS2812.pdf Available in strips like this: https://www.adafruit.com/product/1138?length=1

abojiuc
Posts: 4
Joined: Sun Jul 15, 2018 11:57 pm

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 3:21 am

What if I wanted to control something besides LEDs like an electromagnet? I looked at multiplexing and if I understood correctly only one row is on at a time. I need each component to stay on if they are supposed to be on at all times.

Rine74
Posts: 2
Joined: Mon Jul 16, 2018 5:31 am

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 5:34 am

Yes, You would have individual control of each led (consider each shiftregister as 8 additional out pins)

There's lot's of code samples around for controlling shiftregisters.

Your biggest problem is going to be the wiring of 100 LED's...

Heater
Posts: 9463
Joined: Tue Jul 17, 2012 3:02 pm

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 6:11 am

Multiplexed LEDS are indeed being switched on and off rapidly. Give the persistence of vision of your eyes you do not notice that.

Controlling and electromagnet is a different problem. Use different pins for that. You will need driver transistors, back EMF protection diodes, perhaps even opto-isolators, probably a separate power supply. Google will find hundreds of circuits an suggestions for doing that.

If you need more pins perhaps use a port expander chip like the MCP23S17. For example: http://www.instructables.com/id/Raspber ... -Expander/

abojiuc
Posts: 4
Joined: Sun Jul 15, 2018 11:57 pm

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 7:17 pm

Good advice,
Just out of curiosity what's the max number of pins I can extend to even with additional products?

PiGraham
Posts: 3315
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 7:32 pm

abojiuc wrote:
Mon Jul 16, 2018 7:17 pm
Good advice,
Just out of curiosity what's the max number of pins I can extend to even with additional products?
There isn't really an answer to that. It depends how fast you need to upfdate states and how far signals have to travel. In general the further you need to go the slower and the more discrete devices the longer it takes to update them all. You can connect a hundred LEDs to a single GPIO pin if the distance between each LED is short. See "neopixels", WS2812 etc.

Why don't you tell us what you are hoping to do?

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 9:49 pm

abojiuc wrote:
Mon Jul 16, 2018 7:17 pm
Just out of curiosity what's the max number of pins I can extend to even with additional products?
The RPi is great for programming. It's great for getting some logic signals in and out. It is not great at interfacing to real-world hardware, and was never designed to be. That's why we have HATs. HATs provide the signal conditioning needed to protect the delicate RPi from the chunky outside world, and extend the functions of the RPi to analogue I/O, multiplexed switching, serial control, etc etc etc.

Instead of thinking "what can I get away with wiring to the RPi", you should be thinking "what HAT do I need to connect this to the RPi".

You can design your own circuits instead of using HATs, if you are patient enough to learn how (and willing to risk blowing up your RPi if you make a mistake). The information you need to make a start is here: Beginners Guide to Wiring Things to the GPIO
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

PiGraham
Posts: 3315
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 10:28 pm

The first thing to think about is to be clear about the objective. Work out if you need 100 discrete LEDs on a single Pi or or a string of 100 neopixels or a distributed system that is maybe networked together or a matrix LED panel. There are may possibilities and the best option may not be a HAT.

abojiuc
Posts: 4
Joined: Sun Jul 15, 2018 11:57 pm

Re: Controlling 100 LEDs?

Mon Jul 16, 2018 10:35 pm

Basically I want to be able to control about 16 or more electromagnets. To be able to turn them off and on from my PC. Each one is fairly small (dice sized) and doesn't require much current, although I will use an external power supply.

Each electromagnet will keep a plate elevated or lowered depending if it's on or off. Multiplexing like an LED probably won't work in this case.

I never heard of HAT before, could you tell me more about it? It sounds exactly like what I may need.

Also since my PC is already calculating the state of each electromagnet is the PI3 necessary?

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Controlling 100 LEDs?

Tue Jul 17, 2018 6:37 am

abojiuc wrote:
Mon Jul 16, 2018 10:35 pm
Basically I want to be able to control about 16 or more electromagnets. To be able to turn them off and on from my PC. Each one is fairly small (dice sized) and doesn't require much current, although I will use an external power supply.
The first thing you need to know is how much current and how much voltage. You have to understand that the RPi GPIO outputs can only output 16mA maximum (8mA preferably), and at those currents the voltage available will be significantly less than 3V. If you want more voltage and/or current than that it is essential to use external electronics, and you need to know what your requirements are before you can choose what external electronics to use.

DO NOT think you can supply an external device with (say) 5V and turn it on and off using an RPi pin as the return to 0V. This will blow up your RPi (because when the pin is turned off, it will be subjected to 5V). With an electromagnetic device (motor, relay, solenoid, electromagnet, coil, inductor... whatever you want to call it), this is particularly the case because suddenly switching off an inductor results in large voltages being generated by the collapsing magnetic field.

The link I gave you in my last post tells you what you need to know, but people seem to come on here expecting to be told rather than read for themselves, even when shown what to read.

Beginners Guide to Wiring Things to the GPIO

abojiuc wrote:
Mon Jul 16, 2018 10:35 pm
I never heard of HAT before, could you tell me more about it? It sounds exactly like what I may need.
HATs (Hardware Attached on Top) are the extension boards designed for use with RPi. It's the easy way to go. Note some RPi extension boards can't be called HAT (because they lack certain features), but are still fine to use.

Some people use interface boards designed for Arduino - Arduino generally uses 5V systems so is not directly compatible with RPi (3.3V). People wiring Arduino interface boards to RPi need to be able to read specifications to check it will work and not damage their RPi, and potentially need to adapt the board to the RPi to make it work or be safe (but often they don't, and then they come on the forum asking what's gone wrong). Novices should not try to do this.

abojiuc wrote:
Mon Jul 16, 2018 10:35 pm
Also since my PC is already calculating the state of each electromagnet is the PI3 necessary?
If you are trying to use the RPi simply to provide a PC with I/O, you are going the wrong way. Use the RPi if you want processing independent of the PC. What you really need is a USB relay board you can control from the PC like this: USB relay board on eBay (click). In the past, I have used a PC's Centronics printer port (old school) for I/O (up to Win98). USB to Centronics adapters are available which would allow the same thing (but need some more electronics to run motors/relays/solenoids/electromagnets/lamps...).
Last edited by Z80 Refugee on Tue Jul 17, 2018 7:11 am, edited 4 times in total.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

PiGraham
Posts: 3315
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Controlling 100 LEDs?

Tue Jul 17, 2018 6:54 am

abojiuc wrote:
Mon Jul 16, 2018 10:35 pm
Basically I want to be able to control about 16 or more electromagnets. To be able to turn them off and on from my PC. Each one is fairly small (dice sized) and doesn't require much current, although I will use an external power supply.

Each electromagnet will keep a plate elevated or lowered depending if it's on or off.

Do you have this working for a single electromagnet? You should definitely fully understand the single channel case before attempting to do 16 at once.

Is this plates either up or down, or do you mean to levitate them in free air? The latter is a far more difficult job and not well suited to a Linux computer. I'll assume you want to snap the plates between up or down position.

Typically with electromagnets it takes more time and current to 'pull in' than to hold a close magnetic loop. You may find that, say, turning the control on for 500ms full power pulls the "plate" to the electromagnet and that you can then hold it there with only 10% of full power.

If that works for you then multiplexing might be possible.

abojiuc wrote:
Mon Jul 16, 2018 10:35 pm

Also since my PC is already calculating the state of each electromagnet is the PI3 necessary?
Your PC could control a gpio device itself, or you could use the Pi to do the calculations and control, or you could use some other device such as Arduino to do some or all of the task.

Heater
Posts: 9463
Joined: Tue Jul 17, 2012 3:02 pm

Re: Controlling 100 LEDs?

Tue Jul 17, 2018 7:24 am

Why ask about 100 LEDS when what you actually want is 16 electromagnets.

Personally I would buy myself a bunch of transistors, and misc. components and make solenoid drivers myself. With a circuit like this for example:
https://playground.arduino.cc/Learning/SolenoidTutorial

If more were needed I'd look at using the port expander chips.

Return to “General discussion”

Who is online

Users browsing this forum: Douglas6, HawaiianPi, steinerlein and 61 guests