ESP32 All but pin 2 INPUT_PULLUP are showing high

I'm trying to figure out which of the pins have an internal pull-up. What I'm reading online and what I'm experiencing isn't matching up.

Then I tried to just print the values for all the ones that supposedly can be configured for INPUT_PULLUP.

void setup() {
  Serial.begin(115200);
  pinMode(2, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(25, INPUT_PULLUP);
  pinMode(26, INPUT_PULLUP);
}

void loop() {
  Serial.println("2: " + String(digitalRead(2)));
  Serial.println("4: " + String(digitalRead(4)));
  Serial.println("15: " + String(digitalRead(15)));
  Serial.println("5: " + String(digitalRead(5)));
  Serial.println("18: " + String(digitalRead(18)));
  Serial.println("13: " + String(digitalRead(13)));
  Serial.println("14: " + String(digitalRead(14)));
  Serial.println("25: " + String(digitalRead(25)));
  Serial.println("26: " + String(digitalRead(26)));
  delay(1000);
}

When I run this, ONLY pin 2 is 0. Everything else is 1. And only pin 2 reacts to a button push. Why, if they are configured for INPUT_PULLUP are they all reading HIGH when no wires are connected?

Thanks!

I'm confused. Absent any external circuitry, what else would you expect inputs configured as INPUT_PULLUP to read as other than high?

1 Like

I expect it is working properly. Unfortunately, there are several variations of many modules, and yours is one of them. This is one of the reasons why we ask for links to technical information.

This is the unit I have https://amazon.com/gp/product/B08D5ZD528/ref=ppx_yo_dt_b_asin_title_o06_s00?ie=UTF8&psc=1

I suppose I would expect them to at least be consistent. I thought when you configured the pin with an INPUT_PULLUP that it was default LOW.

Either way, I can't get any but pin 2 internal pullups to work. I have these 2 wire buttons, 1 wire to ground and 1 wire to the pin. On Pin2, I can see the digitalRead value changing. But none of the other pins show any change at all.

That would indicate to me that only pin2 has an internal pull-up, but I thought many more pins were supposed to have that.

INPUT_PULLUP, in the absence of any other external signal, pulls the input high. It pulls it up. I would assume that pin 2 has something pulling it down harder than the relatively week pullup that INPUT_PULLUP enables.

Edit: and there it is, right in the schematic. A 2.4K resistor and LED to ground. That's why GPIO2 (D9) reads as low.

2 Likes

Apologies, when I said "Pin2" I meant D2 on the board.

I guess I'll sort of solve my own, for some reason now, They all work fine except for D2. I tested D4, D5, D13, D14, D12, D22, D23 they all worked as expected this time. Just D2 is always LOW even when set to INPUT_PULLUP.

Try writing a HIGH signal to D2; I believe the LED will light up. The LED is likely acting as a pull-down through a 2.4K resistor, allowing it to complete the circuit when D2 is set HIGH.
@van_der_decken is correct.

Your sketch never references D2, only the bald constant 2, which is a GPIO number. In my (admittedly limited where ESP32s are concerned) experience, ESP32 Dx numbers do not usually equal GPIOx numbers. What board do you have selected?

@van_der_decken I have the ESP32 Dev Module selected. So far every DX number has correlated directly to the GPIO number. The data schematic for this board also shows the GPIO numbers are the same as the D numbers for the pins in the sketch. I have been checking them though to make sure.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.