Unfortunately, variant.cpp doesn’t describe the remaining pins on the SAM D21, which are not connected to the pin headers at the Arduino Zero. Therefore, these extra pins can't be controlled as usual, for example, with digital write (13, 0):
pin19 PB10 = digital pin 23
pin20 PB11 = digital pin 24
pin21 PA12 = digital pin 21
pin22 PA13 = digital pin 38
pin37 PB22 = digital pin 30
pin38 PB23 = digital pin 31
pin39 PA27 = digital pin 26
pin41 PA28 = digital pin 27
pin45 PA30 x not defined, used for SWD programming/debug
pin46 PA31 x not defined, used for SWD programming/debug
pin48 PB3 = digital pin 25
If you use the default variant file (default Arduino Samd Core), Sercom5 is already used as an Uart port on pin 30 and 31. It is the Serial instance. You can rename it Serial4 if you want by modifying the variant.cpp file.
Please don't go away guys because this is the thread I have been looking for for weeks.
Little did I know that the answer to the question I had, "How to use more pins", was under my nose all the time. I have been hunting for this information on the internet without any great success and, as a newby still learning about MCUs and Arduino, this seems to be the "golden" thread and I bet many others feel that way to.
I built a custom board, probably a bit hasty for a newby, but I did it. It is not much of a stretch from the basic Zero but I needed a few extra pins added and to re-route the use of others. If you can confirm I understand what you are saying here I am on my way.
a. I have a direct connection on the board to an LED from PA07. When I write the sketch I simply refer to the LED driver pin as pin 9, ie digitalWrite(9, HIGH) --- correct?
b. I use PA10 and PA11 for on-board serial use so I made sure the use of these pins was not changed.
c. I need three new connections for digital use to PB22, PB23 and PB27 (this was mainly to ease PCB trace layout). So, I simply refer to these as pins 20, 21 and 26 in the sketch, define them as digital pins with pinmode and the IDE will accept this even though these are not defined as Arduino Zero pins. Is this correct?
Do I need to do anything else to make this work?
Obviously I could just try these ideas on the board to see if they work but I am not sure yet that the board itself is perfect yet so it would be a great help if I could know that what I am trying is correct before I experiment.
When you create your own board, you can reassign "pin numbers" to the actual chip pins in any way you like, by re-writing the variant.h and perhaps variant.cpp. In theory, anyway. In reality, departing too far from the existing mappings will cause you all sorts of grief with existing libraries that assume things like "digital pin 0/1 are the Serial port", which wouldn't necessarily be true any more. That's why it's more common for a variant to keep the same pin mappings for the pins that are common, and assign new "high-numbered" pins any added pins...
I was careful to disturb as few pins as possible in the standard Zero range but we did move pin 13 functions to pin 9 to simplify the trace layout. Do you see anything wrong with that? The LED driver layout was copied straight from the Zero schematic except this is a direct connection to the LED with no exterior pin breakout.
I think I have other problems with my board because simply using the "blink" sketch and substituting pin 9 and PA07 for pin 13 and PA17 does not work (but this should be the subject for another post).
It depends on which schematic you look at... Those two pins are rolled between the Ardiuino.cc Zero and Arduino.org M0 Pro. I've seen a few different versions of the schematics floating around out there.
dlabun
I am comparing the variant.cpp file in my computer with the schematic on the Arduino website. You would think that these two would match since they are both from the same source. A typo somewhere no doubt but I suppose for the routine Zero user this does not matter but when you are designing your own board with custom pin-outs it could be a problem.
Thanks for the updated schematic Martini, I think I like this layout more than the old one.
I suppose the pinouts being wrong on the old schematic don't really matter if you are only using the Zero on a dev. board basis because one I/O is the same as another. This would only be a problem for someone making a custom board who did not check the schematic closely enough and somehow built the error into their project.