Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
earnestblimp
 
Posts: 19
Joined: Thu Sep 17, 2009 10:42 am

Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by earnestblimp »

Hi,
This seems like a pretty basic question, but I've searched the forums and haven't found a concrete answer. Perhaps I've used the wrong search terms.

I would just like to know if unused pins on an atmel chip with the arduino bootloader should be marked as outputs or inputs with pull-ups enabled? The Arduino DigitalPins document talks about this but doesn't say anything definitive one way or the other.

Should every sketch do this? I am working in an electrically noisy environment, and figured I should do one of these, but wasn't sure which was the preferred method in terms of power draw, stability, etc. Thanks!

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by mtbf0 »

i believe you want to set them as inputs without pullups. this is easy to do as it's the state things are in when the chip powers up. the pullups source a wee little bit of current.

User avatar
earnestblimp
 
Posts: 19
Joined: Thu Sep 17, 2009 10:42 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by earnestblimp »

i believe you want to set them as inputs without pullups. this is easy to do as it's the state things are in when the chip powers up. the pullups source a wee little bit of current.
Thanks for your response, but wouldn't this just be putting them in a high impedance state where they could act like little antennas and possibly introduce errors on neighboring pins? My understanding was that at least the pull-ups allowed a small amount of current to flow, which helped reduce this. I was hoping that you could go one better by marking them as outputs, because maybe then you'd get the benefits without any current draw, at least that was the thinking. But I don't know enough about what's happening when the pins are marked as outputs to really know for sure. Thanks

User avatar
jchristensen
 
Posts: 111
Joined: Mon Jan 03, 2011 11:45 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by jchristensen »

The Atmel datasheet says the following.
13.2.6 Unconnected Pins
If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are disabled in the deep sleep modes as described above, floating inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle mode).
The simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. In this case, the pull-up will be disabled during reset. If low power consumption during reset is important, it is recommended to use an external pull-up or pull-down. Connecting unused pins directly to VCC or GND is not recommended, since this may cause excessive currents if the pin is accidentally configured as an output.

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by mtbf0 »

shows you what i know. ever so sorry for the lousy advice. will go sit in the shed and reconsider my existence.

User avatar
jchristensen
 
Posts: 111
Joined: Mon Jan 03, 2011 11:45 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by jchristensen »

Awww, now don't do that. I only knew because I happened to be reading the datasheet recently. How sad is that. "Reads datasheets for enjoyment." :lol: Probably for a lot of folks like me who are mostly messing around with Arduinos only half-seriously and have them plugged into the wall, it doesn't make a whit of difference.

It is an interesting area, though. The ATmega328P (the P is for "picoPower") has several design features to help minimize power consumption. Various parts of the MCU can be turned off when not needed. See the descriptions for the Power Reduction Register (PRR) and the MCU Control Register (MCUCR).

Happy Friday!

User avatar
earnestblimp
 
Posts: 19
Joined: Thu Sep 17, 2009 10:42 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by earnestblimp »

Thanks, I should have looked more closely. So that sounds like the recommended way to prevent the floating pins. If anyone knows how this method compares to marking them as outputs though, I'd love to hear about it. I can check to see if it uses less power than the input/pull-up method, I just don't know if it has the same effect or not.

In other words, you always hear that leaving CMOS output pins unconnected is not a problem, it's the inputs you have to worry about. I just didn't know if there was any difference between traditional hardwired outputs like those vs. programming a pin to be in output mode like on the atmega chip. Thanks!

User avatar
jchristensen
 
Posts: 111
Joined: Mon Jan 03, 2011 11:45 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by jchristensen »

I would suspect, and this is sheer speculation on my part, that it's more about power consumption than noise immunity. I'd suspect noise immunity to be about the same for an output vs. an input with a pullup. But perhaps configuring an output pin uses a little more current internally. The difference could be quite small. Like you say, it should be able to be measured, but to see the difference it may take enabling some of the power reduction options and/or sleep modes. If you're not terribly concerned about power consumption, it might be six and a half of one and a dozen of the other :wink:

Being CMOS, the impedance of an input pin should be very high, so the current through the pullup should be exceedingly small. I believe input pins are basically tri-stated, but I can't find a spec for input impedance in the datasheet.

User avatar
earnestblimp
 
Posts: 19
Joined: Thu Sep 17, 2009 10:42 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by earnestblimp »

Thanks all for the responses. I should probably just stick with pull-ups (at least until I'm fully potty trained).

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by floresta »

Thanks all for the responses. I should probably just stick with pull-ups (at least until I'm fully potty trained).
I would just stick with the default values and not mess with any I/O pin settings for pins that I am not using. This is essentially what 'mtbf0' recommended in the very first reply.

Don

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by floresta »

I believe input pins are basically tri-stated,...
This is not the correct terminology to use (although it will probably be correctly interpreted) since the term 'tri-state' really refers to outputs.

Don

oldELECTROguy
 
Posts: 34
Joined: Tue Apr 19, 2011 1:24 pm

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by oldELECTROguy »

pins should always be kept in a logic high state...like a door...keep in closed(logic 1) ESD has a hard time getting in, door open(logic 0)..ESD will find you...i keep all my unused micro's in this state...its some protection for the dreaded ESD...Hello, everybody, I'm new here...been hacking since 1966

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by floresta »

pins should always be kept in a logic high state...like a door...keep in closed
That's just not true. Why do you suppose that the default condition at reset is for all I/O pins to be configured as input pins? It's not just the Atmel chips that are configured this way.

Don

oldELECTROguy
 
Posts: 34
Joined: Tue Apr 19, 2011 1:24 pm

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by oldELECTROguy »

your right...it works on other chips, just not amtel chips...i am really new at this

User avatar
floresta
 
Posts: 223
Joined: Thu Jul 31, 2008 10:27 am

Re: Should Arduino Unused Pins Be Made Outputs Or Inputs With Pull-Ups Enabled?

Post by floresta »

.it works on other chips, just not amtel chips...
???? As far as I know they all are configured the same way, Atmel included, I/O pins are configured as input by default.

Let's say that you have some microprocessor controlled detonators, and you have two varieties. One type is triggered by an active low signal and the other type is triggered by an active high signal. If the I/O were NOT initially configured for input which one would you want connected to your microprocessor as it was coming out of reset, before your program started to run?

Don

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”