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

Pololu Forum

Using multiple VL53L1X with arduino

#1

Hi :smile:
for a project in school i have to implement 5-7 VL53L1X sensors. I found a code for VL53L0X sensors.
I tried to implement two sensors with this code:

#include <VL53L1X.h>

VL53L1X sensor;
VL53L1X sensor2;

void setup()
{

  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);

  delay(500);
  Wire.begin();


  Serial.begin (9600);

  pinMode(4, INPUT);
  delay(150);
  Serial.println("00");
  sensor.init(true);

  Serial.println("01");
  delay(100);
  sensor.setAddress(0x28);
  Serial.println("02");

  pinMode(5, INPUT);
    delay(150);
  sensor2.init(true);
  Serial.println("03");
  delay(100);
  sensor2.setAddress(0x31);
  Serial.println("04");

  sensor.setDistanceMode(VL53L1X::Long);
  sensor.setMeasurementTimingBudget(50000);
  sensor.startContinuous(50);
  sensor2.setDistanceMode(VL53L1X::Long);
  sensor2.setMeasurementTimingBudget(50000);
  sensor2.startContinuous(50);
  sensor.setTimeout(100);
  sensor2.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: ");
  Serial.print(sensor.read());
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
  Serial.println();
  Serial.print("Sensor2: ");
   Serial.print(sensor2.read());
  if (sensor2.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.println();
  delay(1000);

}

when i run the code
i got two different address but i can’t decide which sensor get which address.
sensor get the address 0x16 and
sensor2 get the addres 0x29(default address)
and when my programm is in the loop
i get “TIMEOUT”, so something with the timeout from the sensors is wrong

can somebody help me, why i have different address then i write in my code??

#2

Hello.

From your code, it looks like you intend to connect pins 4 and 5 to the XSHUT pin on the two sensor boards and I do not see any obvious problems with the code. Can you post pictures here that show your connections between the sensors and the microcontroller board including any soldered connections you made? Have you tried a simpler code that tries to initialize and read one of the two sensors without changing the address?

-Nathan

#3

When i tried it with one sensor i can change the address. But when I initialized it again I get an error because he doesn’t have the default address. So i have to shutdown the sensor to start it again. I will upload a picture tomorrow.
The thing is, I don’t need the VL534L1X sensors from Pololu. I ordered them from STMicroelectronics. So they are slightly diffrent from your sensors. But I ordered some sensors from pololu. I also have a problem with the level-shifter. I hope I don’t have the same problem with your sensors. Do you have a datasheet with all the registers for the VL53L1X?

#4

Our init() routine resets the sensor so it will also reset the address. You should run that before changing the address and not after.

As far as we know, ST does not provide a datasheet that documents the VL53L1X sensor’s registers, but it is possible to infer some information about them from the way the API accesses the sensor.

-Nathan

#5

I was wondering if I could get a copy of the finished code. I am also using multiple VL53L1X sensors and I cant figure it out.

#6

with this example its work fine.


#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(" TIMEOUT"); }
  Serial.println();
  delay(500);
  Serial.print("Sensor2_22.5: ");
  Serial.print(sensor2.read());
  if (sensor2.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
  Serial.println();
  delay(500);
  Serial.print("Sensor3_45: ");
  Serial.print(sensor3.read());
  if (sensor3.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
  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);

}

1 Like
Using Multiple VL53L1X with Raspberry Pi
#7

@killia66 is it possible to get schematic for this, please?