internal pull up resistor?

This has probably been asked quite a lot, but i could not find the specifics anywhere else: how does one enable the internal pull up resistor on a pin through software? an example would be nice

pinMode( pin, INPUT_PULLUP );
  • Brian

pinMode( pin, INPUT_PULLUP ); Nope. INPUT_PULLUP isn't defined anywhere.

From the page git mentioned:

pinMode(pin, INPUT);           // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors

wait, setting the pin to high is turning on its pull up resistor? really? oh, i must have sounded stupid with my question... i had no idea that was the same thing... makes sense now tho...

No not stupid, The internal pull-up function it not an intutive feature, almost like AVR folks discovered it by accident. Note also the there is NOT a complementary soft pull-down function if a 0 is written to a digital input. :wink:

Lefty

btw, the internal resistors are pull-up only. So doing:

pinMode(pin, INPUT);      
digitalWrite(pin, LOW);

will not do anything for you.

Nope. INPUT_PULLUP isn't defined anywhere.

It is for me. :wink: Sorry about that. I didn't realize it wasn't part of the standard Arduino stuff.

  • Brian

It is for me. Sorry about that. I didn't realize it wasn't part of the standard Arduino stuff.

  • Brian

How's that work? It takes two steps to turn on the pullup; set mode to input, and then set it high to enable the pullup.

Your single command confuses me. :slight_smile:

How's that work?

I'm currently working with a not-quite-an-Arduino board. It supports the simplified function call. I didn't realize the simplified call wasn't part of the standard Arduino library. It's a little feature the board creator added to the libraries.

I do apologize for the confusion.

  • Brian

wats the board?

They're called a Teensy...

http://www.pjrc.com/teensy/

I have a few of each kind and I've been very pleased with them.

  • Brian

How's that work? It takes two steps to turn on the pullup; set mode to input, and then set it high to enable the pullup.

Your single command confuses me.

digital pins are inputs by default, so unless a pin has been explicitly set to an output, writing a HIGH value will turn on pull-ups

If these internal pullup resistors are there, why do so many circuits include their own pullup resistors? Can you set the pin as INPUT and HIGH, and still read the pin LOW when something less than 20K ohms pulls it low? Is a 10K pullup just more reliable?

External pull-up resistors are somethimes sized to be able to supply a certain current requirement of what it is wire to. The internal pullup may not be able to supply enough current to function correctly. However for just supplying contact current for simple switches the internal pullups are just fine.

Lefty

digital pins are inputs by default, so unless a pin has been explicitly set to an output, writing a HIGH value will turn on pull-ups

Right, but Brian's code enables the pull-up in pinMode(), not with digitalWrite():

pinMode( pin, INPUT_PULLUP );

Which isn't writing a value to the pin, it's presumably setting the mode to input and writing a HIGH value. That's what intrigued me.

Obviously, the Teensy does things differently so it works for him but not for Arduino. I think that syntax is nice, maybe even a little more intuitive. Writing to an input is clever but not necessarily obvious.

I am not sure what Brian was thinking but that is not the way to turn on pull-ups using the standard Arduino software.

The purpose of pinMode is to set a pin to input or output mode, not to turn on or off pull-ups.

Brian, did you actually try that code?

I am not sure what Brian was thinking but that is not the way to turn on pull-ups using the standard Arduino software.

I know that now. When I wrote that reply I hadn't realized the simplified call was not part of the Arduino.

Brian, did you actually try that code?

Yup. It does what you'd expect. The Teensy creator enhanced wiring_digital.c to support the simplified call. And I like it!

  • Brian

Hi Brian,
That illustrates a big problem with modifying the core software. Code you write that uses the modified behavior will not work the same for anyone else. If like many here you find sharing advice and code is part of the fun, you may want to think twice about tinkering with the core.

Hi, Paul here... creator of the Teensy and the one responsible for adding the INPUT_PULLUP option in pinMode().

When I added this, I posted the idea and my code to the Arduino developer mail list. Several people discussed the idea, and ultimately it was rejected for inclusion into the official Arduino core. The Arduino team seemed to feel adding a third option unnecessarily complicated using the pinMode() function, and there was resistance to promoting "active low" logic because the concept of "0 means active, 1 means inactive" can be difficult for novices.

I have added "The INPUT_PULLUP option is a Teensy extension which is not present on the official Arduino" to the web page where this option is documented.

http://www.pjrc.com/teensy/td_digital.html

It's really a very simple extension that could very easily be added to the official Arduino core if they wanted it. I would be happy to prepare a patch.