I'm trying to use the TOF sensor VL53L0X with an arduino uno. Wiring (VL53L0X module to arduino uno): VIN - 5v pin, GND - GND, SDA - A4, SCL - A5. The documentation can be found here. When you install the library, there are pre-written example codes. I've selected the one called "Continuous". When I run the code, nothing is displayed in the serial port.
code:
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X. It is based on
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
The range readings are in units of mm. */
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1) {}
}
// Start continuous back-to-back mode (take readings as
// fast as possible). To use continuous timed mode
// instead, provide a desired inter-measurement period in
// ms (e.g. sensor.startContinuous(100)).
sensor.startContinuous();
}
void loop()
{
Serial.print(sensor.readRangeContinuousMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
So I run the following code to scan the I2C.
// --------------------------------------
// i2c_scanner
//
// Modified from https://playground.arduino.cc/Main/I2cScanner/
// --------------------------------------
#include <Wire.h>
// Set I2C bus to use: Wire, Wire1, etc.
#define WIRE Wire
void setup() {
WIRE.begin();
Serial.begin(9600);
while (!Serial)
delay(10);
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
WIRE.beginTransmission(address);
error = WIRE.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
The following is printed in the serial port
"I2C Scanner
Scanning..."
I have run this code with the wiring shown previously and on a bare arduino, both times, I get the same result. Can someone help, what do I do? Thanks
?
All VL53LOX modules I see (Adafruit, ebay etc.) come with a voltage regulator and I2C level shifter.
The sensor itself runs on 2.8volt, but V-in can be anything between 3.3volt and 5volt.
Maybe it's wise to post a picture of the build.
How long is the I2C wiring. Did you solder the pinheaders.
Leo..
I am feeding the vin with the 5 volt pin, I'll edit the post to make it more clear. So same result. And unfortunately I can't post the documentation because it's several pages long
I'm testing the I2C scanner code on a bare arduino (no components attached). Didn't work. I've also tried all the code mentioned with the VL53L0X attached using jumper wires (length 120mm). And the pinheaders have been soldered. Don't you think it's a problem with I2C since when I run the scan it gets stuck?
Sensor. So I'm guessing I was meant to use it with 3.3v. On the link it says the the VL53L0X is rated for 3.3v but the videos I've watch such as this one (skip to 7:11), the VL53L0X is connected to 5v. So did I damage the hardware? Don't you think the problem could be with I2C since the code gets stuck at "Scanning"?
5V is correct, you did not damage it.
Yes the problen is with the I2C.
To debug he problem, disconnect the SCL wire and run the Scanner program and see what happens.
SCL wire disconnected, still gets stuck at "scanning". What should it show when nothing is connected to the arduino uno? Because even when I disconnect every wire, I get the same problem?
connect the unbranded vl53l0x to a UNO and ran the following I2C scanner
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#include <Wire.h>
void setup() {
// activate internal pullups for twi.
digitalWrite(SDA, 1);
digitalWrite(SCL, 1);
Serial.begin (115200);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 2; i < 120; i++)
{
Wire.beginTransmission (i);
Serial.print (" 0x");
Serial.print (i, HEX);
if (Wire.endTransmission () == 0)
{
Serial.print ("\nFound address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (100); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
the serial monitor diplays - first scan nothing connected second scan vl53l0x connected to UNO SCL and SDA pins (VCC connected to either 3.3V or 5V works)
To figure out if the UNO is broken, run the "ReadAnalogVoltage" example program but change A0 to A5.
Connect a 1K ohm resistor beween 5V and A5. It should print out something close to 5V.
If not, it's bad.