Hello,
I have a pair of ESP32-WROOM-32 chips, both are doing the same thing.
I am attempting to use interrupts to detect a button press.
I started with some pretty clean code from LastMinuteEngineers, a straight copy and paste. (Configuring & Handling ESP32 GPIO Interrupts In Arduino IDE)
But I have a problem. As soon as I connect any wire to the interrupt pin, the interrupt fires, constantly. Hundreds of times in a few seconds. To be clear, this is just a floating jumper wire. I tried on both chips and on a few different pins (modifying the code accordingly) and it keeps happening.
Leave nothing connected to the pin, no problem, connect a jumper lead, instant, constant interrupts.
Tried with the chip removed from the prototype board, tried a chip with no pins.
I tried pulling the pin up with an external resistor, but when I do that the interrupt does not fire when I pull the pin down by grounding it.
Can anyone help me figure out what I am doing wrong?
Here is the code from Lastminute, I have also written a couple of versions from scratch, using other sites, all do the same thing.
struct Button {
const uint8_t PIN;
volatile uint32_t numberKeyPresses;
volatile bool pressed;
};
Button button1 = { 18, 0, false };
void IRAM_ATTR isr() {
button1.numberKeyPresses++;
button1.pressed = true;
}
void setup() {
Serial.begin(115200);
pinMode(button1.PIN, INPUT_PULLUP);
attachInterrupt(button1.PIN, isr, FALLING);
}
void loop() {
if (button1.pressed) {
Serial.printf("Button has been pressed %u times\n", button1.numberKeyPresses);
button1.pressed = false;
}
}