← index #11140Issue #7035
Related · high · value 4.324
QUERY · ISSUE

rp2: Reading pin value from IRQ hangs forver

openby GuillaumeLeclercopened 2023-03-28updated 2026-03-25
bugport-rp2proposed-close
from machine import Pin, idle, disable_irq, enable_irq
from time import sleep_ms

pin = Pin(1, Pin.IN)

def on_change(pin):
    state = disable_irq()
    pin.value()
    enable_irq(state)

pin.irq(on_change, Pin.IRQ_RISING | Pin.IRQ_FALLING)

for i in range(1000):
        idle()
        sleep_ms(100)
        print("WORKING")

It seems impossible to read the value of the pin object passed as an argument to the callback. As soon as it is triggered the RPI Pico stop working until I unplug/replug it. Using the pin from the global context works or even recreating a new Pin instance, but not using the one passed as an argument

firmware: rp2-pico-20230116-unstable-v1.19.1-803-g1583c1f67.uf2

CANDIDATE · ISSUE

rp2: Can't wake from lightsleep with Pin IRQ

openby peterhinchopened 2021-03-15updated 2026-03-24
port-rp2

On a pin change this code sample toggles the LED but never outputs "got here".

from machine import Pin, lightsleep
p25 = Pin(25, Pin.OUT)
p0 = Pin(0, Pin.IN, Pin.PULL_UP)
def foo(_):
    p25(not p25())  # Toggle the LED

p0.irq(foo, trigger=Pin.IRQ_FALLING)
while True:
    lightsleep()
    print('Got here')

The docs indicate that to fix this, the IRQ should be instantiated with wake=machine.SLEEP. Unfortunately this constant does not exist.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied