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

RGB led - cathode vs anode


  • Please log in to reply
8 replies to this topic

#1 jlprest

jlprest

    Member

  • Members
  • PipPip
  • 10 posts

Posted 30 March 2012 - 05:00 AM

Greetings. I am a noob to actually doing something with what I learned in physics years ago. I have a Netduino Plus and ordered a "starter pack" from Makershed and have been working through Getting Started with Netduino. My problem is in the section on the RGB led. It appears I was sent common anode LEDs instead of common cathode discussed in the book. When constructing the circuit as directed I got nothing but by modifying and connecting the 3 "color" leads to ground and the common lead to the 3.3V output from the Netduino I get the appropriate lights. My problem is in how to adjust the program to account for this. I understand altering the duty cycle on a voltage output but how to you adjust the duty cycle for a ground?

I am having a blast and probably have a better understanding of circuits (or at least am developing it) than I ever did.

I am posting the program as written for a common cathode LED below:


PWM redLed = new PWM(Pins.GPIO_PIN_D9);
PWM greenLed = new PWM(Pins.GPIO_PIN_D6);
PWM blueLed = new PWM(Pins.GPIO_PIN_D5);

//for purple

redLed.SetDutyCycle(60);
greenLed.SetDutyCycle(0);
blueLed.SetDutyCycle(100);

Thread.Sleep(Timeout.Infinite);

Thanks for any assistance.

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 30 March 2012 - 07:07 AM

Hello Jlprest. The common cathode leds/displays are often used as examples of application, just because they need a "positive logic" activation. That is a logic "one" means an high level (e.g. +3.3V), thus you're understanding better "boolean true means light". BTW, the common anode is a bit better, at least in cases like this. You only have to "reverse" your mind, in the sense of the logic: "boolean false means light". So, why should be better? Using a common cathode, you must rely only on the voltage outputted by the Netduino port, which is +3.3V at most. A normal led needs less than 2V to get bright, but that's not true for bigger leds, for instance. If you like, you could not place two or more led in series. If you choose the common-anode pattern, the situation is a bit different. You only need to pull the led toward the ground. The supply could be +5V, thus you have another benefit: avoiding an useless current overheating the +3.3V regulator. Please, bear in mind that both the circuits, the one in the book or the common anode, are just for experimental purposes. The output ports of the Netduino (or MCUs in general) aren't targeted to drive so much current. You won't damage the board, but it's preferable to add a transistor/mosfet for each led driven, so that the available current can get much higher. Hope it helps. Cheers
Biggest fault of Netduino? It runs by electricity.

#3 jlprest

jlprest

    Member

  • Members
  • PipPip
  • 10 posts

Posted 30 March 2012 - 06:07 PM

Thanks for the information. Much appreciated.

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 30 March 2012 - 06:30 PM

For common anode RGB LED, connect the anode to VCC and R/G/B cathodes to Netduino PWM pins (through the resistors and possibly transistors), PWM will work inversely: 0% duty cycle = on, 100% = off. The LED will be off when there is voltage on both electrodes (anode connected to VCC, PWM output logic high), because current flows only between different potentials. When PWM output is switched to logic low, the LED turns on. The PWM class does not enable you to specify the 'polarity' (it is supported by the microcontroller though, just not exposed via the managed class), so you need to invert the duty cycle.

#5 jlprest

jlprest

    Member

  • Members
  • PipPip
  • 10 posts

Posted 06 April 2012 - 03:25 AM

For common anode RGB LED, connect the anode to VCC and R/G/B cathodes to Netduino PWM pins (through the resistors and possibly transistors), PWM will work inversely: 0% duty cycle = on, 100% = off. The LED will be off when there is voltage on both electrodes (anode connected to VCC, PWM output logic high), because current flows only between different potentials. When PWM output is switched to logic low, the LED turns on. The PWM class does not enable you to specify the 'polarity' (it is supported by the microcontroller though, just not exposed via the managed class), so you need to invert the duty cycle.


Thanks so much - another "revelation" in my practical understanding of circuits - if the voltage is the same on both leads (+/-) no current flows - I know it's probably elementary to everyone else but I just never thought of it that way. This is going to be so much fun!

#6 LuluPutty

LuluPutty

    New Member

  • Members
  • Pip
  • 1 posts

Posted 20 April 2012 - 06:00 AM

I want to make some LED candles with these and mix them in with the pvc kind. I can't wait to melt some hot glue on the container and see how well the votive still shines through. The tube is rather pliable and I am curious to see if the hot glue melts it a bit.

#7 blairh

blairh

    New Member

  • Members
  • Pip
  • 1 posts

Posted 18 July 2012 - 02:46 AM

I just wanted to thank the participants of this thread - I just acquired some rgb LEDs and had been wrestling a bit with the example in Getting Started with Netduino. I did at least reach the conclusion that the common cathode vs. common anode was the problem, but I had no idea what to do about it. Thanks again! (I've got my Netduino successfully cycling through a "mood light" pattern in celebration of it working!)

#8 SirFatty

SirFatty

    Member

  • Members
  • PipPip
  • 11 posts

Posted 12 February 2013 - 02:36 AM

Just wanted to add a "me too" to the list.  Thanks for the info, just needed to jumpstart the brain.



#9 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 12 February 2013 - 07:39 AM

in the netmf pwm class you can set an invert boolean in the constructor, so you can use it normally, no matter if its anode or cathode.






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.