Page 1 of 1

Single interrupt trigger performing callback function several times.

Posted: Sun Jul 05, 2020 3:06 pm
by HexVitor
Hi, I'm having problems with an ESP32-based project due to the strange behavior of the interruption on some pins.
When configuring the interrupt according to the code below, a single actuation on pin 23 has called the callback function more than 1 time, even without other activations on the pin.
This has happened with several pins. How do I execute the interruption only once per trigger?

MCU: ESP-WROOM-32 (ESP32D0WDQ6)
Firmware: MicroPython v1.12 (for ESP32 with IDF4, 2019.12.20) https://micropython.org/resources/firmw ... -v1.12.bin
IDE: Thonny Python IDE
OS: Windows 10 Home Single Language 2004

Code: Select all

from machine import Pin
from time import sleep

led = Pin(2, Pin.OUT)
button = Pin(23, Pin.IN, Pin.PULL_DOWN)

def callback(pin):
    led(1)
    sleep(1)
    led(0)
    sleep(1)
    
button.irq(trigger=Pin.IRQ_RISING, handler=callback)

Re: Single interrupt trigger performing callback function several times.

Posted: Sun Jul 05, 2020 3:55 pm
by Roberthh
Two possible reasons for that:
a) bouncing of the input signal, if that comes from a switch. There are lots of discussions in this forum about de-bouncing.
b) false triggers due to slow slope of the input signal. That happens with the ESP32. Either increase the slope of the signal, or use the de-bouncing method.

Re: Single interrupt trigger performing callback function several times.

Posted: Tue Jul 07, 2020 12:49 pm
by HexVitor
Thanks for the feedback. I did exhaustive tests with internal and external pull up and pull down resistors and none of the pins were 100% satisfied (they start well but sooner or later they perform the callback function 2 or 3 times with a single trigger). Based on this I believe that the hypothesis of the slow slope of the input signal is the most likely cause, however I do not know how to correct this. Will I need capacitors? If so, how will I use them? Thanks for helping me.

Re: Single interrupt trigger performing callback function several times.

Posted: Tue Jul 07, 2020 2:07 pm
by Roberthh
You need an external active component like the schmitt-trigger gate 74hc14.

Re: Single interrupt trigger performing callback function several times.

Posted: Wed Jul 08, 2020 10:47 am
by jcw
Still sounds like electrical contact bounce to me - resistors won't solve that. Google for "button debounce", e.g.

https://www.allaboutcircuits.com/techn ... l-with-it/