0
Offline
Faraday Member
Karma: 16
Posts: 3196
20 LEDs are enough
|
 |
« on: August 24, 2009, 12:05:39 am » |
As it was discussed here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1243213127 floating input pins are a bad idea. However most users seem to be unaware of this fact. I would like to suggest that by default input pins should be pulled to high. Of course this has some implication for applications that rely on not being pulled up, so this is incompatible. On the other side the floating pins are a pain for all novice and unaware users. In my opinion the floating pins cause more harm than one would expect so this should be fixed. Cheers, Udo
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15320
Measurement changes behavior
|
 |
« Reply #1 on: August 24, 2009, 01:24:23 am » |
Not sure I agree with your assessment. Floating inputs are only a problem if you are using them. If unused in the program, they cause no harm, but possibly raise current consumption by some micro-watts, maybe.
Lefty
|
|
|
|
« Last Edit: August 24, 2009, 01:24:52 am by retrolefty »
|
Logged
|
|
|
|
|
massachusetts
Offline
Newbie
Karma: 0
Posts: 17
|
 |
« Reply #2 on: September 10, 2009, 09:45:20 pm » |
i don't know about that, udo. i'm trying firmata for the first time and floating pins seem to be wreaking havoc. the example i'm using is watching the state of all of the pins all of the time, and they're constantly changing whenever i touch the board.
rob
|
|
|
|
|
Logged
|
|
|
|
|
Toronto, ON
Offline
Full Member
Karma: 9
Posts: 233
|
 |
« Reply #3 on: September 11, 2009, 10:37:11 pm » |
FWIW, Atmel recommends: 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 pullup. In this case, the pullup will be disabled during reset. If low power consumption during reset is important, it is recommended to use an external pullup or pulldown. 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. b
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10181
|
 |
« Reply #4 on: September 18, 2009, 10:51:32 pm » |
If a pin is wired to be an output, wouldn't enabling the pullup be almost the same as turning the pin high? Wouldn't 5v be present on the pin when the pullup is enabled?
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15320
Measurement changes behavior
|
 |
« Reply #5 on: September 18, 2009, 11:03:49 pm » |
If a pin is wired to be an output, wouldn't enabling the pullup be almost the same as turning the pin high? Yes, if a pin is programmed (not wired) to be an output pin then the concept of pull-up is not applicable. The pin will either be high or low depending of the state of the pin's data output register, even if there is nothing wired to the pin. The same register used to hold pin output data is used to enable pull-ups if the pin is programmed to be an input pin. Pull-ups or pull-down is an input pin conditioning thing to ensure that there is a predefined voltage level applied to the pin to give it a predictable high or low voltage level. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10181
|
 |
« Reply #6 on: September 18, 2009, 11:15:41 pm » |
In that case, is defaulting pins to have the internal pullups enabled a good idea?
I apologize if I'm beating a dead horse, but I want to make certain I understand.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15320
Measurement changes behavior
|
 |
« Reply #7 on: September 18, 2009, 11:47:32 pm » |
Well that's kind of a personal choice kind of thing. Posted in this thread is an Atmel recommendation to enable internal pullups on unused input pins. Although the reasons stated have more to do with battery power and sleep mode benefits.
Bottom line? I've read over hundreds of sketches in this form and at least as many in the Arduino web site. I don't EVER recall seeing a sketch where they have enabled pull-ups on UNUSED input pins.
So I don't do it, but certainly don't recommend not doing it, it's really your choice. It doesn't add much overhead as it can be done just once in the setup code. And if you were to use direct port access coding you could do all unused pins in just a few lines of code.
Lefty
|
|
|
|
« Last Edit: September 18, 2009, 11:48:03 pm by retrolefty »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10181
|
 |
« Reply #8 on: September 19, 2009, 01:19:06 am » |
I think we're talking past each other. Let me try rephrasing...
In that case, is having the Arduino startup code default pins to have the internal pullups enabled a good idea? In other words, is Udo's idea a good idea?
Assuming I understand, it sounds as though the idea is not good. That a device connected to a pin could "accidentally" be turned on by the startup code turning on the internal pullups. If this is the case, it would not only be a bad idea but it would create a potentially dangerous situation.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15320
Measurement changes behavior
|
 |
« Reply #9 on: September 19, 2009, 01:36:06 am » |
I think we're talking past each other. I have nothing else or new to add, sorry. It's just not a big deal in my book either way. :'( Lefty
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Faraday Member
Karma: 16
Posts: 3196
20 LEDs are enough
|
 |
« Reply #10 on: September 19, 2009, 02:29:22 am » |
I considered this again after playing around with two interconnected arduinos.
The following is what I found:
1) floating input pins will increase power consumption 2) floating input pins will show up with erratic values (no surprise)
With (1) and (2) and the datasheet, pulling up looks like a good idea.
3) Pulling up pins by default will connect the pullup resistor to the power rail, hence if the pin is pulled high from outside, then the arduino will get some power through the pullup even if the arduino is not directly connected with power. This in turn may lead to unexpected behavior as well.
Considering (1), (2), (3) I think my initial suggestion will just shift the issues around instead of solving all of them. Hence a change to the libraties is probably not such a good idea. However I think the issue should be documented somewhere.
Cheers, Udo
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 3
Posts: 985
Arduino rocks
|
 |
« Reply #11 on: September 19, 2009, 02:37:49 am » |
Wen using digital outputs to drive external circuitry (e.g. a transistor power switch, on/off motor controller, etc.) we typically need to add an external pull-down resistor to make sure whatever is connected remains idle/safe during power on, reset or whenever our software is not in control.
If the Arduino core was modified to force the level opposite of what my design dictates (pull-up as suggested here), this would be undesired. Leaving defaults as is (floating) gives me the option to force logic level either way without conflict.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Online
Brattain Member
Karma: 279
Posts: 15320
Measurement changes behavior
|
 |
« Reply #12 on: September 19, 2009, 10:19:27 am » |
Wen using digital outputs to drive external circuitry (e.g. a transistor power switch, on/off motor controller, etc.) we typically need to add an external pull-down resistor to make sure whatever is connected remains idle/safe during power on, reset or whenever our software is not in control.
A very good point. Especially when the Arduino output pin is directly driving a logic level N channel MOSFET to switch a high current and/or high voltage load. If there is not a external pull-down resistor on the MOSFET gate to ground then there is a good chance that whatever load the MOSFET is switching will turn on erratically if the Arduino is powered off or reset or during a new upload. The resistor is better placed directly at the MOSFET location rather then at the Arduino output pin. Lefty
|
|
|
|
« Last Edit: September 19, 2009, 10:20:31 am by retrolefty »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 120
Posts: 10181
|
 |
« Reply #13 on: September 19, 2009, 01:13:36 pm » |
BenF: Thanks for the post. That's what I was trying to say but obviously didn't do to well! I'm glad you were able to communicate the potential problem.
|
|
|
|
|
Logged
|
|
|
|
|
|