ESP32 pin 35 not stable with digitalRead?

Hello, so I've hooked up a button to pin 35 and poll its reading in a program, but I've noticed it sometimes provides the wrong value. I set up the pin as follows:

pinMode(PIN35,INPUT_PULLUP);

And I pin 35 to 3.3V with a 10k resistor, so I've pulled it up. Is there something wrong with pin 35? I've tried with 36, 39 & 34 with similar setup but there was issues. Is it something with ESP32?

Yes, the GPIO pins on portB of a ESP32 are setup differently than the GPIO pins on portA.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/index.html

Oh I see, may I have some pointers on what pin is on what port? I wasn't able to find on the link you provided

And since I've already soldered everything, is it possible to config pin 35 to pullup input by the software?

Yes it is possible to configure the pins on portB to act like port A pins by using the GPIO pins as RTC_GPIO though the ESP32's API.

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html

I tried adding that but there are some library issues, the rtc_gpio_init wasn't declared, did I write something wrong?

#include "driver/gpio.h"
rtc_gpio_init(GPIO_NUM_35);

I'm sure you'll figure it out.

Input only pins

GPIOs 34 to 39 are GPIs – input only pins. These pins don’t have internal pull-up or pull-down resistors. They can’t be used as outputs, so use these pins only as inputs:
GPIO 34
GPIO 35
GPIO 36
GPIO 39

i'm really sorry but I tried hard but I wasn't able to figure out how to deal with the esp_err_t. could you help me with the right syntax?

At this point I'd just be writing code for you, which I don't do.

BTW, does this rtc_gpio_init(GPIO_NUM_35); need to go inside a function? Did you properly declare the RTC_GPIO configuration structure?

Have you looked at the example code provided with the documentation? That's how I learned.

here is how I use the GPIO api in setup(), perhaps it will have a clue for how to setup the RTC_GPIO API.

void setup()
{
  gpio_config_t io_cfg = {}; // initialize the gpio configuration structure
  io_cfg.mode = GPIO_MODE_OUTPUT;
  io_cfg.pin_bit_mask = ( (1ULL << GPIO_NUM_0) ); //bit mask of the pins to set, assign gpio number to be configured
  gpio_config(&io_cfg);
  gpio_set_level( GPIO_NUM_0, LOW); // 
  //
  adc1_config_width(ADC_WIDTH_12Bit);
  adc1_config_channel_atten(ADC1_CHANNEL_6, ADC_ATTEN_DB_11);// using GPIO 34  
  // hardware timer 4 set for one minute alarm
  hw_timer_t * timer = NULL;
  timer = timerBegin( 3, 80, true );
  timerAttachInterrupt( timer, &onTimer, true );
  timerAlarmWrite(timer, 60000000, true);
  timerAlarmEnable(timer);
  ///
  co2Serial.begin( 9600 , SERIAL_8N1, 25, 26 ); // pin25 RX, pin26 TX
  //
  x_eData.WD.reserve(50);
  x_message.topic.reserve( payloadSize );
  //
  xQ_WindChillDewPoint = xQueueCreate( 1, sizeof(stu_eData) );
  xQ_Message  = xQueueCreate( 1, sizeof(stu_message) );
  xQ_eData    = xQueueCreate( 1, sizeof(stu_eData) ); // sends a queue copy of the structure
  //
  sema_PublishPM = xSemaphoreCreateBinary();
  xSemaphoreGive( sema_PublishPM );
  sema_mqttOK    =  xSemaphoreCreateBinary();
  xSemaphoreGive( sema_mqttOK );
  sema_CollectPressure = xSemaphoreCreateBinary();
  xSemaphoreGive( sema_CollectPressure );
  sema_eData = xSemaphoreCreateBinary();
  xSemaphoreGive ( sema_eData );
  //
  eg = xEventGroupCreate(); // get an event group handle
  //
  xTaskCreatePinnedToCore( fparseMQTT, "fparseMQTT", 7000,  NULL, 5, NULL, 1 );
  xTaskCreatePinnedToCore( MQTTkeepalive, "MQTTkeepalive", 5000, NULL, 6, NULL, 1 );
  xTaskCreatePinnedToCore( DoTheBME680Thing, "DoTheBME280Thing", 20000, NULL, 5, NULL, 1);
  xTaskCreatePinnedToCore( fmqttWatchDog, "fmqttWatchDog", 5000, NULL, 3, NULL, 1 );
  xTaskCreatePinnedToCore( fDoTheDisplayThing, "fDoTheDisplayThing", 30000, NULL, 3, NULL, 1 );
  xTaskCreatePinnedToCore( fGetCO2, "fGetCO2", 4500, NULL, 2, NULL, 1 );
  xTaskCreatePinnedToCore( fParseDewPointWindChill, "fParseDewPointWindChill", 4500, NULL, 2, NULL, 1 );
  xTaskCreatePinnedToCore( fSolarCalculations, "fSolarCalculations", 10000, NULL, 2, NULL, 1 );
  xTaskCreatePinnedToCore( fProcessAirPressure, "fProcessAirPressure", 5000, NULL, 2, NULL, 1 );
  xTaskCreatePinnedToCore( fFindDewPointWithHumidity, "fFindDewPointWithHumidity", 5000, NULL, 2, NULL, 1 );
  xTaskCreatePinnedToCore( fLowSideSwitchTest, "fLowSideSwitchTest", 2000, NULL, 5, NULL, 1 );
} //void setup()

i'm sorry but I'm really lost right now, RTC_GPIO only takes in a port number from what I read on the API, it didn't include any structure. Pin 35 is also listed as ADC1_CH7, RTC_GPIO5, GPI, so it really seems like it is a RTC GPIO...

i also wasn't able to fins anything about ESP32 has portA nor portB, so yeah

see post 7

I've seen yours, I've included that I've connected that pin to a pull-up resistor to 3.3V, the same has worked with pin 34, 36, 39. pin 35 worked after the button goes from open to close, but then it remains open after i released it, so I'm confused

If you have an external pull-up then the problem is with your code.
Please post your entire sketch using code tags.

After reading this

I suggest you try to use another pin :slightly_smiling_face:

Ok, so I might have simplified a bit, my program is quite long atm, and it's actually a water level sensor, which acts as and switch. The sensor became closed when it's in its up position, a part of my code starts up with

#define RESERVE_LOW_SENSOR 35
  const int RESERVE_LOW_ACTIVATE = HIGH;
  pinMode(RESERVE_LOW_SENSOR,INPUT_PULLUP);
int lowReserveReading = digitalRead(RESERVE_LOW_SENSOR);
  if (lowReserveReading == RESERVE_LOW_ACTIVATE){
  ....
}

There is a time when the tank is full, so the switch should be closed, the code inside the if statement still activates. I then open up the enclosure and check with the multimeter and it shows pin 35 & GND is indeed connected... (meaning the switch is closed, so LOW)

I then move the sensor up and down a bit by poking in the tank, half of the time it doesn't activate, half it does, so I'm confused...

I have a suspicion it was my connection, but I triple-checked it and it is still unstable...

Which post in that thread lead you to that conclusion?

Change it to:

pinMode(RESERVE_LOW_SENSOR,INPUT);

that didn't work... also i accidentally shorted the circuit while poking around... so I can not test it for a while... I'mma throw the towel for now...

maybe I should do a proper PCB to make sure everything is actually connected and not just this flimsy prototype board...

Good idea!

Sorry you re unable to figure out how to use the RTC_GPIO API. Looks like you'll have to rethink your project.