Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Best way to do this?


  • Please log in to reply
19 replies to this topic

#1 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 October 2011 - 08:14 AM

I am currently working on some project (details will be available when it's done) but walked into a problem. The project contains 5 leds: - First pair of 2 leds: red & green, will emit not, red or green, they'll never emit both at the same time. - Second pair of 2 leds, same rules as the first pair - The fifth led is seperated I want to use PWM to adjust the brightness of the leds. The Mini only had 4 PWM pins and I should need 6 to connect all leds directly to the Mini. Every pair should get a PWM signal, so perhaps I can do with 3 PWM signals and two switcher pins. I thought of a very dirty solution, using a SN754410 IC to drive the leds, but perhaps someone can suggest something cleaner? It should be solid state and cheap, and I should be able to get the missing parts before friday :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 October 2011 - 09:06 AM

Hi Stefan, One more thought... We sometimes do "software PWM" in C# to change the intensity of LEDs. If there's not a lot going on in your program, you can actually create reasonable effects by turning the LED on briefly several hundred times a second. Chris

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 October 2011 - 09:52 AM

One more thought... We sometimes do "software PWM" in C# to change the intensity of LEDs. If there's not a lot going on in your program, you can actually create reasonable effects by turning the LED on briefly several hundred times a second.

Good point! I could do that.

I also considered a schematic like this, not sure if it'll work though, I don't have the ability to test right now. Yellow=PWM, Blue=GPIO.
Oh and I fergot resistors in the schematic, but it's about the generic idea of using transistors to feed back the ground in pulses.

Attached File  leds_bb.png   18.35KB   41 downloads
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 26 October 2011 - 11:05 AM

Why don't you simply do it like this:
Posted Image
(Red and green LEDs antiparallel) - that way, if the GPIO is low, pulses on the PWM make the green LED light (higher duty cycle -> brighter), if the GPIO is high, it makes the red LED light (higher duty cycle -> darker).
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 October 2011 - 11:14 AM

Why don't you simply do it like this:

(Red and green LEDs antiparallel) - that way, if the GPIO is low, pulses on the PWM make the green LED light (higher duty cycle -> brighter), if the GPIO is high, it makes the red LED light (higher duty cycle -> darker).

I considered that, but I'm afraid it would heat up my mini, and my mini doesn't like to get hot ;)
Unless someone can confirm it won't harm the mini...?
But the 'transistor-way', if the schematic is valid, could even use one PWM, and all 4 leds could use that one. I realized that after drawing out that schematic, that I just PWM ground, so it could contain all leds that need to have that brightness.

So I could use a shift register and have 8 outputs, and one PWM'ed Ground through a transistor, so all 8 leds will have the same brightness. Would that work?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 26 October 2011 - 11:39 AM

I considered that, but I'm afraid it would heat up my mini, and my mini doesn't like to get hot ;)
Unless someone can confirm it won't harm the mini...?


It's all about the current - if you stay within 8mA (low-current LEDs, or just LEDs with not full brightness), it won't harm it - and your "transistor way" is also drawing the curent from the pins. There's actually LEDs that are like this internally (two LEDs antiparallel) and i've used lots of them with arduino, netduino, and other microcontrollers without releasing magic smoke ;)

But the 'transistor-way', if the schematic is valid, could even use one PWM, and all 4 leds could use that one. I realized that after drawing out that schematic, that I just PWM ground, so it could contain all leds that need to have that brightness.

So I could use a shift register and have 8 outputs, and one PWM'ed Ground through a transistor, so all 8 leds will have the same brightness. Would that work?


I wouldn't call it a "PWM'ed Ground", but yes (you already mentioned that your schematic is incomplete though, needs some more resistors and wires ;))
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#7 RichardE

RichardE

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationNorth Yorkshire, UK

Posted 26 October 2011 - 11:40 AM

How about something like this? (see attachment). Uses more pins but only one PWM output for each LED pair.

Attached Files



#8 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 October 2011 - 11:46 AM

Cool! I'm going to test some stuff tonight on my breadboard and will post the results here. If all 4 leds could emit at the same time it would be funny, not required for my project though. In the mean while, I'll read every suggestion and try to figure out the best for my project :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 26 October 2011 - 02:29 PM

Sorry, Stefan, for the delay. I have no other ideas than the StefanW one. There's another solution that would save some pin, but it increases the external hardware. My vote for the StefanW way. The Richard's one is also good, but wastes too many pins IMHO. Cheers
Biggest fault of Netduino? It runs by electricity.

#10 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 26 October 2011 - 02:36 PM

My vote for the StefanW way. The Richard's one is also good, but wastes too many pins IMHO.

Thanks, my own way, by adding a transistor doesn't have your support? Just checking ;) That would actually saves me the most pins and I got a few transistors at my desk atm. If you prefer the method of Stefan (ohh, now it gets confusing!) I'm going to pull that off.

The purpose has something to do with an upcoming holiday, I hope that when it's done, I can post some more details, but I'm not sure if I get it done in time :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#11 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 26 October 2011 - 03:56 PM

With the antiparallel LEDs, you need 2 pins per pair -> one pin per LED -> 5 total, your fritzing board uses 6 pins for 4 leds ;) - if you use a shift register + transistor, that'll be 4 pins (clock, latch, data + transistor), where you can't individually control the brightness ... if that's ok for you, you could do that - or just use an LED PWM driver IC ;)
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#12 RichardE

RichardE

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationNorth Yorkshire, UK

Posted 27 October 2011 - 11:20 AM

If you want to go the PWM IC route the Texas Instruments - TLC5940 looks like a good bet. This allows you to PWM up to 16 LEDs with up to 60 mA per LED but you will still only need 3 digital output pins however many LEDs you use. You can also daisy chain these devices if you need more LEDs. Will even run off 3.3V although you will probably want to use a separate supply for the LEDs if you are driving more than a few (not sure how much current you can draw from the 3.3V supply).

You can get these chips from Farnell (order code 1226306) in breadboard friendly DIL packages.

See link to TLC5940

#13 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 27 October 2011 - 12:30 PM

The IC probably does not fulfill the "I should be able to get the missing parts before friday", that's why I just put it in as a joke :) There are also other chips that talk over I2C and save one more pin, if that's really an issue.
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#14 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 October 2011 - 12:33 PM

The IC probably does not fulfill the "I should be able to get the missing parts before friday", that's why I just put it in as a joke :) There are also other chips that talk over I2C and save one more pin, if that's really an issue.

Good point :D
I haven't got it tested yet, going to work on it tonight/tomorrow (I'm a day off tomorrow). Yesterday I had to take care of user input for my project :D
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#15 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 October 2011 - 07:15 PM

Actually, I solved the problem like this. The normal netduino will be a mini, but I tested it exactly like this schematic: Attached File  works.jpg   85.24KB   42 downloads The red wires to the LEDs will be triggered by a high power 74HCT595, so it won't pull it's power from the Netduino. How does this look, perhaps the transistor itself requires a resistor? I'm not that familiar with transistors and their tricks...
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#16 RichardE

RichardE

    Member

  • Members
  • PipPip
  • 13 posts
  • LocationNorth Yorkshire, UK

Posted 27 October 2011 - 08:19 PM

I think you should normally put a resistor in place of the blue wire to limit the current. The way I think about it is that the maximum current that flows through the LEDs, the resistors and the transistor (from collector to emitter) will be the current that flows into the transistor base multiplied by the gain of the transistor. Normally the LED current is limited by the resistors in series with them. However, if you somehow got a short from the transistor collector to the 3.3V line then the transistor would try to pass a huge current and would probably expire. As a ballpark example, if you put a 4K7 resistor in place of the blue wire and the gain of the transistor is 100 then the base of the transistor will be sitting at around 0.6V (one diode drop) above the emitter, so 0.6V. When you take the output pin high then you will be dropping 3.3 - 0.6 = 2.7V across the resistor. Divide this by 4700 and you get roughly 0.6 mA. If you multiply this by the transistor gain of 100 then the maximum current the transistor will sink is 60 mA which should be enough to light 4 LEDs. Use a lower value resistor if you need more current, but don't draw more than 8mA from the output. If you don't fit the resistor you might get away with it because the Netduino simply won't supply the current but the hardware page states that you shouldn't draw more than 8 mA from an output so best to follow that suggestion. Did I miss something or won't all the LEDs come on at once? They are all connected to the same transistor so will come on together.

#17 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 27 October 2011 - 08:22 PM

Did I miss something or won't all the LEDs come on at once? They are all connected to the same transistor so will come on together.

True, but the red wires to the led, I'm going to switch those, not the PWM. I think I can then decide which leds will emit, according to the PWM brightness :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#18 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 27 October 2011 - 09:39 PM

By not using a resistor you might let your mini become hot, and it doesn't like that ;) (as RichardE said) - You might want to have a look at http://www.kpsec.fre...trancirc.htm#ic which tells you about how to choose the transistor/resistor values. There's also other interesting things on that page :)
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#19 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 October 2011 - 03:46 AM

Yep! Netduino it's much more stressed by the transistor without resistor, than a led connected directly to the I/O.
Biggest fault of Netduino? It runs by electricity.

#20 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 28 October 2011 - 01:56 PM

Without resistor it pulls at max 50mA I just measured. With a resistor of 1kΩ I get a max. of 2,5mA. Thanks :) Now I can continue with this project!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.