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

Pololu Forum

Getting the distance from three VL53L1X sensors

Hi !
I’m trying to measure the distance using three VL53L1X and Arduino UNO, but it doesn’t work. I would like to get advice on how to improve it. The sketch is vl531xtriple.ino attached.
The two VL53L1Xs are working with the attached dualvl531x.ino sketch. The connection diagram is based on the attached sketch, and the XSHUT pin of the third VL53L1X is connected to pin 6 of Arduino UNO.dualvl531x.ino (1.6 KB)

//vl531xtriple.ino
#include <Wire.h>
#include <VL53L1X.h>

VL53L1X gVL531X;


VL53L1X sensor;
VL53L1X sensor2;
VL53L1X sensor3;
void setup()
{

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

  delay(500);
  Wire.begin();


  Serial.begin (9600);

  pinMode(4, INPUT);
  delay(150);
  sensor.init(true);
  delay(100);
  sensor.setAddress((uint8_t)22);
  sensor.setTimeout(500);

  pinMode(5, INPUT);
  delay(150);
  sensor2.init(true);
  delay(100);
  sensor2.setAddress((uint8_t)23);
  sensor2.setTimeout(500);

  pinMode(6, INPUT);
    delay(150);
  sensor3.init(true);
  delay(100);
  sensor3.setAddress((uint8_t)25);
  sensor3.setTimeout(500);

  
  
  Serial.println("addresses set");
  sensor.startContinuous(30);
  sensor2.startContinuous(30);
  sensor3.startContinuous(30);
  Serial.println("start read range");
   
  gVL531X.setTimeout(1000);

  



}

void loop()
{
  int dist1;
  int dist2;
  int dist3;
  dist1 = sensor.readRangeContinuousMillimeters();
  dist2 = sensor2.readRangeContinuousMillimeters();
  dist3 = sensor3.readRangeContinuousMillimeters();
  
  Serial.print(dist1);
  Serial.print("[mm]");
  Serial.print(dist2);
  Serial.println("[mm]");
  Serial.print(dist3);
  Serial.println("[mm]");
  delay(30);

  if (sensor.timeoutOccurred()){
    Serial.print("sensor1timeout\n");
  }
  if (sensor2.timeoutOccurred()){
    Serial.print("sensor2timeout\n");
  }
  if (sensor3.timeoutOccurred()){
    Serial.print("sensor3timeout\n");
  }
}
//dualvl531x.ino
#include <Wire.h>
#include <VL53L1X.h>

VL53L1X gVL531X;


VL53L1X sensor;
VL53L1X sensor2;

void setup()
{

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

  delay(500);
  Wire.begin();


  Serial.begin (9600);

  pinMode(4, INPUT);
  delay(150);
  sensor.init(true);
  delay(100);
  sensor.setAddress((uint8_t)22);
  sensor.setTimeout(500);

  pinMode(5, INPUT);
    delay(150);
  sensor2.init(true);
  delay(100);
  sensor2.setAddress((uint8_t)25);
  sensor2.setTimeout(500);
  
  Serial.println("addresses set");
  sensor.startContinuous(30);
  sensor2.startContinuous(30);
  Serial.println("start read range");
   
  gVL531X.setTimeout(1000);


}

void loop()
{
  int dist1;
  int dist2;
  dist1 = sensor.readRangeContinuousMillimeters();
  //delay(100);
  dist2 = sensor2.readRangeContinuousMillimeters();
  
  Serial.print(dist1);
  Serial.print("[mm]");
  Serial.print(dist2);
  Serial.println("[mm]");
  delay(30);

  if (sensor.timeoutOccurred()){
    Serial.print("sensor1timeout\n");
  }
  if (sensor2.timeoutOccurred()){
    Serial.print("sensor2timeout\n");
  }
}

vl531xtriple.ino (1.5 KB)

Hi,

I tried your 3-sensor program and it seemed to work for me. Note that the program you included in the text of your post and the program you attached as a file are different; the first uses pins 4, 5, and 6, while the second uses pins 2, 3, and 4. You might want to make sure your sensors are wired in a way that matches the program you’re using.

If you keep having trouble, could you post a picture of your setup that shows your wiring and explain in what way the program doesn’t work for you?

Kevin

Thanks for the reply.
I tried to run the program again after correcting the difference between the attached program and the actual pins connected, but nothing appears on the serial monitor. I have checked that the connection between the PC and Arduino, board and serial port are correct. I have attached a program that uses three VL53L1X and a connection diagram for you to check.

//vl531xtriple.ino
#include <Wire.h>
#include <VL53L1X.h>

VL53L1X gVL531X;


VL53L1X sensor;
VL53L1X sensor2;
VL53L1X sensor3;
void setup()
{

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

  delay(500);
  Wire.begin();


  Serial.begin (9600);

  pinMode(4, INPUT);
  delay(150);
  sensor.init(true);
  delay(100);
  sensor.setAddress((uint8_t)22);
  sensor.setTimeout(500);

  pinMode(5, INPUT);
  delay(150);
  sensor2.init(true);
  delay(100);
  sensor2.setAddress((uint8_t)23);
  sensor2.setTimeout(500);

  pinMode(6, INPUT);
    delay(150);
  sensor3.init(true);
  delay(100);
  sensor3.setAddress((uint8_t)25);
  sensor3.setTimeout(500);

  
  
  Serial.println("addresses set");
  sensor.startContinuous(30);
  sensor2.startContinuous(30);
  sensor3.startContinuous(30);
  Serial.println("start read range");
   
  gVL531X.setTimeout(1000);

  



}

void loop()
{
  int dist1;
  int dist2;
  int dist3;
  dist1 = sensor.readRangeContinuousMillimeters();
  dist2 = sensor2.readRangeContinuousMillimeters();
  dist3 = sensor3.readRangeContinuousMillimeters();
  
  Serial.print(dist1);
  Serial.print("[mm]");
  Serial.print(dist2);
  Serial.println("[mm]");
  Serial.print(dist3);
  Serial.println("[mm]");
  delay(30);

  if (sensor.timeoutOccurred()){
    Serial.print("sensor1timeout\n");
  }
  if (sensor2.timeoutOccurred()){
    Serial.print("sensor2timeout\n");
  }
  if (sensor3.timeoutOccurred()){
    Serial.print("sensor3timeout\n");
  }
}

Your program and wiring diagram both look fine. If you post some photos of your actual setup, I could try checking to see if there is anything that doesn’t match your wiring diagram or otherwise looks problematic. Have you been able to confirm that all 3 of your sensors work individually?

Kevin

I apologize for the messy wiring, but I am attaching the actual wiring diagram. I’ve already confirmed that each of the three VL53L1Xs works fine.

I think I only see 2 thin black wires going to the breadboard, so is it possible one of your sensors is missing a ground connection? The sensor boards themselves are not visible in your pictures, so if you post a picture of those, I can additionally check the connections on that end.

Kevin

Sorry for the late reply. I’ve uploaded a picture of the whole circuit, sorry it’s hard to see, and the three sensors are connected to ground. I still can’t get it to work. Is there some other factor such as lack of power?

Have you verified that all of your ground wires are actually electrically connected in your latest setup? It looks like it’s possible the connections go the other way (in vertical columns) in the bottom section of your breadboard.

I would not expect power to be an issue since the VL53L1X generally only uses a few milliamps, which a standard Arduino Uno should easily be able to supply. However, you are not using our carrier boards, so we cannot offer any advice specific to getting those working, and I suggest you try contacting the manufacturer of your boards for help if you continue having trouble. (As I mentioned, your 3-sensor program seemed to work for me with 3 Pololu boards, so it does not appear to be a problem with your program or our library.)

Kevin

Thank you for all your advice.
I will look into the Pololu board and others.