i2c_t3.h versus Wire.h with LCD w/i2c backpack and teensy 3.2

Status
Not open for further replies.
The below code works just fine running my Teensy 3.2 and 16x2LCD with i2c backpack, when I use : #include "Wire.h"
However when I replace #include "Wire.h", with #include "i2c_t3.h", it does not work, and I get the following error:
Any ideas?

/var/folders/lf/jkw3y2rx05z9lq5gph7nhcrh0000gn/T/build3a63475326cceb961ea9a65a0cfc079d.tmp/libraries/Wire/Wire.cpp.o: In function `i2c0_isr':
/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/Wire/Wire.cpp:237: multiple definition of `i2c0_isr'
/var/folders/lf/jkw3y2rx05z9lq5gph7nhcrh0000gn/T/build3a63475326cceb961ea9a65a0cfc079d.tmp/libraries/i2c_t3/i2c_t3.cpp.o:i2c_t3.cpp:(.text.i2c0_isr+0x0): first defined here
/Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: Disabling relaxation: it will not work with multiple definitions
/var/folders/lf/jkw3y2rx05z9lq5gph7nhcrh0000gn/T/build3a63475326cceb961ea9a65a0cfc079d.tmp/libraries/Wire/Wire.cpp.o: In function `TwoWire::flush()':
/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/Wire/Wire.cpp:368: multiple definition of `Wire'
/var/folders/lf/jkw3y2rx05z9lq5gph7nhcrh0000gn/T/build3a63475326cceb961ea9a65a0cfc079d.tmp/libraries/i2c_t3/i2c_t3.cpp.o:/Users/robdelbueno/Documents/Arduino/libraries/i2c_t3/i2c_t3.h:727: first defined here
/Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: Warning: size of symbol `Wire' changed from 20 in /var/folders/lf/jkw3y2rx05z9lq5gph7nhcrh0000gn/T/build3a63475326cceb961ea9a65a0cfc079d.tmp/libraries/i2c_t3/i2c_t3.cpp.o to 16 in /var/folders/lf/jkw3y2rx05z9lq5gph7nhcrh0000gn/T/build3a63475326cceb961ea9a65a0cfc079d.tmp/libraries/Wire/Wire.cpp.o
collect2: error: ld returned 1 exit status
Multiple libraries were found for "i2c_t3.h"
Used: /Users/robdelbueno/Documents/Arduino/libraries/i2c_t3
Not used: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/i2c_t3
Error compiling for board Teensy 3.2 / 3.1.


Why are these errors even referencing Wire, when it is not included?

Here is the sketch code:


#include "i2c_t3.h"
#include "Adafruit_LiquidCrystal.h"

// Connect via i2c, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);

void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);

lcd.setBacklight(HIGH);
delay(500);
lcd.setBacklight(LOW);
delay(500);
}
 
Changing from wire to i2c library, you need to do it everywhere that file is included in your sketch, including all of the libraries that include wire.h...

The errors you are seeing are because since Wire library is still being loaded, it's objects are also built into your executable, and both libraries create some of the same objects, like: i2c0_isr
 
Thanks Kurt.
Adafruit_LiquidCrystal.h includes Adafruit_MCP23008.h, which then includes Adafruit_MCP23008.cpp, which includes Wire.h

I replaced the include in Adafruit_MCP23008.cpp from #include <Wire.h>, to #include <i2c_t3.h>
All seems good now.

Thanks again.
 
Actually. I spoke to soon. While it compiles without error, it does not actually work. I suspect that Adafruit_LiquidCrystal may not be compatible with i2c_t3.h
 
I don't have any of these displays to test. They seem to have some kind of port expander in it (MCP23008)? Try running in immediate mode using the following call after the begin() lines, and see if that works (inside the Adafruit_MCP23008.cpp file). It should essentially run the same as the Wire lib in that mode.
Code:
Wire.begin(...);
[COLOR=#0000ff]Wire.setOpMode(I2C_OP_MODE_IMM);[/COLOR]
 
I will try that nx771, when I get a chance.
Meanwhile, I soldered the jumper on the Adafruit backpack to run it as SPI, and the Adafruit library seems to work fine with i2c_t3 library when using SPI mode.
 
nox771,
I made the change to Adafruit_MCP23008.cpp you suggested ( added Wire.setOpMode(I2C_OP_MODE_IMM); ), and that, in addition to replacing all references to Wire.h with i2c_t3.h, seems to have solved the issue.
I now have the LCD running via i2c, along with my other i2c devices all playing nice.
Thanks!
 
nox771,
I made the change to Adafruit_MCP23008.cpp you suggested ( added Wire.setOpMode(I2C_OP_MODE_IMM); ), and that, in addition to replacing all references to Wire.h with i2c_t3.h, seems to have solved the issue.
I now have the LCD running via i2c, along with my other i2c devices all playing nice.
Thanks!

Ok, thanks for confirming it works.
 
Conditional compilation to select i2c_t3 or Wire libraries

Rather than hardcoding which I2C lib to use, I do this, in my library header file. I make the same mod to libs for other vendor's products. Then it works automagically with either Arduino or Teensy depending on which controller I use:
Code:
// Use Teensy improved I2C library
//#if defined (__MK20DX256__) || defined (__MK20DX128__) 	// Teensy 3.1 or 3.2 || Teensy 3.0
// from [url]https://forum.pjrc.com/threads/42411-Communication-impossible-in-I2C-tennsy3-6?p=135630&viewfull=1#post135630[/url]
#if defined(KINETISK) || defined(KINETISL)	// Teensy 3.X and LC
#include <i2c_t3.h>		
#else
#include <Wire.h>	// for AVR I2C library
#endif

Also to prevent including the same .h file multiple times, something like this:
Code:
#ifndef SYSTRONIX_PCA9548A_h
#define SYSTRONIX_PCA9548A_h
...
// your library header code
...
#endif

I like to have any other necessary #includes (such as Arduino.h) in the library .h file, and then only the one library #include in the .cpp file and any .ino file. Adafruit often have #includes sprinkled all over. Putting other #include in a .h violates some programming guidelines such as from Michael Barr, but you can't please everyone.

I use the Adafruit 7-segment arrays with HT16K33 I2C backpack with Teensy 2 and 3.X and have no problems.
 
Status
Not open for further replies.
Back
Top