using interrupts with UNO WIFI Rev2

Hi,
I tried to use the new card UNO WIFI Rev2 at the place of an UNO (standard).
I use interrupts pin2 and pin3 on UNO and it's work fine.
I compiled the same program with the UNO WIFI Rev2. No problem.
I downloaded it on the card, always OK
A launch the sketch, it seem to work (the input value change when a connect the pin to the ground.
But, with the line "attachInterrupt (digitalPinToInterrupt(2), etatPorte2, CHANGE)", the pin0 react with the interrupt (and not the pin2!).
And for the Pin3, nothing appends!
Any idea ?
Why it is not like the UNO card ?

Thanks in advance

Here is the very simple program I use for test :

void setup(void) {
Serial.begin(9600);
for (int y = 0; y<= 13; y++) {
pinMode (y, INPUT_PULLUP);
}
attachInterrupt (digitalPinToInterrupt(2), etatPorte2, CHANGE);
attachInterrupt (digitalPinToInterrupt(3), etatPorte3, CHANGE);
}

void loop(void) {
for (int x = 0; x <= 13; x++) {
Serial.print (x); Serial.print (":"); Serial.print (digitalRead (x)); Serial.print (" - ");
}
Serial.println ("");
delay (1000);
}

void etatPorte2 () {
Serial.print (digitalRead (2)); Serial.print (" - ");
Serial.println ("Etat Porte 2 Change");
}

void etatPorte3 () {
Serial.print (digitalRead (3)); Serial.print (" - ");
Serial.println ("Etat Porte 3 Change");
}

From attachInterrupt() - Arduino Reference

For Uno WiFiRev.2, Due, Zero, MKR Family and 101 boards the interrupt number = pin number.

So, unlike with the AVR boards, you should not use digitalPinToInterrupt with attachInterrupt on the Uno WiFi Rev2. This is the correct code:

  attachInterrupt (2, etatPorte2, CHANGE);
  attachInterrupt (3, etatPorte3, CHANGE);

sarem:
Why it is not like the UNO card ?

Unfortunately, the product name is a bit misleading. Other than the form factor, the Uno WiFi Rev2 is actually very different from the Uno. You're going to find that some code which works on the Uno doesn't work on the Uno WiFi Rev2 without some modifications.

Thank you,
It's work fine now !

Who can I find the specificity of this new card (for using the Inertial Mesurement Unit by exemple) ?

Jean-Marc

@pert Interrupts drove me nuts on the Uno WiFi Rev 2, too. The documentation says "You still define the interrupts with the usual function attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);."

Then, WAY down at the bottom of the attachInterrupt() page is this note"

"For Uno WiFiRev.2, Due, Zero, MKR Family and 101 boards the interrupt number = pin number."

It took me forever to find that. >:(

My understanding is that attachInterrupt is supposed to work on every board with the:

attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);

syntax. It's just that on the SAMD Boards, Due, 101, and Uno WiFi Rev2, the interrupt numbers are the same as the pin numbers so you can get by without using the digitalPinToInterrupt macro. It's only on the AVR Boards where digitalPinToInterrupt is mandatory if you want to work with Arduino pin numbers. I don't see any reason why digitalPinToInterrupt couldn't still be implemented so that you use the same attachInterrupt syntax across all boards:

#define digitalPinToInterrupt(pin) (pin)

This results in portable code.

My suspicion is that this is actually a bug in the core library for the Uno WiFi Rev2 that needs to be reported and fixed. Investigating it is on my "To do" list but I'm a bit hampered because I don't own an Uno WiFi Rev2 and don't have a good familiarity with the Arduino megaAVR Boards core library code yet.

pert:
This results in portable code.

I brought my dev code from my regular Uno to my new Uno WiFi Rev 2 and it wouldn't work. I traced it to the interrupt problem. When I used the pin number instead of digitalPinToInterrupt(pin), it worked fine.

Portability is good.

Thanks for reporting the bug.

Definitely a bug.

I have now reported the issue: