raspberrypi / pico-micropython-examples

Examples to accompany the "Raspberry Pi Pico Python SDK" book.
BSD 3-Clause "New" or "Revised" License
1.01k stars 228 forks source link

Why can not use IRQ in a new thread? #47

Closed jie-smile closed 2 years ago

jie-smile commented 2 years ago
from machine import Pin
import utime
import _thread

interruptCounter = 0
def callback(pin):
  global interruptCounter
  interruptCounter = interruptCounter+1

def foo():
    p16 = Pin(16, Pin.IN, Pin.PULL_UP)
    p16.irq(callback, Pin.IRQ_FALLING)
    while True:
        utime.sleep(1)

_thread.start_new_thread(foo, ())

while True:
    print(interruptCounter)
    utime.sleep(1)

The irq is not work

lurch commented 2 years ago

The RP2040 MicroPython port has been merged upstream to the main MicroPython repo, see https://github.com/micropython/micropython/pull/6791. So going forward you should report problems with the port there, https://github.com/micropython/micropython/. Technical support can be found on the MicroPython forums, https://forum.micropython.org/viewforum.php?f=21.