# ESP32 - Analog read pin 33 affects interrupt on pin 36?

**URL:** <https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342>\
**Category:** Programming\
**Created:** [June 7, 2023, 5:28am UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342 "2023-06-07T05:28:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 7, 2023, 5:28am UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/1 "2023-06-07T05:28:19Z")

</div>

In the ESP32 design, pin 36 is connected to a push button and configured as input (that's all it can be anyway). and used to trigger interrupts. This is working well.

I just started to use pin 33 as an analog input, to read from a potentiometer, using AnalogRead command. This is working well, tested standalone.

When tested with the main software, it seems that AnalogRead of pin 33 is triggering an interrupt on pin 36.  
When the AnalogRead of pin 33 is disabled, the problem stops. Is there a reason for that?

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [June 7, 2023, 12:05pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/2 "2023-06-07T12:05:42Z")

</div>

Typically the pins on portB, GPIO\_NUM \> 32, are configured for analog readings and not for regular digital I/O.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [June 7, 2023, 12:09pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/3 "2023-06-07T12:09:46Z")

</div>

Post your sketch, please.

---

<div class="post-metadata">

**Author:** ![zm476](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/zm476/32/923016_2.png) [@zm476](https://forum.arduino.cc/u/zm476)\
**Post date:** [June 7, 2023, 12:24pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/4 "2023-06-07T12:24:59Z")

</div>

It has to be put into an anolog read pin for it to get adigital input

---

<div class="post-metadata">

**Author:** ![zm476](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/zm476/32/923016_2.png) [@zm476](https://forum.arduino.cc/u/zm476)\
**Post date:** [June 7, 2023, 12:26pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/5 "2023-06-07T12:26:16Z")

</div>

Also you should put this into the hardware problems not programming problems to keep the forum organized

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 7, 2023, 12:41pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/6 "2023-06-07T12:41:56Z")

</div>

I was not sure if this is a hardware problem or software

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 7, 2023, 12:44pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/7 "2023-06-07T12:44:03Z")

</div>

> [@zm476](#):
>
> It has to be put into an anolog read pin for it to get adigital input

I am not sure I understand. GPIO 36 is defined as an input pullup digital input. GPIO33 is simply used as an AnalogRead.

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 7, 2023, 12:46pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/8 "2023-06-07T12:46:32Z")

</div>

> [@Idahowalker](#):
>
> Typically the pins on portB, GPIO\_NUM \> 32, are configured for analog readings and not for regular digital I/O.

Are you sure? As far as I know these pins can be used as input only, without restriction on digital usage. As I mentioned, they work just fine, as long as I don't use them together.

---

<div class="post-metadata">

**Author:** ![Geek\_Emeritus](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/geek_emeritus/32/238995_2.png) [@Geek\_Emeritus](https://forum.arduino.cc/u/Geek_Emeritus)\
**Post date:** [June 7, 2023, 2:10pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/9 "2023-06-07T14:10:49Z")

</div>

the go to source for ESP32 pins:

> **[ESP32 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials](https://randomnerdtutorials.com/esp32-pinout-reference-gpios/)**
>
> The ESP32 comes with 48 GPIOs with multiple functions. This article intends to be a simple and easy to follow reference guide for the ESP32 GPIOs.

the relevant part:

### 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

if you want input pullup you must supply it yourself

if you digitalRead() them they are digital. if you analog Read  
() them they are analog

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 7, 2023, 3:33pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/10 "2023-06-07T15:33:11Z")

</div>

> [@Geek\_Emeritus](#):
>
> if you want input pullup you must supply it yourself
> 
> if you digitalRead() them they are digital. if you analog Read  
> () them they are analog

I use external pull up resistor with GPIO 36, as input. So it is as written. GPIO36 is not really being read with DigitalRead - it is used to trigger an interrupt, which works well, as long as GPIO 33 is not AnalogRead.

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 7, 2023, 4:52pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/11 "2023-06-07T16:52:00Z")

</div>

> [@GolamMostafa](#):
>
> Post your sketch, please.

```arduino
#include <Arduino.h>

#define button_stop_pin 36
#define potsmtr_pin 33

volatile bool stop_pressed = false;

int num_end_pressed = 0;

void IRAM_ATTR Button_stop_isr() {
  detachInterrupt(button_stop_pin);
  stop_pressed = true;
} // end of ISR

void setup() {
  Serial.begin(9600);
  Wire.begin(); // init I2C bus as a master 
  Serial.println("..starting SETUP....");

  pinMode(button_stop_pin, INPUT);
   
  attachInterrupt(digitalPinToInterrupt(button_stop_pin), Button_stop_isr, RISING);

  Serial.println("..End of SETUP");
} // of SETUP()  

void handle_buttons(); // the function is declared at the bottom after the loop

void loop() {
  
  Serial.println(" ");
  int speed_knob_val = analogRead(potsmtr_pin); 
  
  Serial.print(speed_knob_val);
  //return;

  if (stop_pressed ) {
    // Push buttpn event occured
    Serial.print(" Push Button event occured ");
    handle_buttons();   
  } // of if()      
} // of LOOP()

void handle_buttons() {
  Serial.print(" in START_pressed ");
  
  if (stop_pressed) {
    Serial.print(" in STOP_PRESSED ");
    stop_pressed = false;
    wait_millis(100);
    attachInterrupt(digitalPinToInterrupt(button_stop_pin), Button_stop_isr, RISING);   
  } // of if() stopped pressed

} // of handle_buttons

```

---

<div class="post-metadata">

**Author:** ![noobmastha](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noobmastha/32/738653_2.png) [@noobmastha](https://forum.arduino.cc/u/noobmastha)\
**Post date:** [June 7, 2023, 5:21pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/12 "2023-06-07T17:21:27Z")

</div>

I think that you need to declare function before setup loop.

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 7, 2023, 6:54pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/13 "2023-06-07T18:54:03Z")

</div>

Not really. It works well. The function needs to be declared before usage.

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 8, 2023, 5:47am UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/14 "2023-06-08T05:47:24Z")

</div>

Problem is solved, yet I am not sure exactly why:  
I moved the AnalogRead(33) to Core0 of the ESP32, while leaving all the main code to run on Core1. This solved the problem - interrupts on GPIO36 occur normally, while AnalogRead from GPIO33 work well.  
I assume that the CPU work for AnalogRead is not well synched when interrupts are set. Yet the 2 cores actually solved the problem.

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 8, 2023, 4:56pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/15 "2023-06-08T16:56:07Z")

</div>

I take it back - using a separated ESP32 core did NOT solve the problem. I thought so because my testing program was faulty.

Yet now the problem is really solved - the problem was with GPIO 36. Although stated it is Input only, it connected to the voltage reference of the DAC, so every AnalogRead() affected it, and caused a false interrupt. After moving the push button to another GPIO, the problem was solved.

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 9, 2023, 4:20am UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/16 "2023-06-09T04:20:14Z")

</div>

I just found out: it is a BUG, confirmed by Espressif: [https://github.com/espressif/esp-idf/commit/d890a516a1097f0a07788e203fdb1a82bb83520e](https://github.com/espressif/esp-idf/commit/d890a516a1097f0a07788e203fdb1a82bb83520e)

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [June 9, 2023, 1:16pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/17 "2023-06-09T13:16:23Z")

</div>

Does that mean that the GPIO-36 should not be used as IRQ-pin while GPIO-33 is being used as ADC line?

---

<div class="post-metadata">

**Author:** ![yigalb](https://avatars.discourse-cdn.com/v4/letter/y/34f0e0/32.png) [@yigalb](https://forum.arduino.cc/u/yigalb)\
**Post date:** [June 9, 2023, 2:02pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/18 "2023-06-09T14:02:53Z")

</div>

More than that: GPIO 36 should not be used as IRQ-pin while ANY AnalogRead is used. I checked it across GPIOs for AnalogRead. However, since Espressif identified it as a bug, it may have been fixed on later version of ESP32. I may be using old ones.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [June 9, 2023, 4:43pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/19 "2023-06-09T16:43:19Z")

</div>

There are:  
ESP32S (marked at the bottom side)/ESP32  
ESP32S2  
ES32S3  
ESP32C

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 6, 2023, 4:43pm UTC](https://forum.arduino.cc/t/esp32-analog-read-pin-33-affects-interrupt-on-pin-36/1135342/20 "2023-12-06T16:43:56Z")

</div>

Closed on December 6, 2023, 4:43pm UTC

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