Pin Change interrupt - Finding various variable names

Hello,

I am trying to use pin change interrupt with my Arduino Uno R4 Minima following this tutorial, and in particular using this code found on the website:

/*
  Pin Change Interrupt Test
  pin-change-test.ino
  Demonstrates use of Pin Change Interrupt
  Input on D7, LED on D13
 
  DroneBot Workshop 2022
  https://dronebotworkshop.com
*/
 
// LED and switch
const byte ledPin = 13;
const byte buttonPin = 7;
 
// Boolean to represent toggle state
volatile bool togglestate = false;
 
void setup() {
 
  // Set LED as output
  pinMode(ledPin, OUTPUT);
 
  // Set switch as input with pullup
  pinMode(buttonPin, INPUT_PULLUP);
 
 
  // Enable PCIE2 Bit3 = 1 (Port D)
  PCICR |= B00000100;
  // Select PCINT23 Bit7 = 1 (Pin D7)
  PCMSK2 |= B10000000;
 
}
 
void loop() {
  // No code in Loop
}
 
ISR (PCINT2_vect)
{
  // Interrupt for Port D
  // Invert toggle state
  togglestate = !togglestate;
  // Indicate state on LED
  digitalWrite(ledPin, togglestate);
 
 
}

It, naturally, does not even compile because the Arduino Uno R4 Minima has a Renesas RA4M1 microcontroller instead of whatever the tutorial is using. In particular, the variable names PCICR, PCMSK2, PCINT2_vect are different for the Renesas.

To obtain the correct names (hopefully the only change needed for the above code to work) I tried to look at the documentation of the microcontroller here.

My problem is that I do not understand what is written there and what I should be looking for, as the vocabulary of the tutorial is different from the vocabulary of the documentation full of acronyms.

My question is therefore: does anyone knows of a dictionary that provides this information, or tell me how to decipher the documentation so that I find these variables names I am looking for to copy/paste in the code?

Is Pin Change Interrupt even possible with Arduino Uno R4 Minima?
(Note that I know about attachInterrupt(), but it does not fit my end goal as I would need 4 pins to interrupt instead of the only two existing in the Arduino Uno R4 Minima.)

You might look at the attachInterrupt functions. Example:

// LED and switch
const byte buttonPin = 2;
 
void setup() {
 
  // Set LED as output
  pinMode(LED_BUILTIN, OUTPUT);
 
  // Set switch as input with pullup
  pinMode(buttonPin, INPUT_PULLUP);
 
  attachInterrupt(digitalPinToInterrupt(buttonPin), &my_isr, CHANGE);

}
 
void loop() {
  // No code in Loop
}
 
void my_isr()
{
  digitalWrite(LED_BUILTIN, digitalRead(buttonPin));
 
}

When pin 2 changes it will set the built in LED to it's state...

Thank you, but as I mention at the end of my post, I specifically cannot use attachInterrupt because, in the end, I would need 4 pins able to support the function, while only 2 are available on an Arduino Uno R4 Minima.

There are more than 2 pins, with interrupts. I have not tried all of them but also tried A1...

From my Excel document:

I tried to highlight all of them that had IRQn in their column.

1 Like

This is not what this document is saying.
I tried to use pin 12 and pin 13 (so with attachInterrupt(digitalPinToInterrupt(12), &my_isr, CHANGE); ) in your code, without success, whereas attachInterrupt(digitalPinToInterrupt(2), &my_isr, CHANGE); would work.

Naturally, I would plug the button into pin 12 and 2 respectively. Am I missing something?

Worked for me on Pin 12...

Did you also change the line: const byte buttonPin = 2;

If not if you just edited the pinChange line, did you also change the other places that referenced the buttnPin, like the pinMode and the digitalRead?

As for Arduino docs... Not sure why they only showed those two pins...

Edit: The interrupts on other pins is also shown on the Advanced pinout page:
ABX00080-full-pinout.pdf (arduino.cc)

Scroll down to the advanced section

Edit 2: If two pins have the same IRQ number, my assumption is that only one will work at a time. Example pins 1 and 14 and A4 all are IRQ 1...

Probably one reason Arduino did not fully document this on the attachInterrupt page.

Hi @pf_bsf,

I made a test using 4 buttons on pins 1, 2, 3 & 4 and it is working fine for me, I made a function that changes the status of the built-in LED using any of these four buttons.

This is my sketch:

// LED and switch
const byte buttonPin1 = 0;
const byte buttonPin2 = 1;
const byte buttonPin3 = 2;
const byte buttonPin4 = 3;
bool status = 1;

void setup() {

  // Set LED as output
  pinMode(LED_BUILTIN, OUTPUT);

  // Set switch as input with pullup
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT_PULLDOWN);
  pinMode(buttonPin2, INPUT_PULLDOWN);
  pinMode(buttonPin3, INPUT_PULLDOWN);
  pinMode(buttonPin4, INPUT_PULLDOWN);
  attachInterrupt(digitalPinToInterrupt(buttonPin1), &my_isr, HIGH);
  attachInterrupt(digitalPinToInterrupt(buttonPin2), &my_isr, HIGH);
  attachInterrupt(digitalPinToInterrupt(buttonPin3), &my_isr, HIGH);
  attachInterrupt(digitalPinToInterrupt(buttonPin4), &my_isr, HIGH);
}

void loop() {
  digitalWrite(LED_BUILTIN, status);

  Serial.print("Button 1: ");
  Serial.println(digitalRead(buttonPin1));

  Serial.print("Button 2: ");
  Serial.println(digitalRead(buttonPin2));

  Serial.print("Button 3: ");
  Serial.println(digitalRead(buttonPin3));

  Serial.print("Button 4: ");
  Serial.println(digitalRead(buttonPin4));

  Serial.print("Status: ");
  Serial.println(status);
  delay(300);
}
void my_isr() {
  status = !status;
}

In my code, all the buttons "activate" the same interruption functions when the state is HIGH and it works properly for me.

This is my setup:

To know the available pins for interruptions I used the Full Pinout document

And the excel image that @KurtE attached.

I hope it helps you :slight_smile:

It does help, thank you!