Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Getting the distance from two VL53L1X sensors

Hello I am trying to get the distance from two VL53L1X sensors but not working ? connecting the x-shut to 3k resistor as well.
This’s the code I am using:

#include <Wire.h>

#include <VL53L1X.h>

VL53L1X sensor;
VL53L1X sensor2;
VL53L1X sensor3;
VL53L1X sensor4;
VL53L1X sensor5;

//USE_I2C_2V8K;
void setup()
{

pinMode(2, OUTPUT); //erster Sensor muss nicht über XSHUT angesteuert werden
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);

// Initalisiert I2C
delay(500);
Wire.begin();
Wire.beginTransmission(0x29);
Serial.begin (9600);
/*
digitalWrite(2, HIGH);
delay(150);
Serial.println(“00”);
sensor.init();
Serial.println(“01”);
delay(100);
sensor.setAddress(0x31);
Serial.println(“02”);
*/
digitalWrite(3,HIGH);
delay(150);
sensor2.init();
Serial.println(“01”);
delay(100);
sensor2.setAddress(0x33);
Serial.println(“02”);

digitalWrite(4,HIGH);
delay(150);
sensor3.init();
Serial.println(“03”);
delay(100);
sensor3.setAddress(0x35);
Serial.println(“04”);

digitalWrite(5,HIGH);
delay(150);
sensor4.init();
Serial.println(“05”);
delay(100);
sensor4.setAddress(0x37);
Serial.println(“06”);

digitalWrite(6,HIGH);
delay(150);
sensor5.init();
Serial.println(“07”);
delay(100);
sensor5.setAddress(0x39);
Serial.println(“08”);

digitalWrite(2, HIGH);
delay(150);
Serial.println(“09”);
sensor.init();
Serial.println(“10”);
delay(100);

sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(50000);
sensor.startContinuous(50);
sensor.setTimeout(100);

sensor2.setDistanceMode(VL53L1X::Long);
sensor2.setMeasurementTimingBudget(50000);
sensor2.startContinuous(50);
sensor2.setTimeout(100);

sensor3.setDistanceMode(VL53L1X::Long);
sensor3.setMeasurementTimingBudget(50000);
sensor3.startContinuous(50);
sensor3.setTimeout(100);

sensor4.setDistanceMode(VL53L1X::Long);
sensor4.setMeasurementTimingBudget(50000);
sensor4.startContinuous(50);
sensor4.setTimeout(100);

sensor5.setDistanceMode(VL53L1X::Long);
sensor5.setMeasurementTimingBudget(50000);
sensor5.startContinuous(50);
sensor5.setTimeout(100);

delay(150);
Serial.println(“addresses set”);

Serial.println (“I2C scanner. Scanning …”);
byte count = 0;

for (byte i = 1; i < 120; i++)
{

Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
  Serial.print ("Found address: ");
  Serial.print (i, DEC);
  Serial.print (" (0x");
  Serial.print (i, HEX);
  Serial.println (")");
  count++;
  delay (1);  // maybe unneeded?
} // end of good response

} // end of for loop
Serial.println (“Done.”);
Serial.print (“Found “);
Serial.print (count, DEC);
Serial.println (” device(s).”);

}

void loop()
{

Serial.print(“Sensor1_horizontal: “);
Serial.print(sensor.read());
if (sensor.timeoutOccurred()) { Serial.print(””); }
Serial.println();
delay(500);
Serial.print(“Sensor2_22.5: “);
Serial.print(sensor2.read());
if (sensor2.timeoutOccurred()) { Serial.print(””); }
Serial.println();
delay(500);
Serial.print(“Sensor3_45: “);
Serial.print(sensor3.read());
if (sensor3.timeoutOccurred()) { Serial.print(””); }
Serial.println();
delay(500);
Serial.print(“Sensor4_67.5: “);
Serial.print(sensor4.read());
if (sensor4.timeoutOccurred()) { Serial.print(” TIMEOUT”); }
Serial.println();
delay(500);

Serial.print(“Sensor5: “);
Serial.print(sensor5.read());
if (sensor5.timeoutOccurred()) { Serial.print(” TIMEOUT”); }
Serial.println();
Serial.println();

delay(500);

}

Hello,

Are you using our VL53L1X carrier board? (Your diagram shows Adafruit VL53L0X boards, which use a different sensor than the VL53L1X.) Have you been able to get one sensor working by itself? Could you post a picture of your setup that shows your connections clearly?

Kevin

Yes , I am using your two VL53L1X sensors, I was able to get one reading when disconnecting the X-shut pin from all the sensors.
I used 2k + 1 k R for each connection line
for the connections both SCL connected to pin A5 and Both SDA connected to A4 .

From a quick look at your code, the line

Wire.beginTransmission(0x29);

is not necessary and might be causing problems, so I recommend removing it.

It would probably be best to simplify your circuit and code to use only two sensors for now, which should make things easier to debug. You can also check the return value of the init() function to see if that is where the problem is happening; for example:

  if(sensor2.init())
  {
    Serial.println("sensor2 initialized");
  }
  else
  {
    Serial.println("Could not initialize sensor2");
  }

Once you get two sensors working, you can then gradually add one at a time so that you can check your wiring and code changes at each step.

Kevin