How can I add an extra I2C interface to SODAQ ONE?

Hello all,

I would be interested on adding an extra I2C port to the current pins of SODAQ ONE, I have found these nice examples of @GabrielNotman for the UARTs, and based on that I have tried to add my own new I2C interface.

I would like to replace A9 and A8 analog pins for the new I2C interface called Wire1, so far I have modified my variant.cpp and variant.h to include such a mapping, could you tell me if I am in the right direction?

My main doubts come how to mapp pins A8/A9 to PIN_WIRE1_SDA and PIN_WIRE1_SCL, looking into the schematic I see that A9 and A8 are attached to SAMD pins 14 and 13, so I wonder if my mapping is right in variant.h

Finally, where should I include my macro SECOND_I2C that enables the usage of those new pins?

Thank you very much,

Regards!

Snippet of variant.h, I will reuse sercom4 that it seems free

#ifdef SECOND_I2C
#define PINS_COUNT           (47u)
#define NUM_DIGITAL_PINS     (12u)    // Without the "other" Digital Pins
#define NUM_ANALOG_INPUTS    (10u)    // Without the "other" Analog Pins
#else
#define PINS_COUNT           (49u)
#define NUM_DIGITAL_PINS     (12u)    // Without the "other" Digital Pins
#define NUM_ANALOG_INPUTS    (12u)    // Without the "other" Analog Pins
#endif
#define NUM_ANALOG_OUTPUTS   (1u)
...
static const uint8_t A7  = PIN_A7 ;
#ifndef SECOND_I2C
static const uint8_t A8  = PIN_A8 ;
static const uint8_t A9  = PIN_A9 ;
#endif
static const uint8_t A10 = PIN_A10;
...
/*
 * Wire Interfaces
 */
#ifdef SECOND_I2C

#define WIRE_INTERFACES_COUNT 2

#define PIN_WIRE_SDA         (47u)
#define PIN_WIRE_SCL         (48u)
#define PERIPH_WIRE          sercom3
#define WIRE_IT_HANDLER      SERCOM3_Handler

#define PIN_WIRE1_SDA         (13u)
#define PIN_WIRE1_SCL         (14u)
#define PERIPH_WIRE1          sercom4
#define WIRE1_IT_HANDLER      SERCOM4_Handler

#define WIRE_INTERFACES_COUNT 2
#else

#define WIRE_INTERFACES_COUNT 1

#define PIN_WIRE_SDA         (47u)
#define PIN_WIRE_SCL         (48u)
#define PERIPH_WIRE          sercom3
#define WIRE_IT_HANDLER      SERCOM3_Handler

#endif
...

My variant.cpp

...
  { PORTA, 2,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel0,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    },
  { PORTA, 3,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel1,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3    },
#ifndef SECOND_I2C
  { PORTB, 8,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel2,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_8    },
  { PORTB, 9,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel3,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    },
#endif
  { PORTA, 6,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel6,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6    },
...
  // 47..48 I2C
  { PORTA, 22, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6    }, // I2C_SDA
  { PORTA, 23, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7    }, // I2C_SCL
#ifdef SECOND_I2C
  { PORTB, 8,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_8    }, //I2C_SCL
  { PORTB, 9,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    }, //I2C_SDA
#endif
...

and finally Wire.cpp

...
#if WIRE_INTERFACES_COUNT > 1
  /*Defined second I2C
   */
#ifndef PERIPH_WIRE1
  #define PERIPH_WIRE1          sercom4
  #define WIRE1_IT_HANDLER      SERCOM4_Handler
#endif // PERIPH_WIRE1
  TwoWire Wire1(&PERIPH_WIRE1, PIN_WIRE1_SDA, PIN_WIRE1_SCL);
  void WIRE1_IT_HANDLER(void) {
    Wire1.onService();
  }
#endif
...

This is quite a complicated process.

A few notes:

  • You will need to create a variant description in order to specify compiler directives.
  • You don’t need to modify the Wire source files.
  • You don’t need to remove the descriptions for A8 and A9, the pins can have multiple mapped uses and could still be used as analog inputs if that second I2C bus isn’t in use.
  • I wouldn’t add or remove pin descriptions from anywhere but the end of the array in Variant.cpp. Doing so will throw off the indices for other pins and cause lots of issues.

I have not checked your entries, but what is required is that you specify the SDA and SCL pin entries and map them to the correct sercom (including interrupt handler).

@GabrielNotman thanks for replying,

I have done as told, I have just reverted to the original state and I have added this into Variant.cpp

   // 47..48 I2C
  { PORTA, 22, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6    }, // I2C_SDA
  { PORTA, 23, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7    }, // I2C_SCL
#ifdef SECOND_I2C
  { PORTB, 8,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_8    }, //I2C_SCL
  { PORTB, 9,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    }, //I2C_SDA
#endif

and in variant.h

#define WIRE_INTERFACES_COUNT 2

#define PIN_WIRE_SDA         (47u)
#define PIN_WIRE_SCL         (48u)
#define PERIPH_WIRE          sercom3
#define WIRE_IT_HANDLER      SERCOM3_Handler

#define PIN_WIRE1_SDA         (13u)
#define PIN_WIRE1_SCL         (14u)
#define PERIPH_WIRE1          sercom4
#define WIRE1_IT_HANDLER      SERCOM4_Handler

#define WIRE_INTERFACES_COUNT 2

Still I have the doubt if 13u and 14u are the right pins in the MCU or not, how can I check that?

The indices for PIN_WIRE1_* seem to be incorrect (you are referencing 13/14 and you should be referencing 49/50).

More importantly, though A8 (PORTB8) & A9 (PORTB9) do not support I2C.

See p.21 in the datasheet:

Where are these indices defined? This will also imply that my PINS_COUNT would be 51u.

Looking the pins here suggested me that they were, AIN16 and AIN17, then I have to move to

  { PORTA, 8,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NMI    }, //I2C_SCL
  { PORTA, 9,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    }, //I2C_SDA

but I see that in that SERCOM the serial is as well there, wouldn’t it be a problem?

thanks!

Can I ask why you need a second I2C bus? Do you have a device address conflict?

The indices refer to the entry location within the description array located in Variant.cpp. The array is 0 indexed, with 51 entries after your additions. Since your additions are at the end of the array, they will have indicies 49 & 50.

PORTA8 & PORTA9 can use either Sercom0 or Sercom2 (ALT). You will need to check which Sercoms are already in use for the existing UART, SPI and I2C buses.

Yeah sure, I would like to discern between my internal components, like GPS and accelerometer and the external ones connected to the board, sensors mostly, thus I would like to have two I2C buses for that.

Ok I understand that now, thanks!

I’ve checked and sercom 0 is reserverd for SPI whereas sercom2 is serial1 (LoRa), being the available sercoms 1 and 4, would it be possible to re-use sercom0 if I don’t make use of SPI?

You could try this:

{ PORTA, 8, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NMI }, //I2C_SCL
{ PORTA, 9, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9 }, //I2C_SDA

and this:

#define PIN_WIRE1_SDA         (49u)
#define PIN_WIRE1_SCL         (50u)
#define PERIPH_WIRE1          sercom0
#define WIRE1_IT_HANDLER      SERCOM0_Handler

These pins are currently also mapped for use with SPI (using Sercom0). Adding these lines will allow you to use Wire1 or SPI, but not both at the same time. Sercom2 is also available on those pins, however, Sercom2 is used by Serial1 (LoRa) on PA12 & PA13.

Thanks @GabrielNotman I will try so. I have as well a definition (SECOND_I2C) to control the usage of the second I2C, should I include that in the variant.h file as well? And for compiling this version of the software, should I do something more? As you mention before, I have to specify some compiler directives haven’t I?

Yes I see that sercom2 is for LoRa, which I would need, so I won’t touch that interface.

Off topic: is this the same way to create a new serial on the board?

Thanks again!

The first i2c bus will use the Wire instance, the second bus will use Wire1 etc.

If you are using a device on the second i2c bus, you will need to change your code to reference Wire1 instead of Wire.

Thanks @GabrielNotman, I am doing so, the weird thing is that one of the sensor seems to work in the new bus, but the other doesn’t, it seems to hang :S

On the hardware side the i2c bus requires pull-up resistors. The ones on the existing bus (on the SodaqOne) are 3k resistors. Some external devices will have their own pull-ups, others don’t.

I connected the same sensor to the other I2C interface and it worked fine, also, I used a BME280 in this interface and it seems to be working, I have enabled some debug, and apparently when starting the ACC in the SODAQ something goes wrong…

I am using this driver , I see that if I change the wire interface into wire1 on the Adafruit_TSL2561_U.cpp something seems to mess up.

The existing bus has 3k pull-up resistors attached. The BME280 may have its own pull-up resistors on the i2c lines.

If you have a DMM take a reading of the i2c lines on Wire1. When idle, you should read 3.3V.

Without the pull-up resistors, there will be signalling issues (data etc) between the master and the slave devices. The library may get stuck waiting for specific data to arrive.

I have checked it, it doesn’t have 3k pull-up attached nor the other sensor, I will try to read to see if I have 3.3V

I have included some trace, and I see that the accelerometer takes more time to start, I have this

     debugSerial.println("DEBUG: ACC");
     sodaq_wdt_safe_delay(STARTUP_DELAY*10);
     //starting up Accelerometer
     initMovementDetected();
    ` ...`
 void initMovementDetected() {
SerialUSB.print("DEBUG: enabling ACC ...");

  accelerometer.enable(true, LIS3DE::NormalLowPower10Hz, LIS3DE::XYZ, LIS3DE::Scale2g, true);
  //sodaq_wdt_safe_delay(100);//Original

  sodaq_wdt_safe_delay(200);

 SerialUSB.print("DEBUG: ACC enabled");
 ...}

Serial shows

DEBUG: BEFORE TIMER
DEBUG: ACC
DEBUG: enabling ACC ...

So it seems to get stack enabling the ACC?

If you remove the other device, does it work correctly?

RYes, If I remove TLS2561 it does work for the bme280. Actually more than removing why I am doing is uaing just wire in the library that I told in the previous post, instead of wire1.

Then the setup process completes normally and the setup for the acc is done.

Why is the acc affected if it is connected in a different I2C bus?

Without seeing all of the modifications you have made, it is difficult to tell.

Remember that the accelerometer still remains on the primary bus WIRE.

Hi @GabrielNotman
I followed your suggestions, I only changed the variant.h and variant.cpp where I added the new I2C , my files are these

variant.h

#ifndef _VARIANT_SODAQ_ONE_
#define _VARIANT_SODAQ_ONE_

// The definitions here needs a SAMD core >=1.6.3
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10603

/*----------------------------------------------------------------------------
 *        Definitions
 *----------------------------------------------------------------------------*/

/** Frequency of the board main oscillator */
#define VARIANT_MAINOSC       (32768ul)

/** Master clock frequency */
#define VARIANT_MCK           (48000000ul)

/*----------------------------------------------------------------------------
 *        Headers
 *----------------------------------------------------------------------------*/

#include "WVariant.h"


#ifdef __cplusplus
#include "SERCOM.h"
#include "Uart.h"
#endif // __cplusplus

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

/*----------------------------------------------------------------------------
 *        Pins
 *----------------------------------------------------------------------------*/

// Number of pins defined in PinDescription array
#ifdef SECOND_I2C
#define PINS_COUNT           (51u)
#define NUM_DIGITAL_PINS     (12u)    // Without the "other" Digital Pins
#define NUM_ANALOG_INPUTS    (12u)    // Without the "other" Analog Pins
#else
#define PINS_COUNT           (49u)
#define NUM_DIGITAL_PINS     (12u)    // Without the "other" Digital Pins
#define NUM_ANALOG_INPUTS    (12u)    // Without the "other" Analog Pins
#endif
#define NUM_ANALOG_OUTPUTS   (1u)

#define digitalPinToPort(P)        ( &(PORT->Group[g_APinDescription[P].ulPort]) )
#define digitalPinToBitMask(P)     ( 1 << g_APinDescription[P].ulPin )
//#define analogInPinToBit(P)        ( )
#define portOutputRegister(port)   ( &(port->OUT.reg) )
#define portInputRegister(port)    ( &(port->IN.reg) )
#define portModeRegister(port)     ( &(port->DIR.reg) )
#define digitalPinHasPWM(P)        ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER )

/*
 * digitalPinToTimer(..) is AVR-specific and is not defined for SAMD
 * architecture. If you need to check if a pin supports PWM you must
 * use digitalPinHasPWM(..).
 *
 * https://github.com/arduino/Arduino/issues/1833
 */
// #define digitalPinToTimer(P)

// Interrupts
#define digitalPinToInterrupt(P)   ( g_APinDescription[P].ulExtInt )

// LEDs
#define PIN_LED_RED          (14u)
#define PIN_LED_GREEN        (15u)
#define PIN_LED_BLUE         (16u)

/*
 * Analog pins
 */
#define PIN_A0               (22u)
#define PIN_A1               (PIN_A0 + 1)
#define PIN_A2               (PIN_A0 + 2)
#define PIN_A3               (PIN_A0 + 3)
#define PIN_A6               (PIN_A0 + 4)
#define PIN_A7               (PIN_A0 + 5)
#define PIN_A8               (PIN_A0 + 6)
#define PIN_A9               (PIN_A0 + 7)
#define PIN_A10              (PIN_A0 + 8)
#define PIN_A11              (PIN_A0 + 9)
#define PIN_A12              (PIN_A0 + 10)
#define PIN_A13              (PIN_A0 + 11)

static const uint8_t A0  = PIN_A0 ;
static const uint8_t A1  = PIN_A1 ;
static const uint8_t A2  = PIN_A2 ;
static const uint8_t A3  = PIN_A3 ;
static const uint8_t A6  = PIN_A6 ;
static const uint8_t A7  = PIN_A7 ;
static const uint8_t A8  = PIN_A8 ;
static const uint8_t A9  = PIN_A9 ;
static const uint8_t A10 = PIN_A10;
static const uint8_t A11 = PIN_A11;
static const uint8_t A12 = PIN_A12;
static const uint8_t A13 = PIN_A13;
#define ADC_RESOLUTION      12

/*
 * Serial interfaces
 */
// Serial
#define PIN_SERIAL_RX       (39u)
#define PIN_SERIAL_TX       (40u)
#define PAD_SERIAL_TX       (UART_TX_PAD_0)
#define PAD_SERIAL_RX       (SERCOM_RX_PAD_1)

// Serial1
#define PIN_SERIAL1_RX      (41u)
#define PIN_SERIAL1_TX      (42u)
#define PAD_SERIAL1_TX      (UART_TX_PAD_0)
#define PAD_SERIAL1_RX      (SERCOM_RX_PAD_1)

// Other Digital Pins
static const uint8_t LED_RED       = PIN_LED_RED;
static const uint8_t LED_GREEN     = PIN_LED_GREEN;
static const uint8_t LED_BLUE      = PIN_LED_BLUE;
static const uint8_t GPS_TIMEPULSE = (17u);
static const uint8_t GPS_ENABLE    = (18u);
static const uint8_t BUTTON        = (19u);
static const uint8_t ACCEL_INT1    = (4u);
static const uint8_t ACCEL_INT2    = (5u);
static const uint8_t ENABLE_PIN_IO = (20u);
static const uint8_t SWITCH_SENSE  = (21u);

// Other Analog Pins
static const uint8_t DAC0          = PIN_A0; // or (24u) implications for cores/arduino/wiring_analog.c analogWrite()
static const uint8_t AREF          = (35u);
static const uint8_t BAT_VOLT      = (36u);

/*
 * SPI Interfaces
 */
#define SPI_INTERFACES_COUNT 1

#define PIN_SPI_MISO         (43u)
#define PIN_SPI_SS           (44u)
#define PIN_SPI_MOSI         (45u)
#define PIN_SPI_SCK          (46u)
#define PERIPH_SPI           sercom0
#define PAD_SPI_TX           SPI_PAD_2_SCK_3
#define PAD_SPI_RX           SERCOM_RX_PAD_0

static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SS   = PIN_SPI_SS ;
static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t SCK  = PIN_SPI_SCK ;

/*
 * Wire Interfaces
 */
#ifdef SECOND_I2C

#define WIRE_INTERFACES_COUNT 2

#define PIN_WIRE_SDA         (47u)
#define PIN_WIRE_SCL         (48u)
#define PERIPH_WIRE          sercom3
#define WIRE_IT_HANDLER      SERCOM3_Handler

#define PIN_WIRE1_SDA         (49u)
#define PIN_WIRE1_SCL         (50u)
#define PERIPH_WIRE1          sercom0
#define WIRE1_IT_HANDLER      SERCOM0_Handler

#define WIRE_INTERFACES_COUNT 2
#else

#define WIRE_INTERFACES_COUNT 1

#define PIN_WIRE_SDA         (47u)
#define PIN_WIRE_SCL         (48u)
#define PERIPH_WIRE          sercom3
#define WIRE_IT_HANDLER      SERCOM3_Handler

#endif

/*
 * USB
 */
#define PIN_USB_DM          (38ul)
#define PIN_USB_DP          (39ul)

#ifdef __cplusplus
}
#endif

/*----------------------------------------------------------------------------
 *        Arduino objects - C++ only
 *----------------------------------------------------------------------------*/

#ifdef __cplusplus

/*  =========================
 *  ===== SERCOM DEFINITION
 *  =========================
*/
extern SERCOM sercom0;
extern SERCOM sercom1;
extern SERCOM sercom2;
extern SERCOM sercom3;
extern SERCOM sercom4;
extern SERCOM sercom5;


extern Uart Serial;
extern Uart Serial1;

#endif

// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use.  For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR        Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL     Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE    Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE       Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN  Hardware serial ports which are open for use.  Their RX & TX
//                            pins are NOT connected to anything by default.
#define SERIAL_PORT_USBVIRTUAL      SerialUSB
#define SERIAL_PORT_MONITOR         SerialUSB

// Serial has no physical pins broken out, so it's not listed as HARDWARE port
#define SERIAL_PORT_HARDWARE        Serial
#define SERIAL_PORT_HARDWARE_OPEN   Serial

#define SERIAL_PORT_HARDWARE1       Serial1
#define SERIAL_PORT_HARDWARE_OPEN1  Serial1

#endif /* _VARIANT_SODAQ_ONE_ */

variant.cpp

#include "variant.h"

/*
 * Pins descriptions
 */
const PinDescription g_APinDescription[]=
{
  // 0..3 Main IO Pins (D0-D3) Digital Properties
  { PORTA, 2,  PIO_DIGITAL,    (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    },
  { PORTA, 3,  PIO_DIGITAL,    (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3    },
  { PORTB, 8,  PIO_TIMER,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM4_CH0,   TC4_CH0,      EXTERNAL_INT_8    }, // TC4/WO[0]
  { PORTB, 9,  PIO_TIMER,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM4_CH1,   TC4_CH1,      EXTERNAL_INT_9    }, // TC4/WO[1]

  // 4..5 Other Digital Pins
  { PORTA, 21, PIO_INPUT,      (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5    }, // ACCEL_INT1
  { PORTA, 20, PIO_INPUT,      (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_4    }, // ACCEL_INT2

  // 6..13 Main IO Pins (D6-D13) Digital Properties
  { PORTA, 6,  PIO_TIMER,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM1_CH0,   TCC1_CH0,     EXTERNAL_INT_6    }, // TCC1/WO[0]
  { PORTA, 7,  PIO_TIMER,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM1_CH1,   TCC1_CH1,     EXTERNAL_INT_7    }, // TCC1/WO[1]
  { PORTA, 8,  PIO_TIMER,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM0_CH0,   TCC0_CH0,     EXTERNAL_INT_NMI  }, // TCC0/WO[0]
  { PORTA, 9,  PIO_TIMER,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM0_CH1,   TCC0_CH1,     EXTERNAL_INT_9    }, // TCC0/WO[1]
  { PORTA, 10, PIO_TIMER_ALT,  (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH2,   TCC0_CH2,     EXTERNAL_INT_10   }, // TCC0/WO[2]
  { PORTA, 11, PIO_TIMER_ALT,  (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH3,   TCC0_CH3,     EXTERNAL_INT_11   }, // TCC0/WO[3]
  { PORTB, 2,  PIO_DIGITAL,    (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    },
  { PORTB, 3,  PIO_DIGITAL,    (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3    },

  // 14..21 Other Digital Pins
  { PORTA, 15, PIO_INPUT,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM3_CH1,   TC3_CH1,      EXTERNAL_INT_NONE }, // LED_RED
  { PORTB, 10, PIO_INPUT,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM5_CH0,   TC5_CH0,      EXTERNAL_INT_NONE }, // LED_GREEN
  { PORTB, 11, PIO_INPUT,      (PIN_ATTR_DIGITAL | PIN_ATTR_PWM | PIN_ATTR_TIMER),     No_ADC_Channel, PWM5_CH1,   TC5_CH1,      EXTERNAL_INT_NONE }, // LED_BLUE
  { PORTA, 14, PIO_INPUT,      (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14   }, // GPS_TIMEPULSE
  { PORTA, 18, PIO_OUTPUT,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // GPS_ENABLE
  { PORTA, 16, PIO_INPUT,      (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_0    }, // BUTTON
  { PORTB, 22, PIO_OUTPUT,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // ENABLE_PIN_IO
  { PORTA, 17, PIO_INPUT,      (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1    }, // SWITCH_SENSE

  // 22..33 Main IO Pins Analog Properties
  { PORTA, 2,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel0,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    },
  { PORTA, 3,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel1,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3    },
  { PORTB, 8,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel2,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_8    },
  { PORTB, 9,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel3,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    },
  { PORTA, 6,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel6,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6    },
  { PORTA, 7,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel7,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7    },
  { PORTA, 8,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel16,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NMI  },
  { PORTA, 9,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel17,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    },
  { PORTA, 10, PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel18,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10   },
  { PORTA, 11, PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel19,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11   },
  { PORTB, 2,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel10,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    },
  { PORTB, 3,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel11,  NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3    },

  // 34..36 Other Analog Pins
  { PORTA, 2,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      DAC_Channel0,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    }, // DAC/VOUT
  { PORTA, 3,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel1,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // AREF
  { PORTA, 5,  PIO_ANALOG,     (PIN_ATTR_ANALOG),                                      ADC_Channel5,   NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // BAT_VOLT
  
  // 37..38 USB Pins
  { PORTA, 24, PIO_COM,        (PIN_ATTR_NONE),                                        No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB_N
  { PORTA, 25, PIO_COM,        (PIN_ATTR_NONE),                                        No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB_P

  // 39..40 Serial
  { PORTB, 3,  PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3    }, // SERIAL_RX
  { PORTB, 2,  PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2    }, // SERIAL_TX

  // 41..42 Serial1
  { PORTA, 13, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_13   }, // SERIAL1_RX
  { PORTA, 12, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12   }, // SERIAL1_TX

  // 43..46 SPI 
  { PORTA, 8,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NMI  }, // SPI_MISO
  { PORTA, 9,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    }, // SPI_SS
  { PORTA, 10, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10   }, // SPI_MOSI
#ifdef ENABLE_BASE_SPI
  { PORTA, 7,  PIO_SERCOM_ALT, (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7    }, // SPI_SCK
#else
  { PORTA, 11, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11   }, // SPI_SCK
#endif

  // 47..48 I2C
  { PORTA, 22, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_6    }, // I2C_SDA
  { PORTA, 23, PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7    }, // I2C_SCL
#ifdef SECOND_I2C
  // 49...50 SECOND I2C
  { PORTA, 8,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NMI    }, //I2C_SCL
  { PORTA, 9,  PIO_SERCOM,     (PIN_ATTR_DIGITAL),                                     No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_9    }, //I2C_SDA
#endif
} ;

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

// Multi-serial objects instantiation
SERCOM sercom0( SERCOM0 ) ;    // SPI + Second I2C
SERCOM sercom1( SERCOM1 ) ;
SERCOM sercom2( SERCOM2 ) ;    // Serial1
SERCOM sercom3( SERCOM3 ) ;    // I2C
SERCOM sercom4( SERCOM4 ) ;
SERCOM sercom5( SERCOM5 ) ;    // Serial

Uart Serial(&sercom5, PIN_SERIAL_RX, PIN_SERIAL_TX, PAD_SERIAL_RX, PAD_SERIAL_TX ) ;
Uart Serial1(&sercom2, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX);

void SERCOM2_Handler()
{
  Serial1.IrqHandler();
}

void SERCOM5_Handler()
{
  Serial.IrqHandler();
}

And finanally to compile it, I have added the definition SECOND_I2C to the compiler in the boards.txt file for sodaq one

# SODAQ ONE
# ---------------------------------------
sodaq_one.name=SODAQ ONE
sodaq_one.vid.0=0x2341
sodaq_one.pid.0=0x804d
sodaq_one.vid.1=0x2341
sodaq_one.pid.1=0x004d
sodaq_one.upload.tool=bossac
sodaq_one.upload.protocol=sam-ba
sodaq_one.upload.maximum_size=262144
sodaq_one.upload.use_1200bps_touch=true
sodaq_one.upload.wait_for_upload_port=true
sodaq_one.upload.native_usb=true
sodaq_one.build.mcu=cortex-m0plus
sodaq_one.build.f_cpu=48000000L
sodaq_one.build.usb_product="SODAQ ONE"
sodaq_one.build.usb_manufacturer="SODAQ"
sodaq_one.build.board=SODAQ_ONE
sodaq_one.build.core=arduino
sodaq_one.build.extra_flags=-D__SAMD21G18A__ {build.usb_flags} -DSECOND_I2C
sodaq_one.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
sodaq_one.build.openocdscript=openocd_scripts/sodaq_one.cfg
sodaq_one.build.variant=sodaq_one
sodaq_one.build.variant_system_lib=
sodaq_one.build.vid=0x2341
sodaq_one.build.pid=0x804d
sodaq_one.bootloader.tool=openocd
sodaq_one.bootloader.file=zero/samd21_sam_ba.bin

That’s it, where am I doing a mistake?

Thanks