Overview
The VL53L0X is a ranging sensor that uses time-of-flight of a laser to determine the distance to the next surface correct to the mm with a maximum of 2m. The sensor uses an i2c interface with a default address of 0x29. The xshut pin allows for address control and start up / shut down during setup.
Hardware Setup
Here are the pinouts for the Teensy 4.1 and the VL53L0X:
Make the following connections between the Teensy 4.1 and the sensor:
- Teensy GND to VL53L0X GND
- Teensy 3v3 to VL53L0X VIN
- Teensy pin 0 to VL53L0X XSHUT
- VL53L0X unconnected
- Teensy pin 18 to VL53L0X SDA
- Teensy pin 19 to VL53L0X SCL
No other passive components are required.
Software setup
This sensor example requires the Pololu vl53l0x library, which is available from the Arduino library manager.
Example: Reading distance and printing to the serial monitor
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
// XSHUT pin for VL53L0X
const int XSHUT_PIN = 0;
void setup() {
Serial.begin(115200);
Wire.begin(); // SDA = 18, SCL = 19 on Teensy 4.1
delay(100);
// Initialize XSHUT pin
pinMode(XSHUT_PIN, OUTPUT);
digitalWrite(XSHUT_PIN, LOW); // Reset sensor
delay(10);
digitalWrite(XSHUT_PIN, HIGH); // Power up sensor
delay(10);
// Initialize VL53L0X
sensor.setTimeout(500);
if (!sensor.init()) {
Serial.println("Failed to detect VL53L0X.");
while (1);
}
sensor.startContinuous();
Serial.println("VL53L0X started.");
}
void loop() {
uint16_t distance = sensor.readRangeContinuousMillimeters();
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" mm");
if (sensor.timeoutOccurred()) {
Serial.println("TIMEOUT");
}
delay(20);
}
No comments:
Post a Comment