I2CDev incompatible with Teensy i2c_t3

I am trying to use i2c on a Teensy 3.2 with alternate pins (16 & 17). This requires the i2c_t3 library. I would like to use some of the features of the I2CDevlib as well. I am trying to compile the most basic project and am getting conflicts with the standard Wire library.

The error is “multiple definition of …” for i2c0_isr, i2c1_isr, Wire1, and Wire.

Something in the I2Cdevlib-Core library is including wire.h even though I specified I2CDEV_TEENSY_3X_WIRE which is supposed to switch to i2c_t3.h.

The function that causes this issue to occur is the alternate Wire.begin() statement with the alternate pin settings.

Any help would be appreciated!

Here is my main.cpp:

#define I2CDEV_IMPLEMENTATION       I2CDEV_TEENSY_3X_WIRE

#include <I2Cdev.h>

void setup() {
  // put your setup code here, to run once:
  Wire.begin(I2C_MASTER, 0x00, I2C_PINS_16_17, I2C_PULLUP_EXT, 
    I2C_RATE_400);
    
}

void loop() {
  // put your main code here, to run repeatedly:
}

Here is my platformio.ini:

[env:teensy31]
platform = teensy
board = teensy31
framework = arduino

lib_deps = 
  11  ; I2Cdevlib-Core

build_type = debug

Here is the build output:

> Executing task: platformio run <

Processing teensy31 (platform: teensy; board: teensy31; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy31.html
PLATFORM: Teensy 4.6.0 > Teensy 3.1 / 3.2
HARDWARE: MK20DX256 72MHz, 64KB RAM, 256KB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1), framework-arduinoteensy 1.148.0 (1.48)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 91 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <I2Cdevlib-Core> (/Users/jeff/workspaces/teensy_i2c_test/.pio/libdeps/teensy31/I2Cdevlib-Core_ID11)
|   |-- <Wire> 1.0 (/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/Wire)
|   |-- <i2c_t3> (/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/i2c_t3)
Building in debug mode
arm-none-eabi-g++ -o .pio/build/teensy31/firmware.elf -T mk20dx256.ld -Wl,--gc-sections,--relax -mthumb -mcpu=cortex-m4 -Wl,--defsym=__rtc_localtime=1579369911 -fsingle-precision-constant -Og -g2 -ggdb2 .pio/build/teensy31/src/main.cpp.o -L/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 -L.pio/build/teensy31 -Wl,--start-group .pio/build/teensy31/lib889/libWire.a .pio/build/teensy31/lib1a6/libi2c_t3.a .pio/build/teensy31/libb77/libI2Cdevlib-Core_ID11.a .pio/build/teensy31/libFrameworkArduino.a -larm_cortexM4l_math -lm -lstdc++ -Wl,--end-group
.pio/build/teensy31/lib1a6/libi2c_t3.a(i2c_t3.cpp.o): In function `i2c0_isr':
/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/i2c_t3/i2c_t3.cpp:1132: multiple definition of `i2c0_isr'
.pio/build/teensy31/lib889/libWire.a(WireKinetis.cpp.o):/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/Wire/WireKinetis.cpp:912: first defined here
/Users/jeff/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: Disabling relaxation: it will not work with multiple definitions
.pio/build/teensy31/lib1a6/libi2c_t3.a(i2c_t3.cpp.o): In function `Print::flush()':
/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.h:61: multiple definition of `i2c1_isr'
.pio/build/teensy31/lib889/libWire.a(WireKinetis.cpp.o):/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.h:61: first defined here
.pio/build/teensy31/lib1a6/libi2c_t3.a(i2c_t3.cpp.o): In function `Print::flush()':
/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.h:61: multiple definition of `Wire1'
.pio/build/teensy31/lib889/libWire.a(WireKinetis.cpp.o):/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.h:61: first defined here
/Users/jeff/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: Warning: size of symbol `Wire1' changed from 108 in .pio/build/teensy31/lib889/libWire.a(WireKinetis.cpp.o) to 20 in .pio/build/teensy31/lib1a6/libi2c_t3.a(i2c_t3.cpp.o)
.pio/build/teensy31/lib1a6/libi2c_t3.a(i2c_t3.cpp.o): In function `Print::flush()':
/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.h:61: multiple definition of `Wire'
.pio/build/teensy31/lib889/libWire.a(WireKinetis.cpp.o):/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/Print.h:61: first defined here
/Users/jeff/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: Warning: size of symbol `Wire' changed from 108 in .pio/build/teensy31/lib889/libWire.a(WireKinetis.cpp.o) to 20 in .pio/build/teensy31/lib1a6/libi2c_t3.a(i2c_t3.cpp.o)
collect2: error: ld returned 1 exit status
*** [.pio/build/teensy31/firmware.elf] Error 1
================================================================================== [FAILED] Took 1.23 seconds ==================================================================================
The terminal process terminated with exit code: 1

Well it’s still compling in the built-in Wire library.

Can you try lib_ignore = Wire in the platformio.ini? Does it change the dependency graph?

Thanks for the quick reply (and the formatting!). I reran with lib_ignore (also turned on -verbose). Now it’s complaining that Wire.h doesn’t exist. Something is including Wire.h but I can’t find out where.

Build output:

> Executing task: platformio run <

Processing teensy31 (platform: teensy; board: teensy31; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy31.html
PLATFORM: Teensy 4.6.0 > Teensy 3.1 / 3.2
HARDWARE: MK20DX256 72MHz, 64KB RAM, 256KB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES: toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1), framework-arduinoteensy 1.148.0 (1.48)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Ignored library /Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/Wire
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
Found 90 compatible libraries
Scanning dependencies...
Warning: Ignored `Wire` dependency for `I2Cdevlib-Core` library
Dependency Graph
|-- <I2Cdevlib-Core> (/Users/jeff/workspaces/teensy_i2c_test/.pio/libdeps/teensy31/I2Cdevlib-Core_ID11)
|   |-- <i2c_t3> (/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/i2c_t3)
Building in debug mode
arm-none-eabi-g++ -o .pio/build/teensy31/src/main.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -Iinclude -Isrc -I.pio/libdeps/teensy31/I2Cdevlib-Core_ID11 -I/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/i2c_t3 -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 src/main.cpp
arm-none-eabi-g++ -o .pio/build/teensy31/lib1a6/i2c_t3/i2c_t3.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -I/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/i2c_t3 -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 /Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/i2c_t3/i2c_t3.cpp
arm-none-eabi-g++ -o .pio/build/teensy31/libb77/I2Cdevlib-Core_ID11/I2Cdev.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -I.pio/libdeps/teensy31/I2Cdevlib-Core_ID11 -I/Users/jeff/.platformio/packages/framework-arduinoteensy/libraries/i2c_t3 -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 .pio/libdeps/teensy31/I2Cdevlib-Core_ID11/I2Cdev.cpp
arm-none-eabi-g++ -o .pio/build/teensy31/FrameworkArduino/AudioStream.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 /Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/AudioStream.cpp
arm-none-eabi-g++ -o .pio/build/teensy31/FrameworkArduino/DMAChannel.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 /Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/DMAChannel.cpp
arm-none-eabi-g++ -o .pio/build/teensy31/FrameworkArduino/EventResponder.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 /Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/EventResponder.cpp
arm-none-eabi-g++ -o .pio/build/teensy31/FrameworkArduino/HardwareSerial1.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 /Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial1.cpp
In file included from .pio/libdeps/teensy31/I2Cdevlib-Core_ID11/I2Cdev.cpp:46:0:
.pio/libdeps/teensy31/I2Cdevlib-Core_ID11/I2Cdev.h:86:26: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://platformio.org/lib/search?query=header:Wire.h
*
**************************************************************

compilation terminated.
*** [.pio/build/teensy31/libb77/I2Cdevlib-Core_ID11/I2Cdev.cpp.o] Error 1
arm-none-eabi-g++ -o .pio/build/teensy31/FrameworkArduino/HardwareSerial2.cpp.o -c -fno-exceptions -felide-constructors -fno-rtti -std=gnu++14 -Wno-error=narrowing -fpermissive -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -Og -g2 -ggdb2 -DPLATFORMIO=40100 -D__MK20DX256__ -DTEENSY31 -DUSB_SERIAL -DARDUINO=10805 -DTEENSYDUINO=148 -DCORE_TEENSY -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -D__PLATFORMIO_BUILD_DEBUG__ -I/Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3 /Users/jeff/.platformio/packages/framework-arduinoteensy/cores/teensy3/HardwareSerial2.cpp
================================================================================== [FAILED] Took 2.38 seconds ==================================================================================
The terminal process terminated with exit code: 1

Well I can see that there was recently a commit which might have fixed this, but the version in the PlatformIO library repository wasn’t updated yet.

Can you please do the following:

  • remove the .pio/libdeps folder of your project
  • remove the old lib_deps statement in the platformio.ini and write lib_deps = https://github.com/jrowberg/i2cdevlib.git, while keeping the lib_ignore statement
  • attempt recompile and post error
1 Like

I think I tried that before. Anyway, I tried it and now it can’t find I2CDev.h. I think because there’s a whole bunch of stuff in that repo and it doesn’t look like a library to pio.

src/main.cpp:3:20: fatal error: I2Cdev.h: No such file or directory

Yep you’re right. Ok I got it to compile, the main problem is that PlatformIO builds libraries by themselves so when it tries to compile the I2CDev library it doesn’t get the previous #define I2CDEV_IMPLEMENTATION I2CDEV_TEENSY_3X_WIRE command to select the correct implementation. Here’s how to get a working version:

  • remove all old I2CDev libs from either .pio\libdeps or lib/
  • add a new folder I2Cdevlib-Core to the lib/ to the project and add the .cpp and .h file from here
  • use the platformio.ini
[env:teensy31]
platform = teensy
board = teensy31
framework = arduino
lib_deps = I2Cdevlib-Core
build_flags = -DI2CDEV_IMPLEMENTATION=I2CDEV_TEENSY_3X_WIRE
lib_ignore = Wire
  • use as main.cpp
#include <I2Cdev.h>

void setup() {
  // put your setup code here, to run once:
  Wire.begin(I2C_MASTER, 0x00, I2C_PINS_16_17, I2C_PULLUP_EXT,
    I2C_RATE_400);

}

void loop() {
  // put your main code here, to run repeatedly:
} 
  • should compile fine
RAM:   [=         ]   9.7% (used 6364 bytes from 65536 bytes)
Flash: [=         ]   7.2% (used 18956 bytes from 262144 bytes)
 [SUCCESS] Took 4.40 seconds 
1 Like

Apologies to everyone who has to deal with this. I don’t know of a clean way to fix the organizational issues in that monumental repo, but I’m well aware of them now and have corrected them in the Perilib project (an ambitious reboot of I2Cdevlib that aims to fix everything broken).

1 Like

@maxgerhardt Thanks for your help and helping me understand the PIO build environment a little better! I was able to get a working demo. It took a little more work than I anticipated, though. Turns out the support for Teensy wasn’t really there, just the hint that someone started to work on it.

@jrowberg Thanks for all your efforts on the repo! I was able to complete the Teensy support and sent a pull request. Let me know if there are any issues.

1 Like