Page 1 of 1

invalid trigger behavior

Posted: Fri Feb 07, 2020 11:56 pm
by l00p1n6
Hello,

I have some interrupt trigger testing code which doesn't work properly:

Code: Select all

from machine import Pin
from time import sleep

interrupt_pin = None


def handle_interrupt(pin):
    global interrupt_pin
    interrupt_pin = pin


pin = Pin(12, mode=Pin.IN, pull=Pin.PULL_UP)
pin.irq(trigger=Pin.IRQ_FALLING, handler=handle_interrupt)

while True:
    if interrupt_pin:
        print(interrupt_pin)
        interrupt_pin = None
        sleep(1)
The code prints the pin for both falling and raising events, i.e. both when I connect the pin 12 to GND and when I disconnect it.
Can someone check this small bit of code out, please?

BTW: I have tried using different pins without success.

REPL says I am using:
MicroPython v1.12 on 2019-12-20; ESP32 module with ESP32

Re: invalid trigger behavior

Posted: Sat Feb 08, 2020 8:07 am
by Roberthh
What you see is probably the effect of contact bouncing. When you open or close a contact by hand or in a mechanical switch, you have typically a burst of open/close events. Due to that, you may get seemingly false trigger events.

The ESP32 (and the ESP8266) have another property that in case of electronic signals with a slow transition time you can get multiple trigger events in the transition window between the low and high input value.