Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4866

General • Async function as IRQ handler triggers only once

$
0
0

Code:

from machine import Pinimport asyncioasync def callback(p):    print(f'pin change {p}')async def main():    p0 = Pin(20, Pin.IN)    p0.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=await callback(p0))    while True:        print("Still in main")        await asyncio.sleep_ms(1000)asyncio.run(main())
I am trying to use asyncio on my RP Pico board. The reason being that I want to use async.sleep in the IRQ handler, callback. The issue, I have, is that the handler triggers only once when the code starts executing. Is there a way to attach an async handler behaving similar to a synchronous handler?

Statistics: Posted by jujiro — Sun Feb 16, 2025 9:08 pm — Replies 0 — Views 27



Viewing all articles
Browse latest Browse all 4866

Trending Articles