I am developing a data logger with an ESP32 nodemcu-32s dev board using VSCode and PlatformIO, with Arduino Core.
All is going well with exception that the GPIO I’m using to trigger an interrupt on a RISING input pulse generates a continuous stream of repeat interrupts when the input stays HIGH. When it goes LOW, the interrupts cease. Here is the code that configures the GPIO:
pinMode(OutputPin1, OUTPUT); //Set Digital I/O status for OutputPin1
digitalWrite(OutputPin1, HIGH); //default output pin #1 set to 'HIGH'
pinMode(interruptPin1, INPUT); // Set Digital I/O status for interruptPin1
attachInterrupt(digitalPinToInterrupt(interruptPin1), ISR1, RISING); //Set pin 'interruptPin1' to trigger interrupt on rising edge and run 'ISR1' ISR function
OutputPin1 is used to provide HIGH voltage through a momentary button switch configured in the usual way. When the button is released, a resistor pulls the signal LOW. So the simple goal is to trigger one interrupt per button press.
What happens instead is I get a repeating series of interrupts as long as I hold the INPUT HIGH by pressing the button. When I release the button, allowing it to pull down to LOW again, the stream of interrupts stops. I’ve confirmed the input levels on a scope.
I am pretty new to ESP32 and slow to find the right documentation, but I have experimented with all the interrupt modes – RISING, FALLING, HIGH, LOW, CHANGE. This behavior is constant regardless of what mode I select in attachInterruupt(). For example, even if I specify LOW trigger, the interrupts continue to occur on HIGH (when I press and hold the button). When I release the button, the interrupts stop. So it kind of acts like the mode is HIGH, with repeating interrupts.
The code I’m using (mapped to the specific GPIOs on that MCU) works properly on Arduino MKR1010, so something is obviously different with the ESP32 specifically. I have looked through libraries and tried using the Espressif IDF #defines (e.g. GPIO_INTR_POSEDGE) , but they aren’t making any difference in the behavior.
I haven’t found the header files for ESP32 GPIO defines yet, but in VSCode I can see from hovering over the code the following:
RISING = 0x01
FALLING = 0x02
LOW = 0x0
HIGH = 0x1
CHANGE = 0x2
Question 1: Can anyone give me a clue why this might happen? Question 2: Is there a definition in ESP32 / Arduino to trigger repeating interrupts on a GPIO input level? I didn’t know this was a thing.
Thanks
Stephen
Hi.
I found some people complaining about the same issue, but I couldn’t find a proper solution. See, for example, the following discussions:
- https://www.esp32.com/viewtopic.php?f=13&t=1771
- https://esp32.com/viewtopic.php?t=12919
- https://github.com/espressif/arduino-esp32/issues/955
Do you really need to use interrupts with the buttons? A workaround would be using a debounce sketch to check the values of the pushbuttons on the loop.
Regards,
Sara
Sara,
Thanks for the help. I can switch to software GPIO polling, but I don’t like leaving the issue unsolved. I want the option of using interrupts with ESP32 in the future. There are some fundamental questions that an be answered by someone with deep knowledge of ESP32 – is there a GPIO mode that causes indefinite interrupt repeating on a state? Hopefully I’ll find that answer at some point. I don’t know what use this mode would be.
I’m going to switch to a (different) DOIT DEVIT V1 board and build some testing up from minimal hardware setup, see if the results are different. Then I’ll update this thread.
Stephen