Two TOF one MPU problem

hi there i am using two vl53l0x sensors and one mpu6050 , for each software (in the libraries examples) they work fine but i tried to hook them in one software things got ugly.
serial monitor would have printed vl53l0x values then mpu values after initiating but it seems mpu initiating segment contradict the vl53l0x one,

my question is : why this is happing and how can i get all the readings i want?
notes are: 1.i wired all components correctly (xshut for vl53l0x sensors on 8 & 9) mpu free
2. i2c scanner shows that vl53l0x 1 address is 0x29 and vl53l0x 2 is 0x31 and mpu is 0x68 so there is no address aliases
3. initiating segments for both components are bug free
4. serial monitor is stuck after initiating vl53l0x at ("starting") and then it keeps looping

my code is

#include "Adafruit_VL53L0X.h"
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
// address we will assign if dual sensor is present
#define LOX1_ADDRESS 0x29
#define LOX2_ADDRESS 0x31
Adafruit_MPU6050 mpu;
// set the pins to shutdown
#define SHT_LOX1 8
#define SHT_LOX2 9

// objects for the vl53l0x
Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();

// this holds the measurement
VL53L0X_RangingMeasurementData_t measure1;
VL53L0X_RangingMeasurementData_t measure2;

/*
    Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all XSHUT high to bring out of reset
    Keep sensor #1 awake by keeping XSHUT pin high
    Put all other sensors into shutdown by pulling XSHUT pins low
    Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29 and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
    Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its XSHUT pin high.
    Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29 and whatever you set the first sensor to
 */
void setID() {
  // all reset
  digitalWrite(SHT_LOX1, LOW);    
  digitalWrite(SHT_LOX2, LOW);
  delay(10);
  // all unreset
  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, HIGH);
  delay(10);

  // activating LOX1 and resetting LOX2
  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, LOW);

  // initing LOX1
  if(!lox1.begin(LOX1_ADDRESS)) {
    Serial.println(F("Failed to boot first VL53L0X"));
    while(1);
  }
  delay(10);

  // activating LOX2
  digitalWrite(SHT_LOX2, HIGH);
  delay(10);

  //initing LOX2
  if(!lox2.begin(LOX2_ADDRESS)) {
    Serial.println(F("Failed to boot second VL53L0X"));
    while(1);
  }
}

void read_dual_sensors() {
  
  lox1.rangingTest(&measure1, false); // pass in 'true' to get debug data printout!
  lox2.rangingTest(&measure2, false); // pass in 'true' to get debug data printout!

  // print sensor one reading
  Serial.print(F("1: "));
  if(measure1.RangeStatus != 4) {     // if not out of range
    Serial.print(measure1.RangeMilliMeter);
  } else {
    Serial.print(F("Out of range"));
  }
  
  Serial.print(F(" "));

  // print sensor two reading
  Serial.print(F("2: "));
  if(measure2.RangeStatus != 4) {
    Serial.print(measure2.RangeMilliMeter);
  } else {
    Serial.print(F("Out of range"));
  }
  
  Serial.println();
}

void setup() {
  Serial.begin(9600);

  // wait until serial port opens for native USB devices
  while (! Serial) { delay(1); }

  pinMode(SHT_LOX1, OUTPUT);
  pinMode(SHT_LOX2, OUTPUT);

  Serial.println(F("Shutdown pins inited..."));

  digitalWrite(SHT_LOX1, LOW);
  digitalWrite(SHT_LOX2, LOW);

  Serial.println(F("Both in reset mode...(pins are low)"));
  
  
  Serial.println(F("Starting..."));
  setID();
   if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

}

void loop() {
   
  read_dual_sensors();
  delay(100);
}

i don't get nether "Failed to find MPU6050 chip" nor "MPU6050 Found!" please help, and thanx in advance

If you remove all references to the MPU6050 and disconnect the MPU6050, does the program work as expected?

If so, switch to a modern IMU like the ISM330, from a trusted supplier. The MPU6050 was discontinued many years ago, and you almost certainly have a fake or counterfeit chip, which could be causing the problem.

Maybe they're both occupying the same address.

perhaps I missed it but what is the host microcontroller?
how do you power the system?
upload a schematic showing the wiring and power supplies?

just removing

if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
}

will make it work again
telling arduino of Adafruit_MPU6050 mpu;
don't bother the code

no, please read my post again VL53L0X 1 is at x029 VL53L0X 2 is at 0x30 mpu at 0x68
even so i don't know how to tell i2c the specific addressee of mpu like VL53L0X
if that is a problem in the adafruit example please tell me how to modify it

  1. arduino pro mini as mc
  2. from programming cable once / 3.5 battery in other test
  3. I2C standard wiring (scl to A5) (sda to A4) (vcc to vcc) and (gnd to gnd)
    for VL53L0X xshut the first is for (pin 8) the second is for (pin 9)

the I2C address is a parameter to the begin() method, e.g.

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit VL53L0X test.");
  if (!lox.begin(0x31)) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }

Maybe memory problem?
I noticed you are using the F() macro on Serial.println() except the two that are failing.

"...they work fine but I tried to hook them in one software things got ugly."

My guess is you are running out of RAM. Which Arduino are you using?

Edit: This might help.

no it says 80% being used if that will case a problem then it would be devastating since there is more to be added

Where are you calling the RAM check function?
I presume you are getting this before the setup for the MPU6050, since that is where everything stops.
Not enough RAM.

guy i found the reason the mpu6050 was faulty , for some reason i yet to discover it worked fine as stand alone but after loading dual vlx sensors and reloading mpu_6050_raw it finally gave out and died on me, program worked fine on another chip i am leaving this here for anyone with similar problem. but thanx for you all.

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