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

Pololu Forum

Vl53L0X Problem

#1

I have to connect four Vl53L0X with an Arduino Uno and read from all the sensors the corresponding measured data. All this is supposed to be done via an I2C bus. This is my previous code:

#include <Wire.h>
#include <VL53L0X.h>
//////////////////////////////////////////////////////////////////////////////////////////
#define XSHUT_pin4 8
#define XSHUT_pin3 7      // Definition of the connection pins 
#define XSHUT_pin2 6
#define XSHUT_pin1 5
//////////////////////////////////////////////////////////////////////////////////////////
#define Sensor2_newAddress 42
#define Sensor3_newAddress 43     // default address: 0b0101001 => 41
#define Sensor4_newAddress 44     // Sensors get new addresses
//////////////////////////////////////////////////////////////////////////////////////////
VL53L0X Sensor1;
VL53L0X Sensor2;
VL53L0X Sensor3;
VL53L0X Sensor4;
//////////////////////////////////////////////////////////////////////////////////////////
void setup() { 

  pinMode(XSHUT_pin1, OUTPUT);
  pinMode(XSHUT_pin2, OUTPUT);      // The pins on the sensors must not be connected to 5V 
  pinMode(XSHUT_pin3, OUTPUT);         
  pinMode(XSHUT_pin4, OUTPUT);
//////////////////////////////////////////////////////////////////////////////////////////
  Serial.begin(9600);             // Start serial communication with PC
//////////////////////////////////////////////////////////////////////////////////////////  
  Wire.begin();
  Sensor4.setAddress(Sensor4_newAddress);
    pinMode(XSHUT_pin3, INPUT);
  delay(10);                                   // Sensors get new addresses
  Sensor3.setAddress(Sensor3_newAddress);
    pinMode(XSHUT_pin2, INPUT);
  delay(10);
  Sensor2.setAddress(Sensor2_newAddress);
    pinMode(XSHUT_pin1, INPUT);
  delay(10);
//////////////////////////////////////////////////////////////////////////////////////////  
  Sensor1.init();
  Sensor2.init();
  Sensor3.init();
  Sensor4.init();
////////////////////////////////////////////////////////////////////////////////////////// 
  Sensor1.setTimeout(500);
  Sensor2.setTimeout(500);
  Sensor3.setTimeout(500);
  Sensor4.setTimeout(500);
//////////////////////////////////////////////////////////////////////////////////////////
  Sensor1.startContinuous();
  Sensor2.startContinuous();      
  Sensor3.startContinuous();
  Sensor4.startContinuous();
//////////////////////////////////////////////////////////////////////////////////////////
pinMode(13, OUTPUT);
}
void loop()
{  
//////////////////////////////////////////////////////////////////////////////////////////
  Serial.print(Sensor1.readRangeContinuousMillimeters());
  Serial.print(',');
  Serial.print(Sensor2.readRangeContinuousMillimeters());
  Serial.print(',');                                        // Reading out the sensors
  Serial.print(Sensor3.readRangeContinuousMillimeters());
  Serial.print(','); 
  Serial.print(Sensor4.readRangeContinuousMillimeters());
  Serial.print(',');
//////////////////////////////////////////////////////////////////////////////////////////
  if (Sensor1.readRangeContinuousMillimeters() <= 100) {
        digitalWrite(13, HIGH);
        delay(200);
        digitalWrite(13, LOW);
        delay(200);
        } else {
        digitalWrite(13, LOW);
        }
   
  if (Sensor2.readRangeContinuousMillimeters() <= 100) {
      digitalWrite(13, HIGH);
      }  else {
      digitalWrite(13, LOW);
      }
      
  if (Sensor3.readRangeContinuousMillimeters() <= 100) {
        digitalWrite(13, HIGH);
        delay(500);
        digitalWrite(13, LOW);
        delay(500);
        } else {
        digitalWrite(13, LOW);
        }
        
  if (Sensor4.readRangeContinuousMillimeters() <= 100) {
        digitalWrite(13, HIGH);
        delay(200);
        digitalWrite(13, LOW);
        delay(200);
        } else {
        digitalWrite(13, LOW);
        }      
       
 }

The XSHUT pins of the sensors are connected to the Arduino because with each restart (thus also turning on) the sensors must be assigned a new address so that the I2C bus can keep the sensors apart.

The problem is that the code works well so far and the sensors work so far but only up to a certain point. If the distance between the sensor and the wall is too large, the sensors will break off and give a value of between 30 and 70, although the value is actually over 200. This then turns the led on pin 13, but it should only blink if the distance is really below 40 inches. Can you help me pleas its really important?

#2

The usable range of those detectors depends strongly on the ambient light conditions and the size and reflectivity of the target.

Have you verified that the sensors, used individually without address modification, respond correctly in the same environment?