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

Pololu Forum

Cant read serial with 3 VL53L1X sensors

Hello
I have problem with VL53L1X.h library, i use arduino nano and 3 VL53L1X sensors.
I successfully addressed the sensors and test them, all work , but serial monitor freezes on addressing 3 sensors but all snsors work correctly, i test it with distance and led indikator, only Serial monitor dont work, please help me.

here is code that i use, Serial closes at the β€œ5” but programm still work.

#include <Wire.h>

#include <VL53L1X.h>

VL53L1X sensor;
VL53L1X sensor2;
VL53L1X sensor3;

#define sensor_reset_pin  A0
#define sensor2_reset_pin A1
#define sensor3_reset_pin A2

//USE_I2C_2V8K;
void setup(){
  Serial.begin (115200);
  pinMode(sensor_reset_pin, OUTPUT);  //erster Sensor muss nicht ΓΌber XSHUT angesteuert werden
  pinMode(sensor2_reset_pin, OUTPUT);
  pinMode(sensor3_reset_pin, OUTPUT);

  pinMode(13, OUTPUT);

  digitalWrite(sensor_reset_pin, LOW);
  digitalWrite(sensor2_reset_pin, LOW);
  digitalWrite(sensor3_reset_pin, LOW);

 // Initalisiert I2C
  while(!Serial);
  Wire.begin();
  Wire.setClock(400000);
  Wire.beginTransmission(0x29);
  
  digitalWrite(sensor_reset_pin,HIGH);
  delay(200);
  sensor.init();
  Serial.println("01");
  delay(200);
  sensor.setAddress(0x33);
  Serial.println("02"); 
  
  sensor.setDistanceMode(VL53L1X::Medium);
  sensor.setMeasurementTimingBudget(10000);
  sensor.startContinuous(10);
  sensor.setTimeout(100);
  Serial.println("sensor");
  
  delay(50);
  digitalWrite(sensor2_reset_pin,HIGH);
  
  delay(200);
  sensor2.init();
  Serial.println("03");
  delay(200);
  sensor2.setAddress(0x34);
  sensor2.setDistanceMode(VL53L1X::Medium);
  sensor2.setMeasurementTimingBudget(10000);
  sensor2.startContinuous(10);
  sensor2.setTimeout(100);
  Serial.println("sensor2");
  
  Serial.println("04");
  delay(50);
  
  digitalWrite(sensor3_reset_pin,HIGH);
  
  delay(200);
  sensor3.init();
  Serial.println("05");
  delay(200);
  sensor3.setAddress(0x35);
  sensor3.setDistanceMode(VL53L1X::Medium);
  sensor3.setMeasurementTimingBudget(10000);
  sensor3.startContinuous(10);
  sensor3.setTimeout(100);
  
  Serial.println("06");
  delay(200);
  
  Serial.println("sensor3");
  Serial.println("addresses set");
}
void loop(){
  int i = sensor3.read();
  Serial.print(" |Sensor1: ");
  Serial.print(sensor.read());
  if (sensor.timeoutOccurred()) { 
    Serial.print(" TIMEOUT ");
  }
  
  Serial.print(" |Sensor2: ");
  Serial.print(sensor2.read());
  if (sensor2.timeoutOccurred()) { 
    Serial.print(" TIMEOUT ");
  }

  Serial.print(" |Sensor3: ");
  Serial.print(sensor3.read());
  if (sensor3.timeoutOccurred()) { 
      Serial.print(" TIMEOUT ");
  }
  
  if(i > 200){
    digitalWrite(13,HIGH);
  }else{
    digitalWrite(13,LOW);
  }
  Serial.println();

}

Best regards Nikita

Hi, Nikita.

Are you saying that your program seems to run correctly (you see the LED on pin 13 turning on and off) but you do not see any serial output from the Arduino? If so, I am not sure why that would happen, although it’s possible it could be caused by too much memory being used on the Arduino. If you remove one of the sensors from your program, does that affect the serial behavior?

Kevin

Hello, Kevin!
If i use 2 sensors, serial is working,i use arduino nano 38% memory and 32% flash memory for this program, i saw that people uses 6 of that sensors, i dont know what my problem

Best regards Nikita

Hi, Nikita.

I tried your program on an Arduino Uno with 3 sensors and it worked fine for me (it printed all of the numbers and then started printing readings from the sensors). Are you using an official Arduino Nano (which uses the same microcontroller)? If not, could you link to the exact board that you are using? Do you have another Arduino you could test with?

Could you also post some pictures and/or diagrams showing your wiring?

By the way, assuming you are using our VL53L1X boards, you should avoid driving the XSHUT pins high since they are not level-shifted and not 5V tolerant . Instead, what you can do is set the pin to an input again (e.g. pinMode(sensor_reset_pin, INPUT)) to allow the on-board pull-up resistor to pull it up to 2.8V.

Kevin

Hi, Kevin
I tried your advice to use imputs insted of puting XSHUT pins high, thats also didnt help
That is my wiring, with sensors i use MPU6050:

Im using that model of arduino nano

and also i have motorshield connected to arduino :


Best regards Nikita

Im so sorry, i foun what was my problem, i connect sensors to 3.3V power suply, but when i changed it to 5V serial start work fine
Thank you Kevin for your help and time!
Best regards Nikita

2 Likes