Pin numbers don't match b/w datasheet and variant.h!

Hey Guys,

I don't know what's happening here but the pin definitions in variant.h / variant.cpp don't match with those in datasheet.

The controller I have on zero is SAMD21G18. A look at the datasheet says that pin 31 is PA22 for example. However in variant.cpp, PA22 is pin 20! Same goes for all the other pins.

The variant.h I am looking at is located here,
C:\Users.....\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.6\variants\arduino_zero
I am on windows 10.

I am able to run programs using serial, I2c and SPI interface without problems :o , so variant.h must be correct? What am I missing?

Thanks

The pin number in the variant file is the Arduino pin number. This is just an arbitrary identifier number assigned to each pin that makes it easy to use, e.g.:

digitalWrite(20, HIGH);

sets pin PA22 HIGH.

The Arduino pin number itself doesn't mean anything.

I'm guessing the datasheet you're referring to is the manufacturer's datasheet for the microcontroller? If so then the pin number you're seeing listed there is likely the physical pin number on the chip, which is completely different from the Arduino pin number. If you think about it a little bit you'll see why, it would not be practical for Arduino pin numbers to match physical pin numbers, since every physical pin is numbered rather than just the I/O pins.

Oh I see. I programmed Atmel controllers before using AVR Studio and the pin numbers in definitions were the same as physical pin numbers. That's why I find this Arduino scheme strange.

I programmed Atmel controllers before using AVR Studio and the pin numbers in definitions were the same as physical pin numbers.

No they're not (well, maybe some of the tiny chips.) The ATmega328, for instance, has three separate "ports" (PORTB, PORTC, PORTD), each of which has some subset of bits numbered 0 to 7. A normal AVR programmer has to deal with the multiple PORTS, understand bitmasks vs bit numbers, and some other things that the Arduino/Wiring libraries simplify a great deal...

Hi

Does somebody could provide the pin mapping for the M0PRO board (link between Arduino board pin number and SAMD 21 micro one) ?

Thanks

Daniel

Thanks a lot !

This is for the zero board...need for M0PRO !!

I understood th 2 boards to be pin mapping identical, except D2 / D4 which are inverted, and no ATN on M0PRO ?

Daniel

That is the variant file for the M0 Pro:

I'm guessing the reference to "Zero board" is because they copied it over from the Zero and didn't bother to completely update the comment text.

This is the variant for the Zero:

and indeed it does show the pins 2 and 4 switched from the arduino_mzero variant.