User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Using all 17 available GPIO pins (to build a binary clock)

Wed Oct 31, 2012 9:10 am

Hi!

As my first attempt to use the GPIO pins of the Raspberry PI, I'd like to attempt building a binary clock with LEDs. Perhaps it's not the best approach to power such a clock with a Raspberry Pi, but it would be a good learning project for me. I wish to display the time in 24-hours format, which means that I need 5 bits to display hours (0-23 fits into 5 bits), 6 bits to display minutes (0-59 fits into 6 bits) and again 6 bits for seconds. This means that I need 17 programmable GPIO pins to drive 17 LEDs. I've searched the net a lot to find out how this can be done but I still have a few important questions and I'm hoping to find some answers here :)

I've found a good table of the usable GPIO pins here: https://projects.drogon.net/raspberry-pi/wiringpi/pins/. Lucky me, it seems that exactly 17 programmable GPIO pins are available (well, actually I have a Raspberry Pi Model B Revision B, so there are 4 more available, but it seems that the binary clock could be powered by any R.Pi model :D ).

The way I imagine things is to connect the positive lead of one conventional LED to each of the programmable GPIO pins through a resistor of appropriate value and to connect the negative lead of ALL 17 LEDs to the very same GND pin on the R.Pi. So the first question is: is this correct? Can the GND pin handle the current coming from all 17 LEDs?

My greatest problem is I cannot find the resistor values I need to use for each LED. sure, I know Ohm's law and I know that I'm aiming for a 10 mA current through each led. But there are two things that I don't know: 1. Do the programmable pins provide 3.3V or 5V? 2. Do some of the programmable pins have built-in resistors? If yes, that needs to be subtracted from the resistor values that I plan to use for those pins. Or, in the less lucky case, the build-in resistor values are too high to allow a 10 mA current through.

Finally, I wonder if the Pi can really power my clock. Theoretically my model uses 700 mA max and I have a power supply that can theoretically supply 1.2A. This means that I still have about 500 mA available to use with the LEDs (actualy that's not entirely correct because I have a WiFi USB dongle and a WiFi USB camera plugged into the Pi, so those also eat up some current). Anyway, I'm aiming for 10 mA through each LED. This means that when all LEDs light up (that will only happen for one second each day), the clock should drain about 170 mA (max). Can the Pi handle it?

Thank you in advance for any useful info. Also, I'm new to this forum, I'm hoping I have posted my questions into the right category...
Andras
http://iqjar.com

User avatar
MattHawkinsUK
Posts: 538
Joined: Tue Jan 10, 2012 8:48 pm
Location: UK
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 1:42 pm

You are right, there are 17 GPIO pins available so that is fine. The GPIO uses 3.3V levels.

You can power an LED directly from the GPIO pins. I know people have powered 10 LEDs but not sure about 17. I would do your Ohm's Law calculations with 5mA as most LEDs will be plenty bright enough with 5mA. So using V=IR your resistors need to be :
R = (3.3-2) / 5mA
R = 260
I would round up and use 330 ohm. This assumes the drop across the LED is 2V.

The other option is to switch each LED using a transistor. That way you can use the 5V power rail. This requires more components (1 LED, 2 resistors, 1 transistor) but the 5V supply can easily supply the 80-100mA.

Whether this will work with the other USB devices plugged in I don't know. It sounds like it should be ok.
My Raspberry Pi blog and home of the BerryClip Add-on board : http://www.raspberrypi-spy.co.uk/
Follow me on Google+, Facebook, Pinterest and Twitter (@RPiSpy)

User avatar
Grumpy Mike
Posts: 931
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 1:57 pm

Do the programmable pins provide 3.3V or 5V?
3V3
Do some of the programmable pins have built-in resistors?
Yes they all do.
that needs to be subtracted from the resistor values that I plan to use for those pins.
Yes
I'm aiming for 10 mA through each LED. This means that when all LEDs light up (that will only happen for one second each day), the clock should drain about 170 mA (max). Can the Pi handle it?
No, there is not enough current capacity on the 3V3 regulators.

Read this page:-
http://www.thebox.myzen.co.uk/Raspberry ... tputs.html

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 3:23 pm

Hi Guys!

Thank you for your replies!

Grumpy Mike, the article you linked (http://www.thebox.myzen.co.uk/Raspberry ... tputs.html) is extremely valuable. Very well written and has the info I need about drawn currents. Unfortunately it's also disappointing, because it clearly says that at any given point the RPI can supply safely no more than 51 mA of current. Divided to the 17 LEDs I plan to use, I get 3mA per LED. I don't know if that's enough. Might be enough for high efficiency LEDs, I'm not sure. In the case when I need more current for the LEDs, the solution I can imagine is to send signals of 1 mA strengths to some transistors which could switch on/off the LEDs on a different power supply (not coming from the Pi). I think this is theoretically correct, but my understanding of electronics is quite limited, so I do not yet know how to hook the components up exactly or what kind of transistors are suitable. I'll have to read more on transistors...

In your replies you mentioned that the programmable GPIO pins of the Pi do have built-in resistors. Is there a way to find out those values for each pin? What I want to know is what resistor value to use with each pin to obtain the desired current (3mA if that's enough for the LEDs or 1mA if I go for the transistor-based solution).

Thanks!
Andras
http://iqjar.com

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 3:33 pm

Un4Seen wrote:Hi Guys!

In your replies you mentioned that the programmable GPIO pins of the Pi do have built-in resistors. Is there a way to find out those values for each pin? What I want to know is what resistor value to use with each pin to obtain the desired current (3mA if that's enough for the LEDs or 1mA if I go for the transistor-based solution).

Thanks!
It's easier if you ignore the built-in resistance on the Pi's GPIO pins.

However.. If you're willing to take a little bit of a chance, then it's perfectly possible to drive all 17 GPIOs directly into LEDs via a suitable resistor. See here:

Image

I've very probably exceeding the 3.3v regulator specs there though, but proof of concept was fine. (Actually, I did leave than on for a few days at one point without any apparent ill effects)

Those LEDs have 330 ohm resistors fitted - the maximum curret drawn would be 10mA per pin with a shorted LED, fortunately the LEDs suck up some of that (ok, wrong terminology) and it's less.

Work it out with ohms law - the LEDs are (typically) dropping 1.8v, so the resistor is dropping 3.3 - 1.8 = 1.5v. 330 ohms and 1.5v is a current of I = V/R = 4.54mA. Multiply that by 17 and you get a total current of 77mA.

Go for it...

(disable the serial lines in /boot/cmdline.txt and /etc/inittab though)

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 3:57 pm

Thanks Gordon!

But what did you mean by ignoring the built-in resistors? I thought that if a pin has a built-in resistor, than it must be taken into account when calculating the value of the needed additional resistor to achieve a given current (3mA for example in my case). How can I ignore them?
And why give the LEDs 4.54 mA instead of say 3mA which totals to a safe 51 mA?

Why is it important to serial lines in /boot/cmdline.txt and /etc/inittab?

Lot of questions :)
Andras
http://iqjar.com

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 4:03 pm

Un4Seen wrote:Thanks Gordon!

But what did you mean by ignoring the built-in resistors? I thought that if a pin has a built-in resistor, than it must be taken into account when calculating the value of the needed additional resistor to achieve a given current (3mA for example in my case). How can I ignore them?
And why give the LEDs 4.54 mA instead of say 3mA which totals to a safe 51 mA?

Why is it important to serial lines in /boot/cmdline.txt and /etc/inittab?

Lot of questions :)
The built-in's are for pull-up or pull-down purposes. They're for when a pin is in input mode. When the pin is an output, there is still effectively a tiny bit of resistance between the pin and the +3.3 or 0v supplys for for all intents and purposes it's so small that we can ignore it.

I had 330 ohm resistors to-hand, and they go well with my quick approximation of using 100x the voltage when connecting up standard LEDs. By all means use a higher value resistor!

By default the Pi uses the last 2 GPIOs as a serial output - when using it for other stuff you should turn off what the Pi/Linux is using it for. So edit the bits out of /boot/cmdline.txt and edit the line out of /etc/inittab that refers to /dev/ttyAMA0. Otherwise it's conceviable that the Pi will write something to the serial port which may affect what you're written...

-Gordon
--
Gordons projects: https://projects.drogon.net/

User avatar
RaTTuS
Posts: 10531
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 4:07 pm

Grumpy Mike does know what he's talking about
and it's better in the long run to do the job properly ,..,, ;)
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 5:46 pm

Thanks for the replies, guys! Especially to you, Gordon, for having the patience to explain it simply.

According to all the info gathered here it seems that I'll be able to control 17 LEDs directly through the 17 available programmable GPIO pins, as long as the LEDs can light up with 3mA of current. I'll have to experiment with that. If it does not work, I'll have to think about a more complex method, which involves switching the LEDs using transistors...
Andras
http://iqjar.com

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 7:04 pm

Can I suggest Charlieplexing? You could Charlieplex the LEDs, lighting one at a time in so fast a succession that they all appear to be on at once.

Here's my write up on how to do this with the RPi:

http://www.instructables.com/id/Charlie ... pberry-Pi/
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 7:44 pm

Charlieplexing... I just looked up the term on Wikipedia. What I understood is that it could be possible to drive n*(n-1) LEDs with n pins. But I can't imagine how that is physically achievable. For the binary clock I must be able to light up each of the 17 LEDs individually in all possible combinations. I'll have to read up on this because either I don't understand how it is physically possible to light n LEDs with less than n pins or it is not applicable to my project. I mean each LED has two states: on or off and each pin has two states: low or high. That would make one think that if we need the LEDs to light up in all possible combinations, than we need one pin for each LED.
You mentioned lighting the LEDs in a succession extremely fast, making use of what I know to be called Persistence of Vision and fooling the person who looks at them into thinking that they are all lit up. But I still can't figure out how to light multiple LEDs in sequence using fewer pins than the number of the LEDs.
I'll see what I can find about the topic, maybe it is possible somehow :)
Andras
http://iqjar.com

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 7:55 pm

My link takes you to my own writeup on it. It's possible because each pin has THREE states. High and low, as you said, and INPUT. When a pin is input, it doesn't complete a circuit.

So between two pins, you'll have two LEDs, going in opposite "directions". To light one, you make one pin high and one pin low. To light the other, one pin low and one pin high.

Now add a third pin. Add a pair of LEDs between the second and third pins. Leave the third pin as an INPUT, and then bring the first pin high and the second pin low. The first LED lights because it's between high and low. But neither of the LEDs in the second pair light because they are between low and INPUT.

Add a third pair between the third pin and the first pin, and you'll see the same behavior. Now, if you bring the first pin high, the second pin in, and the third pin low, you'll light only one LED from the pair of LEDs between the first and last pins.

Code: Select all

+------|>|------+
+------|<|------+
|               |
+--|>|--+--|>|--+
+--|<|--+--|<|--+
|       |       |
1       2       3
Bring 1 HIGH, 2 INPUT and 3 LOW, and only the top LED on the top pair will light.

Bring 1 INPUT, 2 LOW and 3 HIGH, and only the bottom LED on the pair between 2 and 3 will light.
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 8:01 pm

And sometimes when you need 17 LEDs and you have 17 GPIOs, life is so much easier...

Charlieplexing is fine, but it needs CPU and a lot of thought to make work.

-Gordon
--
Gordons projects: https://projects.drogon.net/

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 8:14 pm

[email protected] wrote:And sometimes when you need 17 LEDs and you have 17 GPIOs, life is so much easier...

Charlieplexing is fine, but it needs CPU and a lot of thought to make work.

-Gordon
But Gordon, challenging yourself like that is what the RPi is all about. Teaching kids (and all people) who to program and do neat projects like this!
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 8:27 pm

rickseiden wrote:
[email protected] wrote:And sometimes when you need 17 LEDs and you have 17 GPIOs, life is so much easier...

Charlieplexing is fine, but it needs CPU and a lot of thought to make work.

-Gordon
But Gordon, challenging yourself like that is what the RPi is all about. Teaching kids (and all people) who to program and do neat projects like this!
You're right... but sometimes ....

-Gordon
--
Gordons projects: https://projects.drogon.net/

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 8:33 pm

[email protected] wrote:
You're right... but sometimes ....

-Gordon
You're right, too. Sometimes... :)
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Grumpy Mike
Posts: 931
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 8:41 pm

But what did you mean by ignoring the built-in resistors? I
The "built in" series resistor is only 30R which in the context of a resistor you need to limit the current to an LED is insignificant. That is why you can ignore it.

You can use transistors or buffers to increase the power. Did you see the buffer board on the same site?:-
http://www.thebox.myzen.co.uk/Raspberry ... Board.html
That gives you a lot of current capability, more than you need but then that is not a bad thing.
Other buffers you can use are 74HC04, (six in a package) you can run that off 5V and get 20mA per buffer. As this comes from the 5V supply so you have more current to play with.

Charliplexing relies on getting the program running continuously which under Linux it won't, so it will flicker from time to time.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 11:27 pm

I know I've already said this a couple of times, but thank you for yor help, guys :D

rickseiden, sorry, I missed the link in your previous answer. Yes, now it's starting to make sense. Given the fact that the pins can have 3 different states, it's a world of whole new possibilities :) It's an exciting thing to do, especially the software part and I'm a software guy much more than a hardware guy, so I'd definitely give it a try sometime. However, for the binary clock I do get the feeling that Charlieplexing is overkill. And I'm worried about what Grumpy Mike wrote, that there will most likely be flickering under Linux. So I'll probably pass on it for this project, but it's definitely something to consider for my next dream project on the Pi, which is an 8x8x8 LED cube. Oh, yeah!

So I tend to agree with Gordon for the binary clock and try to do it the simple way. If the LEDs can light up with 3mA, than it's as simple as it gets. I just need LEDs and appropriate resistors. By the way, I'm having a hard time accepting the values that I calculated for the resistor values. Let's assume that I use standard 5mm white LEDs, which, as far as I know have a voltage drop of 3.3V (what a coincidence!). We also know that our desired current through the LED is 3mA. Using the online LED calculator (http://led.linear1.org/1led.wiz), we find that the needed resistor value is 1 Ohm. That sounds suspiciously small to me. And if it really is that small, than the mentioned built-in resistor values of around 30 Ohm can play an important role. This small value also does not seem to line up with what Gordon wrote earlier, that he recommends to use resistor values larger than 330 Ohm... what am I missing here? PErhaps Gordon was using LEDs with a smaller voltage drop (say, 2V?). Seems to me that knowing the EXACT voltage drop across the LEDs is important here, but that's kind of hard to knwo for sure and I also read somewhere that it can change as the LEDs get warmer.

Getting back to what Grumpy Mike wrote, that transistors and buffers could be used to get more power, sounds good, but I must confess that the article exceeds my knowledge of electronics a lot and I don't quite understand it yet... but I'll read it a few more times, maybe I will eventually find enlightment :)

Thanks!
Andras
http://iqjar.com

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Using all 17 available GPIO pins (to build a binary cloc

Wed Oct 31, 2012 11:53 pm

You will get flickering with any multi/charlie-plexing you do. I just did a multiplexing project where I ran a 7x5 array off two shift registers and a buffered output. It took some doing, and about a billion wires, but it worked beautifully. Tons of flickering, even at the best settings I could come up with, and I only saved about 7 pins in the process. I could have done 12 pins straight from the Pi to the array, but this method lends itself to adding a second 7x5 array to make a 14x5 array without adding any extra pins. I just need a third shift register in there, and I'd be good to go.

Anyway, it's not like I'm planning on building anything permanent out of this. It's just for fun, so if I can make something happen, like this, I'm good with the results.
There are 10 types of people in this world. Those that understand binary, and those that don't.

techpaul
Posts: 1512
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Thu Nov 01, 2012 12:51 am

Realistically if you want to multiplex arrays it is better done with dedicated hardware to continuously scan the arary and use another system to update simpler codes.

Alternatively for simpler matrix use registers like 74AHC595, which has a shift register latch and output enable function, then have a small piece of hardware a counter and decoder driven from a clock (like the GCLK output on the Pi), the decoder outputs enable the latch oputput enables one at a time and any 'column' drive.

Personally I would consider a small MCU to control the matrix and Pi to update the MCU
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Thu Nov 01, 2012 11:19 am

I'm still concerned with trying the simplest solution first, that is, connect each of the 17 LEDs to a different programmable RPI GPIO pin through a resistor in a way that would give 3mA of current to each LED. I did some more reading and thinking about the topic and I think I know 100% of the theory to start doing it, but it seems a bit dangerous to me, because of the resistor values that I think I need to use.

As I wrote earlier, the diode forward voltage for a standard 5mm white LED is usually 3.3V. Unfortunately the source voltage coming from the Pi pins is also 3.3V. So what resistor value do we need? R=V/I and V=0 in this equation because the LED drops all the source voltage. So this results in R=0. In other words I could connect the LED to the Pi pins directly, without any resistor. Now this seems dangerous from start. First of all what guarantees that the LED's voltage drop is indeed 3.3V, as indicated by the manufacturer? Is there a way to measure it? Second of all, LEDs are known to change their voltage drop as they warm up. So let's assume for a second that the LED's voltage drop differs from the specs or that it drops during use to 3V. This means that I'd need a resistor to handle the extra 0.3V, but I have not connected a resistor, so the current flowing is I=V/R=0.3/0=infinite. Doesn't sound good at all. Or, let's assume that I used an 1 Ohm resistor, as indicated by the LED calculator that I mentioned earlier. Still, I=V/R=0.3/1 = 0.3A = 300mA flowing through the Pi pins. Scary! And let's not even mention the built-in pin resistors of around 30 Ohms, which would play an important part in this case.

What is the safe way to proceed here? Assume that the LED can still work with a voltage drop of only, say 3V, and connect a 100 Ohm resistor? Or perhaps even that's not safe enough... Maybe I should experiment with the LEDs, find the highest resistor value with which they still light up fine when connected to a 3.3V power source. The only problem with that is that I don't have a 3.3V power source, except the Pi. So I need to figure it out in theory. :) It's not simple... :)

Thanks!
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Thu Nov 01, 2012 11:31 am

The reason I'm involved in this insane dilemma with the white LEDs which have a voltage drop of around 3.3V instead of simply using orange LEDs for example, which drop about 2V, is that I'd like to make the hours LEDs blue, the minute LEDs orange and the second LEDs white. It would look nice :)
Andras
http://iqjar.com

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

Re: Using all 17 available GPIO pins (to build a binary cloc

Thu Nov 01, 2012 11:37 am

Hmm. Yes the average forward voltage of a common red LED is about 2 Volt, but its the LED's that have a color more towards blue that have higher forward voltages.
And indeed white LED's have a forward current nearer to 3 volt.

Also obviously the forward voltage also depends on the amount of current running through it.
As a diode a LED has a quite miserable voltage/current curve, not abrupt at all.

Driving white LED's directly from a 3V3 GPIO is therefore a bit tricky.
The simplest solution would be to use a cheap N-FET, like a 2N7002, and just let the PI drive only the gate of the FET. Then let the FET switch the LED which is fed from 5V instead of 3V3.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Thu Nov 01, 2012 11:46 am

That doesn't sound bad at all. With the use of a transistor I could indeed use the 5V pin to drive the LEDs. Do I need to include anything, like a resistor between the GPIO pin, the transistor and the GND pin (in the "driving" circuit)? How should this FET be connected (which leg goes where)? The "driven" circuit remains the same I guess as it would be without a transistor, except that now the resistor value has to be recalculated for 5V-3.3V.

Thanks! :)
Andras
http://iqjar.com

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Using all 17 available GPIO pins (to build a binary cloc

Thu Nov 01, 2012 11:50 am

Un4Seen wrote:I'm still concerned with trying the simplest solution first, that is, connect each of the 17 LEDs to a different programmable RPI GPIO pin through a resistor in a way that would give 3mA of current to each LED. I did some more reading and thinking about the topic and I think I know 100% of the theory to start doing it, but it seems a bit dangerous to me, because of the resistor values that I think I need to use.

As I wrote earlier, the diode forward voltage for a standard 5mm white LED is usually 3.3V. Unfortunately the source voltage coming from the Pi pins is also 3.3V. So what resistor value do we need? R=V/I and V=0 in this equation because the LED drops all the source voltage. So this results in R=0. In other words I could connect the LED to the Pi pins directly, without any resistor. Now this seems dangerous from start. First of all what guarantees that the LED's voltage drop is indeed 3.3V, as indicated by the manufacturer? Is there a way to measure it? Second of all, LEDs are known to change their voltage drop as they warm up. So let's assume for a second that the LED's voltage drop differs from the specs or that it drops during use to 3V. This means that I'd need a resistor to handle the extra 0.3V, but I have not connected a resistor, so the current flowing is I=V/R=0.3/0=infinite. Doesn't sound good at all. Or, let's assume that I used an 1 Ohm resistor, as indicated by the LED calculator that I mentioned earlier. Still, I=V/R=0.3/1 = 0.3A = 300mA flowing through the Pi pins. Scary! And let's not even mention the built-in pin resistors of around 30 Ohms, which would play an important part in this case.

What is the safe way to proceed here? Assume that the LED can still work with a voltage drop of only, say 3V, and connect a 100 Ohm resistor? Or perhaps even that's not safe enough... Maybe I should experiment with the LEDs, find the highest resistor value with which they still light up fine when connected to a 3.3V power source. The only problem with that is that I don't have a 3.3V power source, except the Pi. So I need to figure it out in theory. :) It's not simple... :)

Thanks!
I've just read the others posts since writing this - white LEDs. Power hungry!

Why not try this:

Connect a 330Ω resistor to the Pi's 3.3v line, then connect that to one of those white LEDs and to ground and see how bright (or dim!) it is.

You might find that it's acceptable - you might not. If it's usable, then great, but if its unusable for normal use, but usable for your own experiments, then what I'd be tempted to do is bear with it for your own experiments, use it to develop the software with, then when happy with the software, move on to a plan B.

And that plan B might involve using transistors/FETs/uln2003's to drive each LED off the 5V supply, but right now, it sounds like you're pretty new to electronics, so start with the LEDs then you can progress in stages.

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “Interfacing (DSI, CSI, I2C, etc.)”