Attach interrupt not working on arduino Uno

hello, hope you doing all well, i was trying to trigger an interruption from a nano rp 2040 connect on arduino nano, i linked them with one wire, set the pin for interruption, and this is the code i used :

volatile bool pinState = LOW;
void setup() {
  Serial.begin(9600);
   // Set up the interrupt pin as input
  pinMode(10, INPUT);

  // Attach interrupt to the interrupt pin, triggering on any change (RISING or FALLING)
  attachInterrupt(digitalPinToInterrupt(10), handleInterrupt, CHANGE);
}

void loop() {
  // put your main code here, to run repeatedly:
    delay(100);
}

void handleInterrupt() {
  // This function is called when the interrupt pin changes state
  pinState = digitalRead(10); // Read the current state of the pin

  if (pinState == HIGH) {
    Serial.println("Interrupt detected: Pin is HIGH");
  } else {
    Serial.println("Interrupt detected: Pin is LOW");
  }
}

i did use a level shifter ( since rp2040 operates on 3.3 V and uno on 5 v logic) , i tested with an oscilloscope and checked that the wire sending interruption signal to arduino uno had indeed 5 V, so i can t figure out why the interruption isn't happening.

The topic title

Attach interrupt not working on arduino Uno

Please clarify which board the sketch that you posted is running on

You attached the interrupt to pin 10 but your handler is reading pin 11.

sorry, that was the code on arduino uno ( once the rp 2040 connect set the pin to high, it should trigger the interruption) , i added a print of the digital state of the pin in uno and it s effectively changing, so the problem is why the interruption not triggered.

no , it s was mistake by me while writing the code here, sorry.

you need 2 wires : GNDs need to be shared

make also sure that they run at the same voltage.

The Uno does not support external interrupts on pin 10, only pins 2 and 3

2 Likes

ah thanks, didn t knew that, thought i could customize using attach interrupt.

anyway to do an interruption on arduino uno on a custom pin like D4 or D10 ?

You can use pin change interrupts, but they have several limitations.

You should never print or do any serial I/O in an interrupt routine. On most MCUs, that will crash or freeze the program.

Arduino put in a work-around that allows serial print to work in ISRs, on some MCUs, but it is a bad idea.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.