invalid trigger behavior

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Posts: 5
Joined: Fri Feb 07, 2020 11:33 pm

invalid trigger behavior

Post by l00p1n6 » Fri Feb 07, 2020 11:56 pm


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:
        interrupt_pin = None
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

User avatar
Posts: 2141
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: invalid trigger behavior

Post by Roberthh » Sat Feb 08, 2020 8:07 am

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.

Post Reply