You can use the == operator to see if two pin objects are the same.

p = machine.Pin(0)
p == machine.Pin(0) # True
p == machine.Pin(1) # False

MicroPython actually only creates one Pin object for each physical pin. So you could also use the is operator to compare pin objects by identity.

Answer from David Grayson on Stack Overflow
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › general
Are the GPIO pins in RPi Pico Hardware Interrupts? - Raspberry Pi Forums
GPIO interrupts work differently these are interrupts which have different trigger conditions which can generate an interrupt. Generally there is a multiple conditions routed to a single interrupt. However in this case there is a single GPIO interrupt for all pins and all conditions.
🌐
Microcontrollers Lab
microcontrollerslab.com › home › electronics components › raspberry pi pico pinout reference – which gpio pin to use?
Raspberry Pi Pico Pinout, Features, Programming Options and Peripherals
December 2, 2025 - All GPIO pins can be configured as an external interrupt pin on the following four changes on the state of GPIO pins: ... Note: The Raspberry Pi Pico’s GPIOs are connected to the on-board 3.3V rail and are therefore fixed at 3.3V.
Discussions

Pin interrupts on Rpi pico with arduno-pico code
I'm using the Arduino IDE with the arduino-pico core and I'm trying to get pin interrupts working for a rotary encoder application. Here is the code: #define ROTA 6 // GPIO6 rotary encoder A #define ROTB … More on forum.arduino.cc
🌐 forum.arduino.cc
9
0
July 26, 2022
Correct way to implement interrupts inside a class (Pi Pico W)
There’s a lot of issues with this code - overuse of heap allocation, raw pointers, inconsistent naming etc. But to your actual question: your approach is conceptually broken because you have one static variable to jump through for two motors. So however is last sets sEncoder, and wins. The other can’t count. Depending on your circumstances there’s a few options here: if the pin is asserted long enough, your can write one IRQ that reads the pin states of all(!) pins and dispatches to IRQ handlers specific to each pin. You can encapsulate this into its own class that allow registering additional pins and then contains a data structure to map pin number to callback and a void* user pointer. And then your static function in motor controller casts that to MotorController and you delegate to the correct instance. This only works if the pins are reliably asserted long enough. use the PIO to write a QDEC encoder (it’s part of the official examples) and just obtain a convenient counter value. That’s my approach. More on reddit.com
🌐 r/raspberrypipico
9
1
August 19, 2024
micropython - RPI Pico Micro python which pin triggered the interrupt - Stack Overflow
I have the code below running on a RPI Pico. i want to use a single interrupt handler to handle 2 pins, But how do I know which pin is called the handler? #switches pin assignments cf_close = P... More on stackoverflow.com
🌐 stackoverflow.com
micropython - How to find which pin caused an interrupt? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
August 20, 2022
🌐
Random Nerd Tutorials
randomnerdtutorials.com › home › raspberry pi pico › raspberry pi pico with interrupts: external and timer interrupts (micropython)
Raspberry Pi Pico Interrupts: External and Timer (MicroPython) | Random Nerd Tutorials
December 3, 2025 - The following table shows the connections between the PIR motion sensor and the Raspberry Pi Pico: We’ll wire the PIR motion sensor data pin to GPIO 21 and the LED to GPIO 20. The following code will set the PIR motion sensor as an interrupt.
🌐
Microcontrollers Lab
microcontrollerslab.com › home › raspberry pi pico › pir motion sensor with raspberry pi pico using external interrupts
PIR Motion Sensor with Raspberry Pi Pico using External Interrupts
February 18, 2026 - The center pin is an output pin which provides an active high pulse whenever motion is detected. Otherwise, this pin remains active low. That means a rising edge occurs when a PIR sensor detects motion.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Pin interrupts on Rpi pico with arduno-pico code - Programming - Arduino Forum
July 26, 2022 - I'm using the Arduino IDE with the arduino-pico core and I'm trying to get pin interrupts working for a rotary encoder application. Here is the code: #define ROTA 6 // GPIO6 rotary encoder A #define ROTB 7 // GPIO7 rotary encoder B // rotary encoder pin change interrupt handler void readEncoder() { encoder_state = (encoder_state
🌐
Electrocredible
electrocredible.com › home › embedded systems › raspberry pi pico › raspberry pi pico interrupts tutorial- examples in micropython
Raspberry Pi Pico Interrupts Tutorial- Examples in MicroPython
April 10, 2025 - Here we discuss how to trigger external interrupts on Raspberry Pi Pico and interface push buttons using polling and interrupts. MicroPython will be used in this tutorial.
🌐
Reddit
reddit.com › r/raspberrypipico › correct way to implement interrupts inside a class (pi pico w)
r/raspberrypipico on Reddit: Correct way to implement interrupts inside a class (Pi Pico W)
August 19, 2024 -

Hi!

I am coding a differential robot controller on the Pi Pico W with C++ using the Arduino IDE and I'm facing some trouble implementing the interrupts for the motor encoders.

My main class is robot_control and I am using a motor_controller class to initialize each motor and encoder. This is the class where I want to set the interrupts.

After failing a lot and reviewing many posts on the subject -specially the last comment of this thread: https://forum.arduino.cc/t/interrupt-inside-a-class/180419 I finally got to this code, which compiles but doesn't trigger the interrupts.

Can you please help me find the reason and possible solutions? Thank you in advance!

Main .ino file

// main.ino

#include "robot\_control.h"

RobotControl robot;

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // Wait for serial port to connect
  }
  Serial.println("Initializing robot control system...");
  robot.setup();
  Serial.println("Robot control system initialized.");
}

void loop() {
  robot.loop();
}

robot_control.cpp

#include "robot\_control.h"

RobotControl::RobotControl() : emergencyStop(false), currentMode(ControlMode::AUTONOMOUS) {
  // Adjust pin numbers as needed for your setup
  leftMotor = new MotorController(11, 12, 13, 3);   // en, l\_pwm, r\_pwm, encoderA
  rightMotor = new MotorController(7, 8, 9, 1); // en, l\_pwm, r\_pwm, encoderB

  display = new Display();
  wifiManager = new WifiManager();
  joystick = new JoystickController(26, 27, 16);  // Adjust pins as needed
}

void RobotControl::setup() {
  pinMode(EMERGENCY\_STOP\_PIN, INPUT\_PULLUP);
  display->init();
  wifiManager->connect("ssid", "psw");
}

void RobotControl::loop() {
  // Related stuff
}

robot_control.h

// robot_control.h
#pragma once
#include <Arduino.h>
#include <WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <U8g2lib.h>
#include <BTS7960.h>

class MotorController {
public:
    MotorController(int en, int l_pwm, int r_pwm, int encoderPin);
    void setSpeed(int speed);
    int getSpeed();
    void enable();
    void disable();
    void turnLeft(uint8_t pwm);
    void turnRight(uint8_t pwm);
    void update();
    void encoderLoop();
    void handleEncoder();


private:
    BTS7960 motor;
    // Encoder variables
    volatile long encoderCount;
    unsigned long lastTime;
    float currentSpeed;
    int encoderPin;

    static MotorController* sEncoder;
    static void handleEncoderISR();
};

class RobotControl {
public:
    RobotControl();
    void setup();
    void loop();

private:
    MotorController* leftMotor;
    MotorController* rightMotor;
    Display* display;
    WifiManager* wifiManager;
    JoystickController* joystick;

    // Related functions
};

motor_controller.cpp

#include "robot_control.h"

MotorController* MotorController::sEncoder = 0;

MotorController::MotorController(int en, int l_pwm, int r_pwm, int encoderPin)
    : motor(en, l_pwm, r_pwm), encoderPin(encoderPin),
      encoderCount(0), lastTime(0), currentSpeed(0.0), pulsesPerRevolution(42) {
   
    pinMode(encoderPin, INPUT_PULLUP);
   
    // Set up Encoder variables
    const int pulsesPerRevolution = 42;  

    sEncoder = this;

    // Attach interrupt for encoder
    attachInterrupt(digitalPinToInterrupt(encoderPin), MotorController::handleEncoderISR, RISING);
}

void MotorController::setSpeed(int speed) {
    setpoint = speed;
}

int MotorController::getSpeed() {
    return currentSpeed;
}

void MotorController::enable() {
    motor.Enable();
}

void MotorController::disable() {
    motor.Disable();
}

void MotorController::turnLeft(uint8_t pwm) {
    motor.TurnLeft(pwm);
}

void MotorController::turnRight(uint8_t pwm) {
    motor.TurnRight(pwm);
}

void MotorController::update() {
    // update
}

void MotorController::updatePID() {
    // PID algorithm
}

void MotorController::handleEncoder() {
    encoderCount++;
}

void MotorController::handleEncoderISR() {
    if (sEncoder != 0)
        sEncoder->handleEncoder();
}

void MotorController::encoderLoop() {
   //…
}
Find elsewhere
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › sdk
PIco GPIO Interrupt (C) - Raspberry Pi Forums
gpio_set_irq_enabled_with_callback(21, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, &gpio_callback); and other pins with
🌐
YouTube
youtube.com › watch
Using PICO Interrupts - YouTube
Learn how to use Interrupts on the RPi PICO microcontroller. Covered in this video are:* What Interrupts are* Applications for Interrupts* Two parts of an I...
Published   May 27, 2022
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › sdk
[solved] Pico GPIO interrupts - Raspberry Pi Forums
November 17, 2021 - I am trying to implement a rotary encoder interface using GPIO interrupts. As there is only one vector for all GPIO interrupts and I want some single buttons as well, then in the interrupt handling function I look at what pin has caused the interrupt and pass the call to the appropriate function.
🌐
Upsy
upesy.com › tutorials › raspberry pi pico › pi pico programming › micropython › basics › interruptions
Interrupts RPi Pico MicroPython : React to events - uPesy
February 2, 2023 - Suppose a pin is set to Pin.IRQ_FALLING will generate an interrupt when the signal goes from HIGH to LOW (3.3V to 0V). This example script in MicroPython allows you to use a signal received by your Pi Pico to activate an external interrupt.
🌐
Instructables
instructables.com › circuits › microcontrollers
Dual Cores & Interrupts on Pi Pico : 5 Steps (with Pictures) - Instructables
April 6, 2021 - Dual Cores & Interrupts on Pi Pico: The new Raspberry Pi Pico offers Dual Cores and Interrupts if you use MicroPython. I thought I would give it a go and try explain some of the pitfalls to avoid. This project keeps the action running on the two cores very simple, so that we can conce…
🌐
Stack Overflow
stackoverflow.com › questions › 73427047 › micropython-raspberry-pico-interrupt-but-from-which-pin
micropython - How to find which pin caused an interrupt? - Stack Overflow
August 20, 2022 - def handle_interrupt(Pin): print(Pin) int1 = Pin(2, Pin.IN,Pin.PULL_UP) int1.irq(trigger=Pin.IRQ_FALLING, handler=handle_interrupt) int2 = Pin(10, Pin.IN,Pin.PULL_UP) int2.irq(trigger=Pin.IRQ_FALLING, handler=handle_interrupt)
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › general
Interrupt handling problem in Pico - Raspberry Pi Forums
def my_interrupt(pin): pin.irq(handler=None) # <-- print("Interrupt Detected!") my_timer(pin) # <-- def my_timer(pin): # <-- print("Function Begin!") print("Function END!") pin.irq(trigger=machine.Pin.IRQ_FALLING, handler=my_interrupt) # <--- ... You are right hippy, I think i erased an important line while erasing experimental comments. The code should be like this with interrupt handler declared. The interrupt is declared after functions but before the while loop, so I guess it won't cause any problem. What i don't understand is pico is acting like it has a buffer of pressed buttons like a keyboard.
🌐
GitHub
github.com › earlephilhower › arduino-pico › discussions › 1397
Interrupt Queueing · earlephilhower/arduino-pico · Discussion #1397
There should be an NVIC function and maybe an Pico-SDK wrapper call you could use. One note, though, is that there is only one IRQ for all GPIO pins, so if you have other GPIO-based IRQs you'll lose those, too.
Author   earlephilhower
🌐
Stack Overflow
stackoverflow.com › questions › 77484251 › two-interrupts-in-raspberry-pi-pico
c - Two interrupts in raspberry pi pico - Stack Overflow
#include<stdio.h> #include "pico/stdlib.h" #include "hardware/gpio.h" #include "hardware/adc.h" #include "hardware/pwm.h" #include "hardware/timer.h" #define POT_PIN 26 #define PWM_OUTPUT 12 #define ENCODER_14 14 #define ENCODER_15 15 #define ...
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › general
Multiple Interrupts using RPi Pico - Raspberry Pi Forums
Mon May 29, 2023 5:15 am I had read that all pins can be used as interrupt pins but the Pico has only 2 external interrupts. I think what you mean by this is each of the two processors has separate GPIO interrupts, which is true. Those interrupts have individual enable bits for each GPIO, so you can use a single interrupt to monitor all 10 GPIOs.