3

Is there a non-polling way to detect when an input goes from OFF to ON with the Raspberry Pi Pico MicroController?

I see the Raspberry Pi allows one to do something like below to detect rising edges on a GPIO port (reference: https://forums.raspberrypi.com/viewtopic.php?t=184361):

import RPi.GPIO as GPIO
GPIO.add_event_detect(<pin number>, GPIO.RISING, callback=<callback>)

Is there a similar API available for the Pico? When I try the above on Thonny/Pico, it fails because it doesn't recognize the GPIO module.

5
  • Which Pico GPIO pin interrupt tutorial are you following? I once tried Tom's Hardware Thonny MicroPython and found everything easier than Rpi3/4..
    – tlfong01
    Oct 24, 2022 at 8:07
  • I searched my old code and I found I used the following things: import _thread import utime # global variables , increments with each interrupt counter_1 = 0 counter_2 = 0 # declare pins for leds red_led = Pin(20, mode = Pin.OUT, value = 0) yellow_led = Pin(21, mode = Pin.OUT, value = 0) # declare pins for monitoring interrupts using push buttons core_1_interrupt_pin = Pin(16,Pin.IN,Pin.PULL_DOWN) core_2_interrupt_pin = Pin(15,Pin.IN,Pin.PULL_DOWN)
    – tlfong01
    Oct 24, 2022 at 8:22
  • 1
    I followed a couple of tutorials and this is one: electrocredible.com/…. You also need to define call back functions.
    – tlfong01
    Oct 24, 2022 at 8:25
  • 1
    Thanks @tlfong01 -- the tutorial link was helpful. The key statement here is the irq call, thanks!
    – Vivek
    Oct 26, 2022 at 13:30
  • You are welcome. Cheers.
    – tlfong01
    Oct 27, 2022 at 2:42

1 Answer 1

3

The Raspberry Pi and the Raspberry Pico are two very different machines. Do not assume a tutorial for one has any relevance to the other.

You need to read the Raspberry Pico API documentation for your chosen programming language.

The Raspberry Pico supports GPIO interrupts so no GPIO polling is needed.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.