Adafruit IMU not recognized on Wire2

Status
Not open for further replies.

darktessi07

New member
Hello everyone (sorry for my bad english..) !

It's been some days since I am unable to use properly my 10DOF Adafruit IMU.

10 DOF IMU :
LSM303DLHC Accel / Mag
L3GD20H Gyro
BMP180 Temp/Press

In my project this IMU is connected by I2C to my Teensy 3.5 using SDA2 and SCL2 port (It's hardwired).

To use Wire2, I ve installed i2c_t3 libraries to replace Wire.h. I use the Teensyduino IDE on windows.

The example sketch however compile but the IMU is not recognized on the Wire2 interface (but only by Wire).
I tried to had various lines of code seen on the internet in the setup such as :

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

The IMU works on the Wire pin even when I had one of these lines. When I connect the IMU to pins 3 and 4, Teensy is not able to find it.

If it helps this is the sketch example :

Code:
#include <i2c_t3.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_10DOF.h>

/* Assign a unique ID to the sensors */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified       bmp   = Adafruit_BMP085_Unified(18001);
Adafruit_L3GD20_Unified       gyro  = Adafruit_L3GD20_Unified(20);
void displaySensorDetails(void)
{
  sensor_t sensor;
  
  accel.getSensor(&sensor);
  Serial.println(F("----------- ACCELEROMETER ----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" m/s^2"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" m/s^2"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" m/s^2"));
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));

  gyro.getSensor(&sensor);
  Serial.println(F("------------- GYROSCOPE -----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" rad/s"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" rad/s"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" rad/s"));
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));
  
  mag.getSensor(&sensor);
  Serial.println(F("----------- MAGNETOMETER -----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" uT"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" uT"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" uT"));  
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));

  bmp.getSensor(&sensor);
  Serial.println(F("-------- PRESSURE/ALTITUDE ---------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" hPa"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" hPa"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" hPa"));  
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));
  
  delay(500);
}

void setup(void)
{
  Wire2.begin();
  //Wire.begin(I2C_MASTER, 0x00, I2C_PINS_3_4, I2C_PULLUP_EXT, 400000);
  
  Serial.begin(115200);
  Serial.println(F("Adafruit 10DOF Tester")); Serial.println("");

  /* Initialise the sensors */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
    while(1);
  }
  if(!mag.begin())
  {
    /* There was a problem detecting the LSM303 ... check your connections */
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
  if(!bmp.begin())
  {
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  if(!gyro.begin())
  {
    /* There was a problem detecting the L3GD20 ... check your connections */
    Serial.print("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
}

void loop(void)
{
  /* Get a new sensor event */
  sensors_event_t event;

  
  /* Display the results (acceleration is measured in m/s^2) */
  accel.getEvent(&event);
  Serial.print(F("ACCEL "));
  Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");Serial.println("m/s^2 ");

  /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
  mag.getEvent(&event);
  Serial.print(F("MAG   "));
  Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print("  ");Serial.println("uT");

  /* Display the results (gyrocope values in rad/s) */
  gyro.getEvent(&event);
  Serial.print(F("GYRO  "));
  Serial.print("X: "); Serial.print(event.gyro.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.gyro.z); Serial.print("  ");Serial.println("rad/s ");  

  /* Display the pressure sensor results (barometric pressure is measure in hPa) */
  bmp.getEvent(&event);
  if (event.pressure)
  {
    /* Display atmospheric pressure in hPa */
    Serial.print(F("PRESS "));
    Serial.print(event.pressure);
    Serial.print(F(" hPa, "));
    /* Display ambient temperature in C */
    float temperature;
    bmp.getTemperature(&temperature);
    Serial.print(temperature);
    Serial.print(F(" C, "));
    /* Then convert the atmospheric pressure, SLP and temp to altitude    */
    /* Update this next line with the current SLP for better results      */
    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    Serial.print(bmp.pressureToAltitude(seaLevelPressure,
                                        event.pressure,
                                        temperature)); 
    Serial.println(F(" m"));
  }
  
  Serial.println(F(""));
  delay(1000);
}

Thanks in advance for help !!! :)
 
Last edited:
Looking briefing at the sensor API's it doesn't appear that Adafruit uses I2C_t3 but uses the normal Wire calls. So using i2c_t3 only affects the main sketch. Would recommend not using I2C_t3 otherwise you will probably have to edit the Adafruit libraries. At least for now.

To use Wire2 you are going to have to specify it in the each sensor begin statements. For instance you have:
Code:
gyro.begin()

Now if you look at the L3GD20 library, Adafruit_L3GD20_U.h, file you will see you can specify the which bus you want to use:
Code:
bool begin(gyroRange_t rng = GYRO_RANGE_250DPS, TwoWire *theWire = &Wire);
So your begin would have to look something like:
Code:
gyro.begin(GYRO_RANGE_250DPS, Wire2);

You will have to that for the other 2 sensors as well.
 
Partially Resolved

Looking briefing at the sensor API's it doesn't appear that Adafruit uses I2C_t3 but uses the normal Wire calls. So using i2c_t3 only affects the main sketch. Would recommend not using I2C_t3 otherwise you will probably have to edit the Adafruit libraries. At least for now.

To use Wire2 you are going to have to specify it in the each sensor begin statements. For instance you have:
Code:
gyro.begin()

Now if you look at the L3GD20 library, Adafruit_L3GD20_U.h, file you will see you can specify the which bus you want to use:
Code:
bool begin(gyroRange_t rng = GYRO_RANGE_250DPS, TwoWire *theWire = &Wire);
So your begin would have to look something like:
Code:
gyro.begin(GYRO_RANGE_250DPS, Wire2);

You will have to that for the other 2 sensors as well.

Thanks for your response, it unlocked me to think about an other way to solve everything ...
I ve open libraries of each component by none of them have begin arguments (gyro only have res arg in mine).
According to that, I ve modified each .ccp and replaced Wire.xxxx with Wire2.xxxx.

This way, it works, but obviously, it does not permit to use these libraries with Wire unless you modify it twice...
During my check up in headers files, I ve notices a file : Adafruit_I2CDevice.h in the Adafruit_BusIO librarie.

This is a part of the file

Code:
#include <Wire.h>

#ifndef Adafruit_I2CDevice_h
#define Adafruit_I2CDevice_h

///< The class which defines how we will talk to this device over I2C
class Adafruit_I2CDevice {
public:
  Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = Wire2); //&Wire la place de Wire2
  uint8_t address(void);
  bool begin(bool addr_detect = true);
  bool detected(void);

  bool read(uint8_t *buffer, size_t len, bool stop = true);
  bool write(uint8_t *buffer, size_t len, bool stop = true,
             uint8_t *prefix_buffer = NULL, size_t prefix_len = 0);
  bool write_then_read(uint8_t *write_buffer, size_t write_len,
                       uint8_t *read_buffer, size_t read_len,
                       bool stop = false);
  bool setSpeed(uint32_t desiredclk);

  /*!   @brief  How many bytes we can read in a transaction
   *    @return The size of the Wire receive/transmit buffer */
  size_t maxBufferSize() { return _maxBufferSize; }



It contains the name of the bus for the I2C protocole, I replaced it by Wire2.
It had no effect on my sketch, this header appeared not to be used by other ccp ...

Have a nice day !
 
Status
Not open for further replies.
Back
Top