Skip to content

Interrupt on pin (IRQ) (gpio_interrupt)

What it does: Sets the interrupt handler on the selected pin and trigger (edge/level optional).

gpio_interrupt

Inputs

  • pin: pin number.
  • code: commands to be executed when interrupted.
  • Field trigger: condition for raising an interrupt.

Output

  • none (command block).

When to use it

  • When you need to react immediately to a change in pin status.
  • pulse counter, encoder, quick button, event detection.

Tips and pitfalls

  • Keep the code as short as possible in the interrupt handler.
  • Do not do network operations or long calculations in the interrupt.

Generated Python example

from machine import Pin

def callback22(p):
    print("IRQ", p.value())

p22 = Pin(22, Pin.IN)
p22.irq(trigger=Pin.IRQ_FALLING, handler=callback22)