Internal pull-up resistor?[SOLVED]

Hi,

Is it possible to add an internal pull-up resistor to one of the digital pins when it is defined as input?
I know in Arduino it is possible by doing a digitalWrite(pin#,HIGH);

Thanks,
Henk

yes, see the pinMode() function:

pinMode() takes two arguments, pin: the number of the pin whose mode you wish to set and mode: INPUT, INPUT_PULLUP, INPUT_PULLDOWN or OUTPUT.

(NB: in newer versions of the arduino SDK using digitalWrite() on input is deprecated, you can use pinMode(pin, INPUT_PULLUP) instead.)

3 Likes

Great, it works.

Thanks,
Henk

1 Like

What is the value of the pull-up? With the Arduino I believe it’s 20K…

@whyameye, are you referring to core or photon?

This should be a good reference: http://docs.particle.io/photon/hardware/#4-4-i-o-characteristics

Hello everybody

I try to read analog value with the sparkcore but I can not get the zero value when nothing it’s connected.

My code is very simple :

#include "application.h"

int value;
void setup()
{
     pinMode(A0, INPUT_PULLDOWN);
     Serial.begin(9600);

     }


void loop()
{
   value=analogRead(A0);

   Serial.println(String(value));
     delay(1000);

     }

someone there an idea why it does not work ?

Thank you in advance

@Sherkann, setting the pinMode() prior to analog input has no affect since the pin is set to INPUT (floating) by the function. Reading a floating (unconnected) analog input will give you a random value due to noise on the pin. Connecting the pin to GND or 3V3 will produce zero and 4095 respectively and as expected. You can use external pull-up or pull-down resistors as required. :smiley:

1 Like

@peekay123 Thank you for your reply
I thought that an internal pulldown could be used :confused:

This is kind of related - but refers to Photon analog pin A0.

Kind of a cross check - cos I had this exact config working fine on a Core…but now after upgrading to a photon it doesn’t work. Obviously I have misunderstood something or screwed up something - but I need a sanity check.

If I want to use A0 as digital GPIO to read a push button. I set the pin up like

pinMode(A0, INPUT_PULLUP);

which should work and make that pin behave like any of the D pins yes?

If yes, I am puzzled cos my code reads A0 and waits for a LOW, then it does a debounce delay (120ms) and wait loops for A0 to go high again when the button is released. Observed behaviour is that the initial LOW is seen, but the wait loop exits immediately. Tried a different button - same thing.

Obviously I am missing something.

If the A0 pin setup is correct I am out of idea and will boil down my code to something I can post here to see if anyone can see my mistook! :slight_smile:

Thanks as ever guys!

Best regards
Alan T

Post your code so we can have a look