Arduino Zero Bare Board - Using All SAMD21G18 Digital Pins

Hello everyone,

I'm designing a SAMD21G18 (zero based) bareboard and I'm willing to use more pins than the 13 digital + 6 analog pins that are available on the development board.

The SAMD21G18 datasheet says that is has 34 pins total (digital + analog)...

I wonder if I can use all these pins by modifying the Arduino_Pins.h library. And if so, how to modify it?

Thanks

Hi TSMotter,

The pin configurations for the SAMD21G18A are stored in the "variant.h" and "variant.cpp files.

These are located (on my Windows PC at least) at:

C:\Users\Computer\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.18\variants\arduino_zero...

To configure additional Arduino digital and analog pins you need modify the g_APinDescription[] array in the variant.cpp file. This file also configures the available timers: TCC0, TCC1, etc...

The pin assignments of the SPI/I2C/Serial sercom (serial communciation) modules are defined in the "variant.h" file.

For example to assign additional pins to the larger 64-pin SAMD21J18A to the "variant.cpp" file, I just appended them to end of the g_APinDescription[] array and also added the additional TC6 and TC7 timers:

// SAMD21J18A Pins...
 
// 44..47 - Analog pins
{ PORTB,  4, PIO_ANALOG, 0, ADC_Channel12, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4 }, // ADC/AIN[12]
{ PORTB,  5, PIO_ANALOG, 0, ADC_Channel13, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 }, // ADC/AIN[13]
{ PORTB,  6, PIO_ANALOG, 0, ADC_Channel14, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6 }, // ADC/AIN[14]
{ PORTB,  7, PIO_ANALOG, 0, ADC_Channel15, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // ADC/AIN[15]
 
// 48..51 - Digital pins
{ PORTB,  12, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, 
{ PORTB,  13, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13 }, 
{ PORTB,  14, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14 }, 
{ PORTB,  15, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_15 }, 
 
// 52..53 - SERCOM/UART (Serial1)
{ PORTB, 16, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_0 }, // TX: SERCOM5/PAD[0]
{ PORTB, 17, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1 }, // RX: SERCOM5/PAD[1]
 
// 54..55 - Digital pins
{ PORTB,  30, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14 }, 
{ PORTB,  31, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_15 }, 
 
 // 56..57 - Analog pins
{ PORTB,  0, PIO_ANALOG, 0, ADC_Channel8, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_0 }, // ADC/AIN[8]
{ PORTB,  1, PIO_ANALOG, 0, ADC_Channel9, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1 }, // ADC/AIN[9]
 
 // 58..59 - SERCOM/UART (Serial2)
{ PORTA, 12, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // TX: SERCOM2/PAD[0]
{ PORTA, 13, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13 }, // RX: SERCOM2/PAD[1]
} ;

const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM]={ TCC0, TCC1, TCC2, TC3, TC4, TC5, TC6, TC7 } ;

I'm designing a SAMD21G18 (zero based) bareboard and I'm willing to use more pins than the 13 digital + 6 analog pins that are available on the development board.

Note that the normal Arduino-UnoR3-like SAMD21 boards usually DO have more than the 14+6 IO pins.
Unlike the AVR Uno, the I2C (2pins) and SPI (3pins) are likely to be independent. Five more pins go to USB and its associated Tx/Rx LEDs. JTAG (SWD - two pins) might be broken out so that you can attach a debugger. AREF is probably re-configurable as IO...
Sparkfun has a samd21g breakout where ALL of the pins are connected somewhere. Not counting the ones I mention above, there are only three additional pins.

Thanks a lot!

I shall try this as soon as I'm able to!