To Whom It May Concern:
I am new to using this kind of device. I have added one TOF device, and it works well.
I only use the +, -, SCL and SDA connections for it to work.
Arduino VL53L0X board
5V - VIN
GND - GND
SDA - SDA
SCL - SCL
This is the Code I use for this:
#include <Wire.h> //"#include Wire.h
#include <VL53L0X.h> //#include VL53L0X.h
VL53L0X sensor;
//#define LONG_RANGE
//#define HIGH_SPEED
#define HIGH_ACCURACY
void setup()
{
Serial.begin(9600);
delay(10);
Wire.begin();
sensor.init();
sensor.setTimeout(500);
#if defined LONG_RANGE
// lower the return signal rate limit (default is 0.25 MCPS)
sensor.setSignalRateLimit(0.1);
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);//default
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);//default
//sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 28);//default
//sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 20);//default
#endif
#if defined HIGH_SPEED
// reduce timing budget to 20 ms (default is about 33 ms)
sensor.setMeasurementTimingBudget(20000);//default
#elif defined HIGH_ACCURACY
// increase timing budget to 200 ms
sensor.setMeasurementTimingBudget(200000);
#endif
}
void loop()
{
//Serial.print(sensor.readRangeSingleMillimeters());
//Serial.print("Distance (inches): ");
//Serial.println(sensor.readRangeSingleMillimeters()/25.4001);
long DISTANCE = (sensor.readRangeSingleMillimeters()/25.4001);
if (sensor.timeoutOccurred())
{
Serial.print("Distance (READING): ");
Serial.print(" TIMEOUT");
}
else
{
Serial.print("Distance (feet): ");
Serial.println(DISTANCE/12);
Serial.print("Distance (inches): ");
Serial.println(DISTANCE);
}
Serial.println();
Serial.println();
Serial.println();
delay(100);
}
HERE ARE MY QUESTIONS:
What code do I use for three TOF devices?
What connections do I make on the TOF board, and on an Arduino Mega Board?
Thank you for helping!
I have reviewed the information available and often referred to, (V73GVHRP/VL53L0X-AN4846.pdf)
and I would appreciate answers with the actual code and wire placement.
Thank you, again
This is my guess as to the wiring:
5V - VIN
GND - GND
SDA - SDA
SCL - SCL
XSHUT - 9 <— NEXT UNIT IS 10, THEN THIRD UNIT IS 11 ON ARDUINO
This is my code example that I have come up with for three sensors:
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
VL53L0X sensor2;
VL53L0X sensor3;
void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(500);
Wire.begin();
Serial.begin (9600);
//SENSOR
pinMode(9, INPUT);
delay(150);
Serial.println("00");
sensor.init(true);
Serial.println("01");
delay(100);
sensor.setAddress((uint8_t)22);
Serial.println("02");
//SENSOR 2
pinMode(10, INPUT);
delay(150);
sensor2.init(true);
Serial.println("03");
delay(100);
sensor2.setAddress((uint8_t)25);
Serial.println("04");
//SENSOR 3
pinMode(11, INPUT);
delay(150);
sensor3.init(true);
Serial.println("05");
delay(100);
sensor3.setAddress((uint8_t)28);
Serial.println("06");
Serial.println("");
Serial.println("addresses set");
Serial.println("");
Serial.println("");
sensor.setTimeout(500);
sensor2.setTimeout(500);
sensor3.setTimeout(500);
}
void loop()
{
Serial.println("__________________________________________________________________");
Serial.println("");
Serial.println("=================================");
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
//for (byte i = 1; i < 120; i++)
for (byte i = 1; i < 30; 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).");
Serial.println("=================================");
//CHECK DISTANCES
long DISTANCE_FWD = (sensor.readRangeSingleMillimeters()/25.4001);
long DISTANCE_FLT = (sensor2.readRangeSingleMillimeters()/25.4001);
long DISTANCE_FRT = (sensor3.readRangeSingleMillimeters()/25.4001);
//FWD OR SENSOR
if (sensor.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance FWD (READING): ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance FWD (feet): ");
Serial.println(DISTANCE_FWD/12);
Serial.print("Distance FWD (inches): ");
Serial.println(DISTANCE_FWD);
Serial.println("_________________________________");
Serial.println("");
}
//FLT OR SENSOR2
if (sensor2.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance FLT (READING): ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance FLT (feet): ");
Serial.println(DISTANCE_FLT/12);
Serial.print("Distance FLT (inches): ");
Serial.println(DISTANCE_FLT);
Serial.println("_________________________________");
Serial.println("");
}
//FRT OR SENSOR3
if (sensor3.timeoutOccurred())
{
Serial.println("_________________________________");
Serial.print("Distance FRT (READING): ");
Serial.println(" TIMEOUT");
Serial.println("_________________________________");
Serial.println("");
}
else
{
Serial.println("_________________________________");
Serial.print("Distance FRT (feet): ");
Serial.println(DISTANCE_FRT/12);
Serial.print("Distance FRTD (inches): ");
Serial.println(DISTANCE_FRT);
Serial.println("_________________________________");
Serial.println("");
}
Serial.println("__________________________________________________________________");
Serial.println();
Serial.println();
Serial.println();
Serial.println();
delay(2000);//can change to a lower time like 100
}
Hello.
I do not see anything obviously wrong with your code. If it does not work, can you post pictures that clearly show how you have connected everything? Can you also confirm that you are able to get each of your sensors working individually with our example code?
-Jon
How long cable do we use for VL53L0x ?we use 5 pcs pololu and 2m flat cable
2m seems pretty long, though there is some chance it could work for your system. I recommend reading this blog post to get an idea of what you can do to successfully communicate over long distances using the I2C protocol.
-Jon
A post was split to a new topic: VL53L0X distance issues
Hi this was helpful for me, is there any update ? will this code work ? i am just starting arduino and i need to connect 4 sensors TOF with one mega board