Connecting LEDs to the sv-328 I/O ports?

Hi,
I have an Orangutan sv-328 and would like to add additional LEDs. I was thinking of using the User I/O ports. PC5…PC0 and/or possibly PD1-PD0.
I anticipate having to add a resistor to the LED as these ports puts out 5V.

Q1: Are there other considerations from a connectivity standpoint - e.g is it better to use one port type vs. the other ?

Q2: How would I control the LED (turn on/off) with software ?
I found the following in the Pololu digital1 example section:
Assuming I want to use PC1 port.

Is it as simple as this ?

 set_digital_output(IO_C1, HIGH);   // to turn PC1 port  on
 set_digital_output(IO_C1, LOW);   // to turn PC1 port  off

I appreciate any help or feedback.
Thanks!
John

I don’t know of any reasons why one output pin on the ATmega328 would be better than another for driving LEDs. They should all work for you. Just remember that the maximum current per I/O pin (according to Table 28.1 in the datasheet) is 40.0 mA, so your resistor value and diode voltage need to be set so they won’t draw more than that amount of current. A 1 kilo-ohm resistor would be a safe choice, allowing at most 5 mA to come out of the pin.

Yes, it is as simple as that. But note that the second line of your code tells the AVR to actively drive the pin low, it doesn’t turn the pin “off” like your comment says. A safer way to turn off your LED is to set it as a digital input, but both ways will work.

-David

Thank you David - I appreciate the quick reply.
Regarding your comment on turning the LED off ( a bit safer )… is this what you had in mind by setting the pin to input ? Is it better to set the input High or Low or doesn’t matter ?

set_digital_input(IO_C1, LOW);     //turns LED off by switching the port to a digital input

                                                 // and then to turn it back on set the port to digital output 
set_digital_output(IO_C1, HIGH);  // turns LED on

Thanks,
John

You code is almost correct, but LOW is not a valid value for the second parameter of set_digital_input. It should either be HIGH_IMPEDANCE or PULL_UP_ENABLED. You can read about those options in the Orangutan Digital I/O section of the Pololu AVR C/C++ Library Command Reference.

In general, whenever you are trying to decide what parameters to supply to a library function, you should read the command reference.

I recommend doing HIGH_IMPEDANCE because you don’t need a pull-up resistor on that pin, so enabling the pull-up resistor would just be a (small) waste of power.

-David

Thanks again David.
I appreciate the recommendation as sometimes when I read the command reference I don’t fully understand the implications of some of the settings due to my lack of hardware knowledge.
Happy Holidays.