SparkFun Forums 

Where electronics enthusiasts find answers.

Hi to all,
For my new project I need to reconfigure the SERCOMs to get three UART and three I2C buses.

I have been following these guides: ... a-new-wire

The three UART work, however I cannot get the secondary Wire to work.
The hardware is a Sparkfun SAMD21 Mini and three BME280 sensors, connected to pins as follows, with 4k7 pullups (SDA, SCL): (A4, A5), (4, 3), (11, 13)
I carefully selected the pins out of the table in the SAMD21 datasheet, they should be correct.
The first bus is default and works, the 2nd is on SERCOM0 and the 3rd on SERCOM1.

This is the test code for a single Wire:
Code: Select all
#include "wiring_private.h" // pinPeripheral() function
#include <Wire.h>
#include <SparkFunBME280.h>

TwoWire myWire(&sercom0, 4, 3);

BME280 bme1; // I2C

void SERCOM0_Handler(void);

void SERCOM0_Handler(void) {

void setup() {
  // put your setup code here, to run once:
  while (!SerialUSB) {
    ; // wait for serial port to connect

  SerialUSB.println("SAMD21 Test Initialization");

   SerialUSB.println("Initializing I2C on pin 4, 3");

  pinPeripheral(3, PIO_SERCOM);
  pinPeripheral(4, PIO_SERCOM);
  SerialUSB.println("Inizialized, looking for sensor");
   if(bme1.beginI2C(myWire) == false) {
    SerialUSB.println("Sensor NOT found!");
  } else {
    SerialUSB.println("Sensor found");

void loop() {
  // put your main code here, to run repeatedly:
    SerialUSB.print("Sensor 2 temp: ");
    SerialUSB.println(bme1.readTempC(), 2);
The sketch will be stuck at "Inizialized, looking for sensor".
Tried to do the same with Adafrult BME280 library, still stuck.
If I run the I2C scanner code, the device is correctly found at address 0x77 so at least something is clicking.

Need to change anything in variants.cpp / variants.h?
Any other advice?

Thank you!

Looks like we've added our own tutorial on this since you posted. Feel free to check this out. I ended up using those pins in my example, but on Sercom 2. Also it looks like you don't need the Handler Function for this. Let us know if you were able to figure this out or if you have any other questions. ... amd-boards