vl53l1x — VL53L1X ToF distance sensor driver
This module provides a driver for the STMicroelectronics VL53L1X time-of-flight ranging sensor over I2C. The VL53L1X measures absolute distance up to ~4 m using a 940 nm invisible laser emitter and a SPAD receiving array.
Example usage:
import time
from machine import I2C
import vl53l1x
bus = I2C(1)
tof = vl53l1x.VL53L1X(bus)
while True:
print("Distance: {} mm".format(tof.read()))
time.sleep_ms(100)
Classes
- class vl53l1x.VL53L1X(bus: machine.I2C, address: int = 0x29)
Construct a VL53L1X driver instance.
busis a configuredmachine.I2Cbus object used to communicate with the sensor.addressis the 7-bit I2C address of the device. Defaults to0x29.
The constructor performs a soft reset, verifies the chip model ID, writes the default configuration block to the device, and applies the start-up register fix-up that the ST API performs on the first ranging start. The call blocks for ~200 ms while the sensor settles. Raises
RuntimeErrorif the model ID register does not return the expected value0xEACC.- writeReg(reg: int, value: int) None
Write a single 8-bit
valueto the 16-bit device register addressreg.
- writeReg16Bit(reg: int, value: int) None
Write a 16-bit
value(big-endian) to the 16-bit device register addressreg.
- readReg(reg: int) int
Read a single 8-bit value from the 16-bit device register address
regand return it as anint.
- readReg16Bit(reg: int) int
Read a 16-bit value (big-endian) from the 16-bit device register address
regand return it as anint.
- read_model_id() int
Return the contents of the 16-bit model-ID register at
0x010F. The expected value for a VL53L1X is0xEACC.
Constants
- vl53l1x.VL51L1X_DEFAULT_CONFIGURATION: bytes
Default 91-byte configuration block written to the device starting at register
0x2Dduring construction. The block sets the interrupt polarity, sigma threshold, signal threshold, intermeasurement period, distance thresholds, ROI center/size, and other ranging parameters recommended by the ST ultra-light driver. Most bytes are not user-modifiable; refer to the in-source comments for the user-tunable fields.