1
\$\begingroup\$

I'm programming a custom ESP32 board using Arduino where GPIO25 and GPIO32 are connected to pogo pins via short 5mm traces and to nothing else. The goal is to poll for a short between them as part of an alignment procedure - pretty straightforward.

The issue is, pinMode(X, INPUT_PULLUP) does not actaully turn on the pullup for either pin; the ADC readings are always floating. Whichever pin I'm using still successfully detects a short when intended, but because It is floating and never pulled high, it causes a lot of false flags. Code below:

    int foo=9999;
    pinMode(25, OUTPUT);
    pinMode(32,INPUT_PULLUP);
    while(foo>0){
        foo=analogRead(32);
        Serial.println(foo);
        //do other stuff
    }
\$\endgroup\$
2
  • \$\begingroup\$ I typed the code in here directly, that was a typo. Fixed now. I'm reading the correct ADC pin when the described problem happens \$\endgroup\$ Sep 19, 2020 at 17:29
  • \$\begingroup\$ This Reddit thread has that IDF library direct approach that may work. I'm about to try it out myself. Reddit Thread on ADC w/ internal pullup \$\endgroup\$
    – Rudy Moore
    Jul 18, 2021 at 19:38

1 Answer 1

1
\$\begingroup\$

Hi all I got to the bottom of this for anyone googling:

Using analogRead attaches the GPIO pin you're using to the ADC channel and disconnects it from the pull-up. Calling pinMode(X, INPUT_PULLUP) after every analogRead will reinstate the bias.

\$\endgroup\$
3
  • \$\begingroup\$ Would that actually cause the pullup to be active during the ADC sampling? Or does this just mean you end up relying on stray capacitance to hold the value? \$\endgroup\$ Sep 21, 2020 at 22:30
  • \$\begingroup\$ The latter it seems, which is good enough for me as a workaround. I no longer get any false positives with this method. I'd bet there's a way to achieve both using IDF library functions directly. \$\endgroup\$ Sep 22, 2020 at 2:14
  • \$\begingroup\$ If it's really capacitance making it happen, I'd be tempted to add my own capacitors. Or external resistors, unless that causes a power consumption issue... \$\endgroup\$ Sep 22, 2020 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.