Seattle, USA
Offline
Full Member
Karma: 0
Posts: 248
|
 |
« on: February 26, 2010, 08:37:08 pm » |
This has been discussed at length over on the teachers and developers lists, but I'm repeating it here just to see if folks not following those discussions might want to add their thoughts.
The issue is that the Arduino board provides internal pullup resistors on I/O pins that can be enabled instead of having to wire one in on a circuit. But to enable this capability, you must issue a digitalWrite command on the pin.
This is, at best, very obscure and counter-intuitive to the novice who might be struggling to even understand the concept of a pullup resistor. And, at worst, it can cause execution problems, which I can not even tease out of my own memory, that are very difficult to debug.
So, this is a vote for taking the opportunity of a good conceptual cleanup on that for uno punto zero.
.andy
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15316
Measurement changes behavior
|
 |
« Reply #1 on: February 26, 2010, 10:04:09 pm » |
Sure. Maybe have a core function called enablePullup(pin). If would have to be smart enough to not do anything if the pin's mode is already set as an output pin, or state that it also changes or defines the pin as an input as well as set the pull-up. I guess you would need a disablePullup(pin), or maybe pullUp(pin,state).
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Mobile, AL
Offline
Sr. Member
Karma: 0
Posts: 314
CAUTION!-Slow Learner
|
 |
« Reply #2 on: February 27, 2010, 12:10:57 am » |
Unless it causes a problem with the pullup resistors set, just have the IDE by default set ALL digital pullups. By defining a pin as a INPUT or OUTPUT would it become active without having to write anything else.
"IF" doing so can cause execution problems, then maybe we should leave as is? Sure would save several lines of code just to define as INPUT, then digitalWrite (HIGH) for every unused pin.
Ken H>
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 230
Arduino rocks
|
 |
« Reply #3 on: February 27, 2010, 05:14:49 am » |
Automatic inclusion of pullups would not be good. There are too many cases where one would not want them.
Why not simply add another mode parameter option to pinMode -- e.g. pinMode(pin, PULLUPINPUT) or such?
It would only take a #define for "PULLUPINPUT" and a simple change in pinMode() in wiring_digital.c to do the digitalWrite to connect the pullup.
That wouldn't break anything and would be easy to add to the documentation. A few words and maybe a simple illustration could (should) also be put in the documentation to explain the pullup concept to novices.
|
|
|
|
« Last Edit: February 27, 2010, 05:16:41 am by RoyK »
|
Logged
|
|
|
|
|
SE USA
Offline
Faraday Member
Karma: 33
Posts: 3621
@ssh0le
|
 |
« Reply #4 on: February 27, 2010, 01:45:29 pm » |
Automatic inclusion of pullups would not be good. There are too many cases where one would not want them. agreed
|
|
|
|
|
Logged
|
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 11
Arduino rocks
|
 |
« Reply #5 on: March 03, 2010, 07:49:37 am » |
yeah - don't enable pullups by default, please! I have a lot of carrier boards that might do bad things to an arduino if that happened...
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
God Member
Karma: 0
Posts: 710
Arduino is Genius
|
 |
« Reply #6 on: March 11, 2010, 09:48:39 pm » |
Agree. I teach children and beginers using Arduino's, and I would like to introduce people to using the internal pull-up resistors early on, soon after digitalWrite.
I sometimes get a smart a$$ who starts in with "processor X has pull-up resistors built in, why doesn't an Arduino ...", and the opaqueness of the current mechanism is not helpful.
pullUpResistor(pin, ON) pullUpResistor(pin, OFF) would be fine, rather than enablePullUp(pin), disablePullUp(pin) I don't want pullUps enabled by default as things will break. Also, if pull-ups are enabled by default, I don't get the errors which give me a chance to explain that switches (floating inputs) need to be pulled to +V or Ground, which seems to be a handy thing to understand, and I lose the chance to talk about pull-down inputs, which people sometimes see in projects, and which seem more logical.
|
|
|
|
« Last Edit: March 11, 2010, 09:52:33 pm by gbulmer »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10158
|
 |
« Reply #7 on: March 20, 2010, 02:57:05 am » |
I like the way it's done with the Teensy. pinMode has a third option: INPUT_PULLUP.
|
|
|
|
|
Logged
|
|
|
|
|
Forum Administrator
Cambridge, MA
Offline
Faraday Member
Karma: 7
Posts: 3532
|
 |
« Reply #8 on: March 20, 2010, 07:32:38 am » |
What do you think of something like: pinMode(9, INPUT, true); to enable pull-up resistors, pinMode(9, INPUT, false); to make sure they're disabled, and: pinMode(9, INPUT); which would leave the pull-up resistor unaffected?
Something about INPUT_PULLUP just seems a bit clunky.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, USA
Offline
Full Member
Karma: 0
Posts: 248
|
 |
« Reply #9 on: March 20, 2010, 09:03:32 am » |
I like it!
.andy
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #10 on: March 20, 2010, 10:09:52 am » |
me 2 Will like it twice as much if we can set the option for outputs als :)o
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #11 on: March 21, 2010, 02:35:45 am » |
The benefit of pinMode(9,INPUT_PULLUP) is that its more obvious what the code does than pinMode(9, INPUT, true); If the user was not familiar with pulls-ups than context sensitive help on INPUT_PULLUP would get him relevant information.
Or, if you prefer the three argument version, you could define PULLUP as true and use: pinMode(9, INPUT, PULLUP)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 118
Posts: 10158
|
 |
« Reply #12 on: March 21, 2010, 02:53:51 am » |
I agree with mem. The way I see it, digital pins really do have three "modes": input, output, and input w/ pullup.
The alternative is more versatile but, if the versatility is really that important, why not add a new function that allows the two operations to be arbitrarily combined. "pinControl" seems like a good name for such a function.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 22
Arduino rocks
|
 |
« Reply #13 on: March 21, 2010, 09:14:45 am » |
The benefit of pinMode(9,INPUT_PULLUP) is that its more obvious what the code does than pinMode(9, INPUT, true); If the user was not familiar with pulls-ups than context sensitive help on INPUT_PULLUP would get him relevant information.
Or, if you prefer the three argument version, you could define PULLUP as true and use: pinMode(9, INPUT, PULLUP) I like the three element, method best, it is more consistant with previous code) If we #DEFINE PULLUP 1 every one can have it their way. Personally I like rembering TRUE and FALSE best another variable has more charactors to potentially mistype and screw up the case with. I agree with mem. The way I see it, digital pins really do have three "modes": input, output, and input w/ pullup.
The alternative is more versatile but, if the versatility is really that important, why not add a new function that allows the two operations to be arbitrarily combined. "pinControl" seems like a good name for such a function. There are more than 3 modes. Pins can be defined as output can benefit from a pullups too.
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #14 on: March 21, 2010, 09:44:15 am » |
it is more consistent with previous code Hi Ray, could you clarify what previous code the three element version is consistent with? Pins can be defined as output can benefit from a pullups too. Pull-ups can only be enabled on inputs. Because of the way internal pull-ups are implemented on the controller chip, an output pin whose value is low cannot have pull-ups enabled.
|
|
|
|
|
Logged
|
|
|
|
|
|