Error between SparkFunBME280.h and i2c_t3

rhr531

Member
Hi,

I recently received a project that uses teensy 3.2 and I receive the following error when trying to compile using platform.io ide, any help would be appreciated



In file included from C:\Users\rafa\.platformio\packages\framework-arduinoteensy\libraries\Wire/Wire.h:29,
from .pio\libdeps\teensy31\SparkFun BME280\src/SparkFunBME280.h:39,
from src\main.cpp:36:
C:\Users\rafae\.platformio\packages\framework-arduinoteensy\libraries\Wire/WireKinetis.h:229:16: error: conflicting declaration 'TwoWire Wire'
229 | extern TwoWire Wire;
| ^~~~
In file included from src\main.cpp:30:
C:\Users\rafa\.platformio\packages\framework-arduinoteensy\libraries\i2c_t3/i2c_t3.h:1000:15: note: previous declaration as 'i2c_t3 Wire'
1000 | extern i2c_t3 Wire;
| ^~~~
In file included from C:\Users\rafa\.platformio\packages\framework-arduinoteensy\libraries\Wire/Wire.h:29,
from .pio\libdeps\teensy31\SparkFun BME280\src/SparkFunBME280.h:39,
from src\main.cpp:36:
C:\Users\rafa\.platformio\packages\framework-arduinoteensy\libraries\Wire/WireKinetis.h:232:16: error: conflicting declaration 'TwoWire Wire1'
232 | extern TwoWire Wire1;
| ^~~~~
In file included from src\main.cpp:30:
C:\Users\rafa\.platformio\packages\framework-arduinoteensy\libraries\i2c_t3/i2c_t3.h:1002:19: note: previous declaration as 'i2c_t3 Wire1'
1002 | extern i2c_t3 Wire1;
| ^~~~~
In file included from src\main.cpp:36:
.pio\libdeps\teensy31\SparkFun BME280\src/SparkFunBME280.h:194:39: error: could not convert 'Wire' from 'i2c_t3' to 'TwoWire&'
194 | bool beginI2C(TwoWire &wirePort = Wire); //Called when user provides Wire port
| ^~~~
| |
| i2c_t3
src\main.cpp: In function 'void setup()':
src\main.cpp:738:23: error: invalid initialization of reference of type 'TwoWire&' from expression of type 'i2c_t3'
738 | if (!sensor.beginI2C())
| ~~~~~~~~~~~~~~~^~
In file included from src\main.cpp:36:
.pio\libdeps\teensy31\SparkFun BME280\src/SparkFunBME280.h:194:28: note: in passing argument 1 of 'bool BME280::beginI2C(TwoWire&)'
194 | bool beginI2C(TwoWire &wirePort = Wire); //Called when user provides Wire port
| ~~~~~~~~~^~~~~~~~~~~~~~~
*** [.pio\build\teensy31\src\main.cpp.o] Error 1
 

Attachments

  • 1718987157741.png
    1718987157741.png
    326 bytes · Views: 11
Is there any specific library that works with bme280 and i2c_t3? the library that is indicated on github has apparently been converted to wire.h
 
Just use default i2c driver with the BME28, i.e., Wire, instead of the i2c_t3 library. Use the Example 1 directly. Cant help more since you didn't post your sketch.

Code:
/*
  Get basic environmental readings from the BME280
  By: Nathan Seidle
  SparkFun Electronics
  Date: March 9th, 2018
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  Feel like supporting our work? Buy a board from SparkFun!
  https://www.sparkfun.com/products/14348 - Qwiic Combo Board
  https://www.sparkfun.com/products/13676 - BME280 Breakout Board
 
  This example shows how to read humidity, pressure, and current temperature from the BME280 over I2C.

  Hardware connections:
  BME280 -> Arduino
  GND -> GND
  3.3 -> 3.3
  SDA -> A4
  SCL -> A5
*/

#include <Wire.h>

#include "SparkFunBME280.h"
BME280 mySensor;

void setup()
{
  Serial.begin(115200);
  Serial.println("Reading basic values from BME280");

  Wire.begin();

  if (mySensor.beginI2C() == false) //Begin communication over I2C
  {
    Serial.println("The sensor did not respond. Please check wiring.");
    while(1); //Freeze
  }
}

void loop()
{
  Serial.print("Humidity: ");
  Serial.print(mySensor.readFloatHumidity(), 0);

  Serial.print(" Pressure: ");
  Serial.print(mySensor.readFloatPressure(), 0);

  Serial.print(" Alt: ");
  //Serial.print(mySensor.readFloatAltitudeMeters(), 1);
  Serial.print(mySensor.readFloatAltitudeFeet(), 1);

  Serial.print(" Temp: ");
  //Serial.print(mySensor.readTempC(), 2);
  Serial.print(mySensor.readTempF(), 2);

  Serial.println();

  delay(50);
}
 
The problem is that another library in the project uses i2c_t3.h, and using the sensor library (which uses wire.h) creates the conflicts that I pasted in the first post
 
My guess is that since most libs use standard wire library you are going to see things like
Code:
bool beginI2C(TwoWire &wirePort = Wire);
So anywhere in the BME280 library you will probably have to change TwoWire to i2c_t3
Code:
bool beginI2C(i2c_t3 &wirePort = Wire);

other thing is to replace Wire.h with i2c_t3.h.

NOTE: you will probably have to do this in both the .h and the .cpp files.

NOTE2: your wire.begin in your sketch (which not posted) will have to change as well:

Code:
  Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);

Note: Its been a while since playing this lib.
 
i'm attaching the code here,

some of the libraries included were changed by the last person who touched this project to use i2c_t3 instead of wire
 

Attachments

  • code.txt
    2.8 KB · Views: 10
Last edited:
My guess is that since most libs use standard wire library you are going to see things like
Code:
bool beginI2C(TwoWire &wirePort = Wire);
So anywhere in the BME280 library you will probably have to change TwoWire to i2c_t3
Code:
bool beginI2C(i2c_t3 &wirePort = Wire);

other thing is to replace Wire.h with i2c_t3.h.

NOTE: you will probably have to do this in both the .h and the .cpp files.

NOTE2: your wire.begin in your sketch (which not posted) will have to change as well:

Code:
  Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);

Note: Its been a while since playing this lib.

Thank you very much, I made the changes you suggested and the errors disappeared, however now I have a lot of warnings and the project does not compile, can you help me?

Code:
c:/users/rafae/.platformio/packages/toolchain-gccarmnoneeabi-teensy/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\teensy31\libc58\libWire.a(WireKinetis.cpp.o): in function `i2c0_isr':
WireKinetis.cpp:(.text.i2c0_isr+0x0): multiple definition of `i2c0_isr'; .pio\build\teensy31\lib4e6\libi2c_t3-11.0.a(i2c_t3.cpp.o):i2c_t3.cpp:(.text.i2c0_isr+0x0): first defined here
c:/users/rafae/.platformio/packages/toolchain-gccarmnoneeabi-teensy/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\teensy31\libc58\libWire.a(WireKinetis.cpp.o): in function `i2c1_isr':   
WireKinetis.cpp:(.text.i2c1_isr+0x0): multiple definition of `i2c1_isr'; .pio\build\teensy31\lib4e6\libi2c_t3-11.0.a(i2c_t3.cpp.o):i2c_t3.cpp:(.text.i2c1_isr+0x0): first defined here
c:/users/rafae/.platformio/packages/toolchain-gccarmnoneeabi-teensy/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\teensy31\libc58\libWire.a(WireKinetis.cpp.o):(.data.Wire1+0x0): multiple definition of `Wire1'; .pio\build\teensy31\lib4e6\libi2c_t3-11.0.a(i2c_t3.cpp.o):(.bss.Wire1+0x0): first defined here
c:/users/rafae/.platformio/packages/toolchain-gccarmnoneeabi-teensy/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\teensy31\libc58\libWire.a(WireKinetis.cpp.o):(.data.Wire+0x0): multiple definition of `Wire'; .pio\build\teensy31\lib4e6\libi2c_t3-11.0.a(i2c_t3.cpp.o):(.bss.Wire+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\teensy31\firmware.elf] Error 1
 
Back
Top