Can't get interrupts to work #276
-
Using the Arduino IDE 1.8.15, arduino-pico 1.9.3 as the board, on a Raspberry Pi Pico (bought this week!). My first sketch, which uses a toggle switch with each side connect to digital pins 14 and 15 (physically 19 and 20) and a potentiometer attached to ADC 0 (physical pin 31). The first version used simple polling to read the input values, which it writes out via the serial port, but I thought I would try and get the two digital inputs to use interrupts instead, with no success.
(There's no fundamental reason why the serial stuff is in the second core. I've tried doing everything in the first core, with no change in outcome.) With Looking at #25/#26, I would expect interrupts to work; I'm probably doing something really stupid, but can't for the life of me see what. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
I've definitely had interrupts working, both with the Arduino attachInterrupt() and the native gpio_set_irq_enabled_with_callback(). I settled on the latter so I could have one interrupt handler that worked out which pin triggered the interrupt. However, that doesn't explain your issue. Can't see an obvious problem, but in my code, I simply use the GPIO number in the digitalPinToInterrupt macro. Otherwise, I'd start by putting some LED toggling in the interrupt handler, to avoid any issues with variables. That way, you can see if the interrupt is getting called at all. Having said all of that, I tried your code on my Pico and it works (core: 1.9.1) |
Beta Was this translation helpful? Give feedback.
I've definitely had interrupts working, both with the Arduino attachInterrupt() and the native gpio_set_irq_enabled_with_callback(). I settled on the latter so I could have one interrupt handler that worked out which pin triggered the interrupt.
However, that doesn't explain your issue. Can't see an obvious problem, but in my code, I simply use the GPIO number in the digitalPinToInterrupt macro. Otherwise, I'd start by putting some LED toggling in the interrupt handler, to avoid any issues with variables. That way, you can see if the interrupt is getting called at all.
Having said all of that, I tried your code on my Pico and it works (core: 1.9.1)