Need help with i2c bus references

Hello! This is proving to be a miserable fruitless battle. Can you please help? I'm reading two BNO055 sensors and two TOF sensors. One BNO055 and one TOF on same bus. The pairs of sensors need to be on different i2c buses and I have no idea what I'm doing wrong. In this example I'm only showing the TOF for testing purposes. Please save me!!! Thank you in advance!
Marc

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

#include <VL53L1X.h>
VL53L1X leftSensor;
VL53L1X rightSensor;

/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (50)

Adafruit_BNO055 leftIMU = Adafruit_BNO055(55, 0x29, &Wire);
Adafruit_BNO055 rightIMU = Adafruit_BNO055(55, 0x29, &Wire1);

float leftPitchMeasured;
float leftPitchFilteredOld=0;
float leftPitchFilteredNew;

float rightPitchMeasured;
float rightPitchFilteredOld=0;
float rightPitchFilteredNew;

float leftRollMeasured; 
float leftRollFilteredOld=0;
float leftRollFilteredNew;

float rightRollMeasured; 
float rightRollFilteredOld=0;
float rightRollFilteredNew;

float leftPitch;
float leftRoll;

float rightPitch;
float rightRoll;

float leftDistance;
float rightDistance;

void setup(void)
{
  Serial.begin(115200);
  Serial1.begin(115200);
  
  leftIMU.begin();
  rightIMU.begin();

  leftIMU.setExtCrystalUse(true); //use crystal on board not in chip
  rightIMU.setExtCrystalUse(true); //use crystal on board not in chip

  delay(1000);
  Wire.begin();
  Wire.setClock(400000);
  Wire.beginTransmission(0x28);

  Wire1.begin();
  Wire1.setClock(400000);
  Wire1.beginTransmission(0x29);

  leftSensor.setTimeout(500);
  rightSensor.setTimeout(500);

  if (!leftSensor.init())
  {
    Serial.println("Failed to detect and initialize sensor!");
    while (1);
  }

  if (!rightSensor.init())
  {
    Serial.println("Failed to detect and initialize sensor!");
    while (1);
  }
  
  leftSensor.setDistanceMode(VL53L1X::Long);
  leftSensor.setMeasurementTimingBudget(50000);
  leftSensor.startContinuous(50);
 
  rightSensor.setDistanceMode(VL53L1X::Long);
  rightSensor.setMeasurementTimingBudget(50000);
  rightSensor.startContinuous(50);
}

void loop(void)
{
  leftDistance = (leftSensor.read());
  rightDistance = (rightSensor.read());

  imu::Vector<3> leftAcc = leftIMU.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
  imu::Vector<3> rightAcc = rightIMU.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);

leftPitchMeasured=atan2(leftAcc.x()/9.8,leftAcc.z()/9.8)/2/3.14159*360; //converted to degrees 
// next that value needs to be be LOW PASS FILTERED
leftPitchFilteredNew=.75*leftPitchFilteredOld+.25*leftPitchMeasured;
   
//roll=atan2(acc.y()/9.8, acc.z()/9.8); //result in radians
leftRollMeasured=atan2(leftAcc.y()/9.8, leftAcc.z()/9.8)/2/3.14159*360; //converted to degrees 
// next that value needs to be be LOW PASS FILTERED
leftRollFilteredNew=.75*leftRollFilteredOld+.25*leftRollMeasured;
//========================================
rightPitchMeasured=atan2(rightAcc.x()/9.8,rightAcc.z()/9.8)/2/3.14159*360; //converted to degrees 
// next that value needs to be be LOW PASS FILTERED
rightPitchFilteredNew=.75*rightPitchFilteredOld+.25*rightPitchMeasured;
   
//roll=atan2(acc.y()/9.8, acc.z()/9.8); //result in radians
rightRollMeasured=atan2(rightAcc.y()/9.8, rightAcc.z()/9.8)/2/3.14159*360; //converted to degrees 
// next that value needs to be be LOW PASS FILTERED
rightRollFilteredNew=.75*rightRollFilteredOld+.25*rightRollMeasured;
//========================================

/*
if (leftPitchFilteredNew > 0)
{
 leftPitchFilteredNew = leftPitchFilteredNew * -1;
}
 else
 {leftPitchFilteredNew = abs(leftPitchFilteredNew);
}
*/
/*
Serial.print(leftPitchFilteredNew);
Serial.print(",");  
Serial.print(leftRollFilteredNew);
Serial.print(",");  
Serial.println(leftDistance);

Serial1.print(leftPitchFilteredNew);
Serial1.print(",");   
Serial1.print(leftRollFilteredNew);
Serial1.print(",");  
Serial1.println(leftDistance);
*/

Serial.print(leftDistance);
Serial.print("========");
Serial.println(rightDistance);

leftPitchFilteredOld=leftPitchFilteredNew;
leftRollFilteredOld=leftRollFilteredNew;

delay(BNO055_SAMPLERATE_DELAY_MS);
}

Which Arduino board are you using and which pins are you using for the I2C interfaces ?

Teensy 4.1 SCL/SDA 19/18 and SCL1/SDA1 16/17

Links to the data sheets of the two types of sensor, please. Don't make us do the work you've already done.

1 Like

Have you read the data sheet. I find you have the choice of two I2C addresses thereby eliminating the need for the second bus when only two of these are used. Try this link and read it: Adafruit 9-DOF Absolute Orientation IMU Fusion Breakout - BNO055 : ID 2472 : Adafruit Industries, Unique & fun DIY electronics and kits As far as the TOF no idea of what you have. Post links to the technical information on the parts you actually have.

Hi! I have read the data sheets. The device does need two buses because each set of sensors are quite far from each other (1.5meters) I think the problem is in my code to access each bus. One set of sensors works fine...but I can't get two working??? Something in my code stinks!

Apparently you have not read the specification on the I2C bus. Good luck, the I2C bus was designed for chip to chip on the same board, not board to board. You might get lucky and it will work.

But still no links for us?

Oh, I get it! It's a secret project, so you can't tell us what you're doing 'cause we'd steal your idea.

If it does, it'll last until it's terribly important that it does work, at which point it will fail intermittently, making the OP think the sensors are toast.

Hint - Look for I2C repeaters, if you really must pursue this further. I'd have given you a link, but...

Have fun, I give up.

1 Like

Hi, @gundersonmarc

Can you post a link to data/specs of the TOF sensor?

Can it be setup with different I2C addresses?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

The code shows ONE BNO055 and TWO VL53L1X sensors. The second is apparently the problem. These sensors can have their I2C address changed on the fly, but you have to use the shutdowns pins to select them one by one and change addresses.

As long as you understand how the bus works and know what you're doing, there's a lot more that you can do with it. 1.5 m is out of the official spec but perfectly possible. For 2x 1.5m wiring attached to it, proper testing is needed (scoping the signals can be very telling at how far or close you are from the limits).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.