Oz-Solutions Tutorial: RGB LED - Netduino 2 (and Netduino 1) - Netduino Forums
   
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

Oz-Solutions Tutorial: RGB LED


  • Please log in to reply
26 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 08 November 2010 - 12:57 AM

A tutorial on using an RGB LED, this video is WAY shorter than my digital input and output video so you won't die of boredom :) NOTE: Please use a resistor with your RGB LED., I will update the diagram/schematic soon. Video: Code: The code is kinda long so please go to http://oz.heliohost.org to download/view the Program.cs file and the diagram seen in the video. Thanks! Code and Diagram are attacked here, but there's no harm in visiting my traffic-less website ;) NOTE: Please use a resistor with your RGB LED., I have updated the diagram/schematic.

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 November 2010 - 03:38 AM

The paper cube was a good idea...to diffuse the RGB LED light. And at less than 5 minutes, it was easy to find the time to watch the whole tutorial... Thanks for posting this, oz! Chris

#3 CwbhX

CwbhX

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationNYC

Posted 08 November 2010 - 04:02 AM

Ah! Great video! This is going to help me (the Newbie :P) a lot with my project. Thank you sooo much for this Oz! Sincerely, Cwbh
-Cwbh

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 08 November 2010 - 08:39 AM

Very nice tutorial. But please include current limiting resistors in the schematic, so people do not burn both the LED and Netduino (PWM pins can source only 8 mA).

#5 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 08 November 2010 - 03:00 PM

I'm glad the tutorial was helpful, thanks to all for your kind comments and for watching.

...

Very nice tutorial. But please include current limiting resistors in the schematic, so people do not burn both the LED and Netduino (PWM pins can source only 8 mA).


I didn't think about the current being used, I'll update the schematic as soon as possible (this weekend at the latest). thanks for pointing this out!

#6 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 08 November 2010 - 09:15 PM

Very nice tutorial. But please include current limiting resistors in the schematic, so people do not burn both the LED and Netduino (PWM pins can source only 8 mA).


I updated the schematic, thanks again for pointing this out.

#7 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 08 November 2010 - 09:50 PM

I updated the schematic, thanks again for pointing this out.

Nice try Posted Image I am not going to nit-pick any further, but generally it is not considered a good idea to connect LEDs with different forward voltage in parallel with one resistor. The reason is left as an exercise for the curious reader Posted Image

P.S. Is the resistor really yellow-violet-yellow (470 kΩ)?

#8 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 08 November 2010 - 10:03 PM

Nice try Posted Image I am not going to nit-pick any further, but generally it is not considered a good idea to connect LEDs with different forward voltage in parallel with one resistor. The reason is left as an exercise for the curious reader Posted Image

P.S. Is the resistor really yellow-violet-yellow (470 kΩ)?


It would be a shame if someone messed up their netduino or led because of me, so nit-pick all you wish! The resistor is that value, I used that value with some other leds I have, but I feel like it isn't to important since [hopefully] people will use the resistor that fits their led. I am sitting here ready to change the schematic, what resistance would you suggest?

#9 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 08 November 2010 - 11:24 PM

It would be a shame if someone messed up their netduino or led because of me, so nit-pick all you wish! The resistor is that value, I used that value with some other leds I have, but I feel like it isn't to important since [hopefully] people will use the resistor that fits their led. I am sitting here ready to change the schematic, what resistance would you suggest?

Well then...

In general, the value of current limiting resistor is calculated as R = (VCC - VF)/IF, where VCC is the supply voltage, VF is LED forward voltage (aka drop) and IF is LED forward current. The typical and maximum values of VF and IF are usually obtained from the device datasheet, certain safe values can be used (depending on LED color) in case the datasheet is not available. For example, Sparkfun's RGB LED has typical forward voltage 2.0V/3.2V/3.2V for Red/Green/Blue at IF = 20 mA. Thus, the resistor values for LEDs powered from 3.3V rail are:

  • Red: (3.3 [V] - 2.0 [V])/0.02 [A] = 65 Ω,
  • Green: (3.3 [V] - 3.2 [V])/0.02 [A] = 5 Ω,
  • Blue: (3.3 [V] - 3.2 [V])/0.02 [A] = 5 Ω.
Unfortunately, Netduino PWM pins can handle only 8 mA, so you'd need to use a transistor to switch higher current, or increase the resistance so the current falls below safe 8 mA - however, LEDs will be significantly dimmer (look for Luminous Intensity vs. Forward Current chart; unfortunately it is not included in the mentioned datasheet):

  • Red: (3.3 [V] - 2.0 [V])/0.008 [A] = 162 Ω,
  • Green: (3.3 [V] - 3.2 [V])/0.008 [A] = 12.5 Ω,
  • Blue: (3.3 [V] - 3.2 [V])/0.008 [A] = 12.5 Ω.
Now, the above is for LED driven in continuous mode. When in pulse mode (i.e. PWM), the current is actually lower, because it flows only when the signal is high, it is directly dependent on duty cycle for square waves. This means that for 10% duty cycle the current should be 10× higher to get the same average, resulting in the same luminosity. Suddenly, we are talking about ~100 mA, which is a lot, Netduino cannot handle such current on any pin, even Arduino has 40 mA limit per pin. This so called 'peak current' is also mentioned in the datasheet, for this particular RGB LED the absolute maximum value is (rather low) 30 mA; 100 mA is not uncommon. The resistor is calculated using the same formula, the real challenge is to ensure the LED is being switched on only for short period of time - leaving the pin on continuously while debugging will burn it. Perhaps a specialized driver IC is worth considering in such scenarios, they usually contain constant current source circuitry, various protections etc.

Regarding the shared resistor and parallel LED connection, it is relatively safe (if you know what you are doing) for LEDs with the same forward voltage - it can vary significantly, so measure, prefer LEDs from the same batch etc. For different forward voltages (e.g. 2.0 V red vs. 3.2 V green) the variations in the forward voltage requirements of individual LEDs will result in non-uniform current distribution, which means non-uniform brightness. Additionally, if one of the LEDs fails, the other can be damaged by high current.

There is a lot of information on the subject available on the Internet, the key is to understand the LED current vs. voltage characteristics - the I-V diagram. Hope this helps a bit.

P.S. Burning LED smells really badly...

#10 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 08 November 2010 - 11:41 PM

P.S. Burning LED smells really badly...


Thanks for that wonderful information. Though, I'll leave the diagram as it is since all LEDs are different, and hopefully people read your very detailed explanation above. If you make a diagram with all those safety features included you're welcome to post it here, I can even attach it to this thread, with proper credits given of course.

Thanks again

#11 Gandarez

Gandarez

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationSão Paulo/Brazil

Posted 27 February 2011 - 03:47 AM

Hi, When I create new PWM I receive a Exception, Anybody knows ? Thanks!

#12 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 27 February 2011 - 03:50 AM

Hi,

When I create new PWM I receive a Exception, Anybody knows ?

Thanks!


type the erro message in here, maybe i can help. OH and only pins 5 6 9 and 10 are PWM.

#13 Gandarez

Gandarez

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationSão Paulo/Brazil

Posted 27 February 2011 - 04:01 AM

type the erro message in here, maybe i can help. OH and only pins 5 6 9 and 10 are PWM.


OZ, mine is FEZ Panda, it has 6 PWM IOs, are 5,6,8,9,10 and maybe the 7.

Look the exception in attachment;

Thank you in advance.

Attached Files



#14 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 27 February 2011 - 04:15 AM

OZ, mine is FEZ Panda, it has 6 PWM IOs, are 5,6,8,9,10 and maybe the 7.

Look the exception in attachment;

Thank you in advance.


Hi Gandarez,

Let's see if we can get you started on the right path...

I believe that you need to switch your pin assignments over to the ones GHI uses for the NXP chips. And then manually cast their Pins enumerations to the Cpu.Pin type using (Cpu.Pin).

Here's a link to GHI's forum. You may be able to get insights there (and I believe they have the reference design schematics available as well).

Chris

#15 dny238

dny238

    New Member

  • Members
  • Pip
  • 1 posts

Posted 04 July 2012 - 03:20 AM

Guys, I could use some help. We've built a netduino project similar to this one. But it doesn't work. I took this sample code and tried it too, doesn't work. I grabbed a couple of AA batteries and put them in series to generate 3volts, then touched the contacts to my led to see if it's broken, and it works, but only if I reverse the polarity from what's in the diagram. What am i doing wrong? I was connecting the negative side of the battery to longest lead (common) of the RGB LED. That won't light it up, but it will if I reverse the connection and put the positive to the common. Have I done something wrong? Rob

#16 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 04 July 2012 - 06:50 AM

Guys,
I could use some help. We've built a netduino project similar to this one. But it doesn't work. I took this sample code and tried it too, doesn't work.

I grabbed a couple of AA batteries and put them in series to generate 3volts, then touched the contacts to my led to see if it's broken, and it works, but only if I reverse the polarity from what's in the diagram. What am i doing wrong?

I was connecting the negative side of the battery to longest lead (common) of the RGB LED. That won't light it up, but it will if I reverse the connection and put the positive to the common.

Have I done something wrong?
Rob


I think you've got a common anode LED. There is nothing you're doing wrong, just put the common lead into the 3V# instead of GND. this will also make it so SetDutyCycle(0) will turn them on, and SetDutyCycle(100) will turn them off. so its reversed.

#17 Guardian

Guardian

    New Member

  • Members
  • Pip
  • 5 posts

Posted 15 December 2012 - 06:27 PM

Hello, I'm beginner of NetDuino Plus2 I have a error when I do your source code: Microsoft.SPOT.Hardware.PWM ne contient pas un constructeur qui accepte des arguments 1. I have the same code. Sorry I'm very bad English and I can make spelling mistakes. Thanks

#18 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 17 December 2012 - 11:32 PM

Hello Guardian,

I'm beginner of NetDuino Plus2
I have a error when I do your source code:
Microsoft.SPOT.Hardware.PWM ne contient pas un constructeur qui accepte des arguments 1.

The Microsoft.SPOT.Hardware.PWM class constructor requires four arguments.
http://msdn.microsof...y/hh399616.aspx

You'll need to add period/duration or frequency/dutycycle and then set "invert" to bool, for a total of four agruments.

These arguments' values will be used as the starting PWM configuration when you call PWM.Start().

Does that help get you on the right path?

Chris

#19 Guardian

Guardian

    New Member

  • Members
  • Pip
  • 5 posts

Posted 21 December 2012 - 11:24 PM

Yes Thanks for your answer Chris. But now I have a new problem. public static void Main() { // write your code here PWM redLed = new PWM(SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_PIN_D9, 100, 50, false); PWM greenLed = new PWM(SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_PIN_D6, 100, 0, false); PWM blueLed = new PWM(SecretLabs.NETMF.Hardware.Netduino.PWMChannels.PWM_PIN_D5, 100, 70, false); redLed.SetDutyCycle = (100); greenLed.SetDutyCycle = (0); blueLed.SetDutyCycle = (75); Thread.Sleep(Timeout.Infinite); } With SetDutyCycle, V C# Visual Studio tells me that there is an error. 'Microsoft.SPOT.Hardware.PWM' ne contient pas une définition pour 'SetDutyCycle' et aucune méthode d'extension 'SetDutyCycle' acceptant un premier argument de type 'Microsoft.SPOT.Hardware.PWM' n'a été trouvée (une directive using ou une référence d'assembly est-elle manquante ?) This syntax SetDutyCycle is obsolete or I have do an error ? I want use RBG led and change the color. Thanks and sorry for english mistakes

#20 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 22 December 2012 - 08:08 AM

you wanna use like redLed.DutyCycle = 0.5f; (50%) its in percent from 0.0f - 1.0f




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.