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

Pololu Forum

Multiple VL53L0X Problem

Hello dear people, I use 4 X Vl53L0X for my project.
i have connected the sensors with arduino mega, because the program for arduino uno was big(Has shown lowmemory error).Unfortunately from time to time the sensors will stop working. Still another question: could the sensors be made faster? I get per sensor 4 values in second. Is it possible to do more? Thanks a lot

#define HIGH_SPEED

#define LOX1_ADDRESS 0x30
#define LOX2_ADDRESS 0x31
#define LOX3_ADDRESS 0x32
#define LOX4_ADDRESS 0x33
int sensor1,sensor2,sensor3,sensor4;


#define SHT_LOX1 2
#define SHT_LOX2 3
#define SHT_LOX3 4
#define SHT_LOX4 5

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

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



void setID() {
  delay(10);
  digitalWrite(SHT_LOX1, LOW);    
  digitalWrite(SHT_LOX2, LOW);
  digitalWrite(SHT_LOX3, LOW);    
  digitalWrite(SHT_LOX4, LOW);  
  
  delay(10);
  
  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, HIGH);
  digitalWrite(SHT_LOX3, HIGH);
  digitalWrite(SHT_LOX4, HIGH);  
  delay(10);


  digitalWrite(SHT_LOX1, HIGH);
  digitalWrite(SHT_LOX2, LOW);
  digitalWrite(SHT_LOX3, LOW);
  digitalWrite(SHT_LOX4, LOW);
  delay(10);
  
  if(!lox1.begin(LOX1_ADDRESS)) {
    Serial.println(F("Failed to boot first VL53L0X"));
    while(1);
  }
  delay(10);


  digitalWrite(SHT_LOX2, HIGH);
  delay(10);


  if(!lox2.begin(LOX2_ADDRESS)) {
    Serial.println(F("Failed to boot second VL53L0X"));
    while(1);
  }
  
  
  digitalWrite(SHT_LOX3, HIGH);
  delay(10);

  
  if(!lox3.begin(LOX3_ADDRESS)) {
    Serial.println(F("Failed to boot second VL53L0X"));
    while(1);
  }
  
  
   
  digitalWrite(SHT_LOX4, HIGH);
  delay(10);

  
  if(!lox4.begin(LOX4_ADDRESS)) {
    Serial.println(F("Failed to boot second VL53L0X"));
    while(1);
  }  
     
}

void read_quad_sensors() {
  
  lox1.rangingTest(&measure1, false); 
  lox2.rangingTest(&measure2, false); 
  lox3.rangingTest(&measure3, false); 
  lox4.rangingTest(&measure4, false); 

  
  
  Serial.print("1: ");
  if(measure1.RangeStatus != 4) {     
    sensor1 = measure1.RangeMilliMeter+2;    
    Serial.print(sensor1);
    Serial.print("");    
  } else {
    Serial.print("Out of range");
  }
  
  Serial.print(" ");

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

   Serial.print(" ");

  
  Serial.print("3: ");
  if(measure3.RangeStatus != 4) {
    sensor3 = measure3.RangeMilliMeter-8;
    Serial.print(sensor3);
    Serial.print("");
  } else {
    Serial.print("Out of range");
  }
  
  
  Serial.print(" ");

 
  Serial.print("4: ");
  if(measure4.RangeStatus != 4) {
    sensor4 = measure4.RangeMilliMeter+12;
    Serial.print(sensor4);
    Serial.print("");
  } else {
    Serial.print("Out of range");
  }  
  Serial.println();
}

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

  while (! Serial) { delay(10); }

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

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

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

  Serial.println(F("All four in reset mode...(pins are low)"));
  
  
  Serial.println(F("Starting..."));
  setID();
 
}

void loop() {
   
  read_quad_sensors();
  delay(10);
}

Hello,

Are you using Pololu VL53L0X boards, or are they made by someone else?

Since it looks like you’re using Adafruit’s VL53L0X library, they would probably be better able to help you with your software. You might consider posting on their forum.

Kevin

1 Like

Hello Kevin,
thanks for your quick reply.
I use Arduino from the company Elegoo.
I found yesterday another program that runs with Arduino uno is much faster and without probleme than then.
I will report much if I get a problem.
Thank you and have a nice day