Hi,
I cannot get a button press interrupt to occur when I press a button connected to my ESP32. I have it connected to P4 with a pull up resistor to 3.3V on the board. I made a little diagram to show my wiring (I used some random website without a proper ESP32 symbol so ignore the pin names in the picture). I used 22k resistor because I couldn't find any 10k. I don't think it would make a difference, but please let me know if you think it would.
The code is so simple that I have no idea where I'm going wrong. I've done button interrupts no problem on arduinos, teensy's, raspberry pi's, etc. so I like to think I know the fundamentals. But for some reason the interrupt isn't working on ESP32. I've tried on two ESP32's now and neither worked, so I think it's something wrong with my code. But I've looked at countless tutorials and my code matches with what others say to do. I've tried on different GPIO (34, 35, 32, and now 4) and that didn't help either. I tried with internal pull ups vs. external (on pin 4 only) and that did not seem to change anything.
The code I have blocked out in my loop function actually shows that the pin goes LOW when I press the button, so I'm confident in my wiring at least. But the interrupt just doesn't seem to occur. Please let me know if I'm missing something.
#define buttonPin 4
void IRAM_ATTR ISR() {
// debounce the button press
Serial.println("button");
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 200) {
Serial.println("button is pressed");
last_interrupt_time = interrupt_time;
}
}
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), ISR, LOW);
Serial.begin(115200);
delay(500);
Serial.println("Set up done");
}
void loop() {
// put your main code here, to run repeatedly:
/*
static unsigned long last_loop_time = 0;
unsigned long loop_time = millis();
if (loop_time - last_loop_time > 1000) {
Serial.println(digitalRead(buttonPin));
last_loop_time = loop_time;
} */
}
