External button, 19=13?

We need 4 external buttons on the SODAQ ONE V2.

For one of those buttons I want to use AIN11.

AIN11 is PB3, and in variant.cpp of sodaq_one this is pin 13.
It’s not working when I define pin 13 for the button.
When I define pin 19 (instead of 13): it works. Why?

You are correct, AIN11 = PB3 and that should be pin 13. Do you know if you’re running the latest board files for the SODAQ ONE?



Using pin 19 definition, and connecting to the button to AIN0 also works (and better than when connected to AIN11).

Pin 19 is PORTA16 (see variant.cpp), this is attached to the button on the board.

Pin 13 is attached to PORTB3, additionally A11 (pin 33) is also defined on PORTB3.

Use 13 when you want to use the pin for digital operation and A11 or 33 when you want to use it in analog input mode.

I agree that it should not work when using AIN11 for the physical connection, and defining pin 19 instead of pin 13 or pin 33.

But it works and I don’t know why…

OK, found it…

When I defined BUTTON_PIN 19, I was using
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), ButtonChange, CHANGE);

digitalPinToInterrupt(19) is 0, so this is the same as
attachInterrupt(0, ButtonChange, CHANGE);
But this “pin” 0 is converted to interrupt 2.
PA2 is using interrupt 2.

That is why connecting the external button to PA2 (AIN0) worked.

So, lesson learned: check WInterrupts.c and use the pin number in attachInterrupt.
attachInterrupt(BUTTON_PIN, ButtonChange, CHANGE);

Yes with the SAMD boards you should not use the digitalPinToInterrupt() macro.