You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C, then port the API code. We strongly recommend using an Arduino to start though!
- Connect Vin to the power supply, 3-5V is fine (red wire on STEMMA QT version). Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
- Connect GND to common power/data ground (black wire on STEMMA QT version)
- Connect the SCL pin to the I2C clock SCL pin on your Arduino (yellow wire on STEMMA QT version). On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
- Connect the SDA pin to the I2C data SDA pin on your Arduino (blue wire on STEMMA QT version). On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2
The VL53L0X has a default I2C address of 0x29!
You can change it, but only in software. That means you have to wire the SHUTDOWN pin and hold all but one sensor in reset while you reconfigure one sensor at a time
To begin reading sensor data, you will need to install the Adafruit_VL53L0X Library.
The easiest way to do that is to open up the Manage Libraries... menu in the Arduino IDE
Then search for Adafruit VL53L0X and click Install
We also have a great tutorial on Arduino library installation at:
Open up File->Examples->Adafruit_VL53L0X->vl53l0x and upload to your Arduino wired up to the sensor
Thats it! Now open up the serial terminal window at 115200 speed to begin the test.
Move your hand up and down to read the sensor data. Note that when nothing is detected, it will say the reading is out of range
I2C only allows one address-per-device so you have to make sure each I2C device has a unique address. The default address for the VL53L0X is 0x29 but you can change this in software.
To set the new address you can do it one of two ways. During initialization, instead of calling lox.begin(), call
lox.begin(0x30) to set the address to 0x30. Or you can, later, call
lox.setAddress(0x30) at any time.
The good news is its easy to change, the annoying part is each other sensor has to be in shutdown. You can shutdown each sensor by wiring up to the XSHUT pin to a microcontroller pin. Then perform something like this pseudo-code:
- Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all XSHUT high to bring out of reset
- Keep sensor #1 awake by keeping XSHUT pin high
- Put all other sensors into shutdown by pulling XSHUT pins low
- Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29 and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
- Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its XSHUT pin high.
- Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29 and whatever you set the first sensor to
- Repeat for each sensor, turning each one on, setting a unique address.
Note you must do this every time you turn on the power, the addresses are not permanent!