Trellis and Multiple I2C ports

Status
Not open for further replies.

Paula

Active member
Hi everyone,

I'm new to Teensy and Arduino and so far I'm really impressed.
I'm an electronics engineer and used to writing assembly and C, but I've ot myself a teensy 3.6 to have a play with without all the faff of writing low level drivers.

Anyway, I've managed to get myself a Teensy 3.6 hooked up to 8 of the Adafruit Trellis PCBs via a level shifter and it's working great.
What I want to do now is use the other I2C busses (well at least one, if not two), I want to use one of them for the 3 axis accelerometer.
I've read up and know that I should be using the "i2c_t3" library in place of the "wire" library, but when I swap "#include <wire.h>" for "#include <i2c_t3.h>" I get the following errors ;

Arduino: 1.8.1 (Mac OS X), TD: 1.35, Board: "Teensy 3.6, Serial, 180 MHz, Fast, US English"

In file included from /Users/Paula/Documents/Arduino/libraries/Adafruit_Trellis_Library-master/Adafruit_Trellis.h:35:0,
from /Users/Paula/Dropbox/Projects/Nexus/TrellisTest/TrellisTest.ino:20:
/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/Wire/Wire.h:104:16: error: conflicting declaration 'TwoWire Wire'
extern TwoWire Wire;
^
In file included from /Users/Paula/Dropbox/Projects/Nexus/TrellisTest/TrellisTest.ino:19:0:
/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/i2c_t3/i2c_t3.h:987:15: error: 'Wire' has a previous declaration as 'i2c_t3 Wire'
extern i2c_t3 Wire;
^
Error compiling for board Teensy 3.6.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Digging a little deeper it seems the trellis libraries have the 'wire.h' library hardwired in.
Is there a way around this?

Many thanks in advance
Paula
 
Generally you have to clone all of the libraries that you use that use Wire.h to be named differently, and then in the renamed files, change the "Wire.h" to "i2c_t3.h". Then change your main program to use the cloned libraries as well. Also, possibly change "Wire" to "Wire1" if you want to use the secondary i2c port.

On the Teensy, you will need pull-up resistors between each of the SDA/SCL pins that you use and 3.3v, unless your device already has pull-up resistors. Typically 2.2K or 2.4K resistors are recommended for simple i2c buses with short wires on 3.3v systems.
 
Last edited:
You can also connect two sets of I2C devices (or even more on Teensy 3.6) to the normal Wire lib using the alternate SDA & SCL pins. Just use Wire.setSCL(pin) and Wire.setSDA(pin) to switch the wire lib to the other pins. Of course, each pin needs a real pullup resistor.
 
Thanks, modifying the adafruit .h and .cpp files did it, I thought I'd tried this but clearly I hadn't. it's now compiling and seems to be working.
I'll add in the second I2C line tomorrow :)
 
Status
Not open for further replies.
Back
Top