Does SparkFun_VL53L1X_Arduino_Library support multiple distance sensors

Hello,

I am trying to use two VL53L4CD distance sensors connected to one arduino. I have tried using the setI2CAddress() function to differentiate the two sensors but I still only get one reading. I also cut the I2C jumpers to have only one pair but I am still not getting separate readings. I attached my code below as well. Is the only way to accomplish this using a MUX?

#include <Wire.h>
#include "SparkFun_VL53L1X.h" 
//Optional interrupt and shutdown pins.
//#define SHUTDOWN_PIN 2
//#define INTERRUPT_PIN 3

SFEVL53L1X distanceSensorRear;
SFEVL53L1X distanceSensorFork;
//Uncomment the following line to use the optional shutdown and interrupt pins.
//SFEVL53L1X distanceSensor(Wire, SHUTDOWN_PIN, INTERRUPT_PIN);
uint8_t addr_r = 0x29;
uint8_t addr_f = 0x26;

void setup(void)
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("VL53L4CD Setup");

  distanceSensorRear.setI2CAddress(addr_r);
  distanceSensorFork.setI2CAddress(addr_f);

  Serial.print("Sensor Address rear: ");
  Serial.print(distanceSensorRear.getI2CAddress()); // Get sensor ID
  Serial.print("\tSensor Address front: ");
  Serial.println(distanceSensorFork.getI2CAddress());
  distanceSensorRear.setDistanceModeShort(); // Set distance mode (short for rear shock)
  distanceSensorFork.setDistanceModeShort();
  distanceSensorRear.setTimingBudgetInMs(20);
  distanceSensorFork.setTimingBudgetInMs(20);
  Serial.print("Range Status r: ");
  Serial.println(distanceSensorRear.getRangeStatus());
  Serial.print("\tRange Status f: ");
  Serial.println(distanceSensorFork.getRangeStatus());
  
  
  if (distanceSensorRear.begin() != 0 && distanceSensorFork.begin() != 0) //Begin returns 0 on a good init
  {
    Serial.println("Sensors failed to begin. Please check wiring. Freezing...");
    while (1)
      ;
  }
  Serial.println("Sensor online!");
}

void loop(void)
{
  distanceSensorRear.startRanging(); //Write configuration bytes to initiate measurement
  distanceSensorFork.startRanging();
  
  int rear_distance = distanceSensorRear.getDistance(); //Get the result of the measurement from the sensor
  int fork_distance = distanceSensorFork.getDistance();
  distanceSensorRear.stopRanging();
  distanceSensorFork.stopRanging();

  Serial.print("Time(s): ");
  Serial.print(millis());
  
  Serial.print("\tRear Distance(mm): ");
  Serial.print(rear_distance);

  Serial.print("\tFork Distance(mm): ");
  Serial.println(fork_distance);
}

Thank you for the help!

Somebody else faced the same problem using this sensor with ESP32. Ended up using two different I2C buses.

https://community.st.com/s/question/0D5 … sing-esp32

Thank you for that link that helped clear things up a ton. Do you know if the sparkfun library supports using two sensors at the same time?

Nevermind, figured everything out