• TrillSolved
  • teensy 4.1 i2c communication on pin 44 and 45

hi there,

I want to connect a trill ring (and an OLED) to the i2c port on PIN 44 and 45 on a teensy 4.1

since I really need all 18 analog inputs, I cannot use the standard i2c pins (Wire "0"), but have to resort to Wire 1...

is it not too much trouble to change the library to use Wire1 or is it a deep rabbit hole? (I mean doing the changes locally at my side)

It should be enough to replace the #include <Wire.h> in the library files Trill.cpp with #include <Wire1.h>. See more details here, section "Use of Other I2C Ports".

hmm, that did not work...

 /Users/lokki/Documents/Arduino/libraries/Trill-Arduino-master/Trill.h:19:10: fatal error: Wire1.h: No such file or directory
   19 | #include "Wire1.h"
      |          ^~~~~~~~~
compilation terminated. </code>

the file to edit is Trill.h I guess, Trill.cpp has no Wire.h include...

I think teensy has no wire1.h file, it is all included in wire...

I take this conclusion because I can use

Wire1.setSDA(PIN_SDA);
  Wire1.setSCL(PIN_SCL);

in setup with no problem, also I have other teensy projects with 4 OLED screens , that use the second i2c interface without Wire1 include...

Oh that's it then. Just replace all instances of Wire with Wire1
Or better put at the top of Trill.cpp, after the Trill.h include:

#define Wire Wire1

haha, no kidding that is what I just did now and wanted to report here :-) I took the replace approach but will do the define approach, since it is easier to see and reverse back if I need Wire for another project.

EDIT: will only be able to test this actually works in about one or two weeks when all other parts arrive.

Thanks

13 days later

ok, I can confirm that doing a #define Wire Wire1at the beginning of Trill.cpp and Wire1.setSDA(44);
Wire1.setSCL(45);
in setup() of the teensy sketch works flawlessly!

8 months later

I just updated to Trill 1.1. library and this "hack" does no longer work. I also tried not using it (since I thought you may have fixed it) but it does still not work.

Also not on 1.1.3

And now I cannot downgrade to 1.0.0 anymore because I get "Failed to install library: 'Trill:1.0.0'. No valid dependencies solution found: dependency 'Wire' is not available" in the Arduino IDE...arghh..

Hmm the updated trill library - which you can now install through the arduino ide - allows to set a custom Wire object by passing it as an argument to begin(). Try thay instead of the hack?

so I would need to add what to use Wire1 instead of Wire?

I tried: trillSensor.begin(255,Wire1); and trillSensor.begin(Wire1); both of which give me an error:

"cannot convert 'TwoWire' to 'uint8_t' {aka 'unsigned char'}"

ok I can see now, that begin replaces the old setup function.

I can use int ret = trillSensor.begin(Trill::TRILL_RING);
and it compiles, however If I try:

int ret = trillSensor.begin(Trill::TRILL_RING,Wire1);I get the same error as above...

See the header:

/* Initialise the hardware */
		int begin(Device device, uint8_t i2c_address = 255, TwoWire* wire = &Wire);
		/* Initialise the hardware, it's the same as begin() */
		int setup(Device device, uint8_t i2c_address = 255, TwoWire* wire = &Wire) { return begin(device, i2c_address, wire); }

The second argument is the address and the third is a pointer to the TwoWire object.
So

trill.begin(Trill::TRILL_RING, 255, &Wire1)

With 255 meaning default address

yes! it works again. thanks and sorry for not figuring it out by myself, for some reason I always have a hard time reading these header infos, once I see an example it makes sense.