2nd I2C channel on zero?

Is it possible to use a different i2c channel in addition to the one connected to pin 9 and 10 on zero? The SAMD21 chip has 4 i2c channels so in terms of hardware, I think its quite possible. Not sure about the software driver part. Any one experienced? or Any idea how can I do that?

Thanks

I have no experience with the Zero or SAMD in general. If you look at the source of the Arduino SAMD Boards' Wire library

you can see it's written to support up to 6 channels:

#if WIRE_INTERFACES_COUNT > 0
  extern TwoWire Wire;
#endif
#if WIRE_INTERFACES_COUNT > 1
  extern TwoWire Wire1;
#endif
#if WIRE_INTERFACES_COUNT > 2
  extern TwoWire Wire2;
#endif
#if WIRE_INTERFACES_COUNT > 3
  extern TwoWire Wire3;
#endif
#if WIRE_INTERFACES_COUNT > 4
  extern TwoWire Wire4;
#endif
#if WIRE_INTERFACES_COUNT > 5
  extern TwoWire Wire5;
#endif

so you would just be able to use the standard Wire library functions prepended by Wire1, Wire2, Wire3 instead of Wire just as documented in the reference.

However, if you look at the variant file for the Zero

only one is enabled:

#define WIRE_INTERFACES_COUNT 1

The only variant with more than one (2) is the Circuit Playground board.

Is the reason that those pins aren't broken out on the boards?

So the quick hack would be to simply change the value of WIRE_INTERFACES_COUNT in variant.h and see if it works. The real way to do it would be to create your own hardware core that references the Arduino SAMD Boards package for as many components as possible but contains its own board definition and variant. There are already a couple of these sort of hardware packages in existence that could be used as a model, and in fact it could be worth checking if any of them are configured for more I2C channels.

Hi robot9,

Yes it's possible to create a second I2C channel, using one of the SAMD21's spare SERCOM (Serial Communication) modules.

It's detailed in this Adafruit tutorial: Creating a new Wire | Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports | Adafruit Learning System.

MartinL:
Hi robot9,

Yes it's possible to create a second I2C channel, using one of the SAMD21's spare SERCOM (Serial Communication) modules.

It's detailed in this Adafruit tutorial: Creating a new Wire | Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports | Adafruit Learning System.

The Tutorial you referenced is for Adafruit Feather which is a different variant from the Arduino Zero.

You are assuming that on the Arduino Zero the extra I2C pins are brought out to board pins.

As far as I know the Arduino Due is the only board with more than one i2c channel.
I have done some more checking and the below tutorial may be what you need to pursue.

https://www.arduino.cc/en/Tutorial/SamdSercom

I have not attempted it. I may have to try it in the future.

The Adafruit tutorial is valid for any board that uses the SAMD21... Doesn't matter if it's an Adafruit Feather, Arduino Zero or a Sparkfun SAMD21 Breakout board. If you read the whole tutorial it shows you how to get additional SPI, Serial and I2C ports.

Thanks guys. I got it working. Both the Adafruit and Arduino tutorials were helpful.

That's what I found about zero:

There are 6 sercom channels as follows,
S0-> Configured for Serial1 (Pin 0 and 1)
S1-> Spare
S2-> Spare
S3-> Default I2C ports
S4-> Default SPI (SPI/ICSP Header)
S5-> Configured for Serial (Debug port)

I used Sercom1 to create additional Wire and it worked on pin 35 and 37 but not on 11 and 13. I also tried Sercom2 on pins 3 and 4 but it didn't work. Any ideas?

Hi robot9,

In your code are you calling the pinPeripheral() function after myWire.begin()?

Have you used the pinPeripheral() function with the PIO_SERCOM_ALT argument for pins 3 and 4? As SERCOM2 is the alternative Sercom option on these pins.