import vl53l0x
The vl53l0x module reads ST VL53L0X laser time-of-flight ranging sensors over I2C. It performs the sensor initialization, tuning, timing-budget setup, and reference calibration needed before measurements are useful.
Quick example
import vl53l0x
front = vl53l0x.VL53L0X(sda=21, scl=22)
reading = front.read()
if reading["ok"]:
print(reading["distance_mm"])
front.configure(profile="long_range")
print(front.distance())
front.start_continuous(period_ms=100)
data = front.read_continuous()
print(data["mm"])
front.stop_continuous()
importvl53l0x
VL53L0X time-of-flight distance sensor module.
The vl53l0x module reads ST VL53L0X laser time-of-flight ranging sensors over I2C. It performs the sensor initialization, tuning, timing-budget setup, and reference calibration needed before measurements are useful.
vl53l0x.VL53L0X(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None, io_2v8: bool = None) -> vl53l0x_sensor
vl53l0x.VL53L0X(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None, io_2v8: bool = None) -> vl53l0x_sensorCreate and initialize an independent VL53L0X distance sensor.
Use one VL53L0X object for each physical ranging sensor. Multiple sensors can share one I2C bus after each sensor is assigned a unique address.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Defaults to 0x29. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 400000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
io_2v8 |
bool |
positional or keyword | No | Optional bool. True enables 2.8 V I/O mode. Defaults to True. |
vl53l0x_sensor vl53l0x_sensor object.
vl53l0x.VL53L0X().configure(profile=None, timing_budget_us=None, signal_rate_limit=None, pre_vcsel=None, final_vcsel=None) -> bool
vl53l0x.VL53L0X().configure(profile=None, timing_budget_us=None, signal_rate_limit=None, pre_vcsel=None, final_vcsel=None) -> boolConfigure ranging profile and advanced measurement settings.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
profile |
str |
positional or keyword | No | Optional value. Defaults to None. |
timing_budget_us |
int |
positional or keyword | No | Optional value. Defaults to None. |
signal_rate_limit |
float |
positional or keyword | No | Optional value. Defaults to None. |
pre_vcsel |
int |
positional or keyword | No | Optional value. Defaults to None. |
final_vcsel |
int |
positional or keyword | No | Optional value. Defaults to None. |
vl53l0x.VL53L0X().profile(name) -> bool
vl53l0x.VL53L0X().profile(name) -> boolApply a named ranging profile.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
name |
str |
positional or keyword | Yes | Required value. |
vl53l0x.VL53L0X().read(timeout_ms=None) -> dict
vl53l0x.VL53L0X().read(timeout_ms=None) -> dictPerform one single-shot range measurement.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to None. |
vl53l0x.VL53L0X().distance(timeout_ms=None) -> int
vl53l0x.VL53L0X().distance(timeout_ms=None) -> intPerform one single-shot measurement and return millimeters.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to None. |
vl53l0x.VL53L0X().start_continuous(period_ms=None) -> bool
vl53l0x.VL53L0X().start_continuous(period_ms=None) -> boolStart continuous ranging.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
period_ms |
int |
positional or keyword | No | Optional value. Defaults to None. |
vl53l0x.VL53L0X().read_continuous(timeout_ms=None) -> dict
vl53l0x.VL53L0X().read_continuous(timeout_ms=None) -> dictRead the next continuous ranging result.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional value. Defaults to None. |
vl53l0x.VL53L0X().stop_continuous() -> bool
vl53l0x.VL53L0X().stop_continuous() -> boolStop continuous ranging.
vl53l0x.VL53L0X().ready() -> bool
vl53l0x.VL53L0X().ready() -> boolCheck whether a range result is ready.
vl53l0x.VL53L0X().set_timeout(timeout_ms) -> bool
vl53l0x.VL53L0X().set_timeout(timeout_ms) -> boolSet the default read timeout.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | Yes | Required value. |
vl53l0x.VL53L0X().set_signal_rate_limit(limit_mcps) -> bool
vl53l0x.VL53L0X().set_signal_rate_limit(limit_mcps) -> boolSet return signal-rate limit.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
limit_mcps |
float |
positional or keyword | Yes | Required value. |
vl53l0x.VL53L0X().get_signal_rate_limit() -> float
vl53l0x.VL53L0X().get_signal_rate_limit() -> floatReturn the current signal-rate limit.
vl53l0x.VL53L0X().set_timing_budget(timing_budget_us) -> bool
vl53l0x.VL53L0X().set_timing_budget(timing_budget_us) -> boolSet measurement timing budget.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timing_budget_us |
int |
positional or keyword | Yes | Required value. |
vl53l0x.VL53L0X().get_timing_budget() -> int
vl53l0x.VL53L0X().get_timing_budget() -> intReturn the current measurement timing budget.
vl53l0x.VL53L0X().set_vcsel_period(type, period_pclks) -> bool
vl53l0x.VL53L0X().set_vcsel_period(type, period_pclks) -> boolSet a VCSEL pulse period.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
type |
str |
positional or keyword | Yes | Required value. |
period_pclks |
int |
positional or keyword | Yes | Required value. |
vl53l0x.VL53L0X().get_vcsel_period(type) -> int
vl53l0x.VL53L0X().get_vcsel_period(type) -> intReturn a VCSEL pulse period.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
type |
str |
positional or keyword | Yes | Required value. |
vl53l0x.VL53L0X().set_address(address) -> bool
vl53l0x.VL53L0X().set_address(address) -> boolChange this sensor's I2C address.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
address |
int |
positional or keyword | Yes | Required value. |
vl53l0x.VL53L0X().id() -> dict
vl53l0x.VL53L0X().id() -> dictRead identification registers.
vl53l0x.VL53L0X().timeout_occurred() -> bool
vl53l0x.VL53L0X().timeout_occurred() -> boolReturn and clear the timeout flag.
vl53l0x.VL53L0X().reset() -> bool
vl53l0x.VL53L0X().reset() -> boolSoft-reset and reinitialize this sensor.
vl53l0x.VL53L0X().info() -> dict
vl53l0x.VL53L0X().info() -> dictReturn I2C, timeout, profile, and timing settings.
vl53l0x.VL53L0X().close() -> bool
vl53l0x.VL53L0X().close() -> boolRelease this VL53L0X handle.
vl53l0x.VL53L0X().Example
vl53l0x.VL53L0X().Examplesensor = vl53l0x.VL53L0X(sda=21, scl=22) print(sensor.distance())
vl53l0x.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None, io_2v8: bool = None) -> bool
vl53l0x.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None, io_2v8: bool = None) -> boolLegacy: initialize the module-level default VL53L0X sensor.
Prefer ``sensor = vl53l0x.VL53L0X(...)`` for new projects. The legacy wrapper keeps older singleton-style scripts working.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Defaults to 0x29. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 400000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
io_2v8 |
bool |
positional or keyword | No | Optional bool. True enables 2.8 V I/O mode, which is suitable for most breakout boards. Defaults to True. |
bool True when the sensor is detected, initialized, tuned, and calibrated.
vl53l0x.configure(profile: str = None, timing_budget_us: int = None, signal_rate_limit: float = None, pre_vcsel: int = None, final_vcsel: int = None) -> bool
vl53l0x.configure(profile: str = None, timing_budget_us: int = None, signal_rate_limit: float = None, pre_vcsel: int = None, final_vcsel: int = None) -> boolConfigure ranging profile and advanced measurement settings.
Profiles are convenience presets. Use ``"default"`` for normal reads, ``"high_speed"`` for faster lower-accuracy reads, ``"high_accuracy"`` for slower precise reads, and ``"long_range"`` for better dark-condition range.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
profile |
str |
positional or keyword | No | Optional preset name. Use "default", "high_speed", "high_accuracy", or "long_range". |
timing_budget_us |
int |
positional or keyword | No | Optional measurement timing budget in microseconds. Must be at least 20000. |
signal_rate_limit |
float |
positional or keyword | No | Optional return signal-rate limit in MCPS. Lower values can extend range but may reduce reliability. |
pre_vcsel |
int |
positional or keyword | No | Optional pre-range VCSEL pulse period. Use 12, 14, 16, or 18. |
final_vcsel |
int |
positional or keyword | No | Optional final-range VCSEL pulse period. Use 8, 10, 12, or 14. |
bool True when all requested settings are accepted.
vl53l0x.profile(name: str) -> bool
vl53l0x.profile(name: str) -> boolApply a named ranging profile.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
name |
str |
positional or keyword | Yes | Preset name. Use "default", "high_speed", "high_accuracy", or "long_range". |
bool True when the profile is applied.
vl53l0x.read(timeout_ms: int = None) -> dict
vl53l0x.read(timeout_ms: int = None) -> dictPerform one single-shot range measurement.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to the module timeout, initially 500. |
dict Dict with ``ok``, ``timeout``, ``distance_mm``, ``mm``, ``range_status``, ``continuous``, ``timeout_ms``, ``address``, ``profile``, and ``timing_budget_us`` fields.
vl53l0x.distance(timeout_ms: int = None) -> int
vl53l0x.distance(timeout_ms: int = None) -> intPerform one single-shot range measurement and return millimeters.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to the module timeout, initially 500. |
int Integer distance in millimeters, or -1 when the read times out.
vl53l0x.start_continuous(period_ms: int = None) -> bool
vl53l0x.start_continuous(period_ms: int = None) -> boolStart continuous ranging.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
period_ms |
int |
positional or keyword | No | Optional inter-measurement period in milliseconds. Use 0 for back-to-back measurements. Defaults to 0. |
bool True when continuous ranging is started.
vl53l0x.read_continuous(timeout_ms: int = None) -> dict
vl53l0x.read_continuous(timeout_ms: int = None) -> dictRead the next continuous ranging result.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | No | Optional timeout in milliseconds. Defaults to the module timeout, initially 500. |
dict Dict with the same fields as ``read()``, with ``continuous`` set to True when continuous mode is active.
vl53l0x.stop_continuous() -> bool
vl53l0x.stop_continuous() -> boolStop continuous ranging.
bool True when continuous ranging is stopped.
vl53l0x.ready() -> bool
vl53l0x.ready() -> boolCheck whether a range result is ready.
bool True when the VL53L0X interrupt status says a measurement is ready.
vl53l0x.set_timeout(timeout_ms: int) -> bool
vl53l0x.set_timeout(timeout_ms: int) -> boolSet the default read timeout.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timeout_ms |
int |
positional or keyword | Yes | Timeout in milliseconds. Use 0 to disable timeout checks. |
bool True when the timeout is stored.
vl53l0x.set_signal_rate_limit(limit_mcps: float) -> bool
vl53l0x.set_signal_rate_limit(limit_mcps: float) -> boolSet return signal-rate limit.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
limit_mcps |
float |
positional or keyword | Yes | Signal-rate limit in MCPS. Lower values can improve possible range but can also admit weaker, less reliable returns. |
bool True when the value is accepted.
vl53l0x.get_signal_rate_limit() -> float
vl53l0x.get_signal_rate_limit() -> floatReturn the current return signal-rate limit.
float Float signal-rate limit in MCPS.
vl53l0x.set_timing_budget(timing_budget_us: int) -> bool
vl53l0x.set_timing_budget(timing_budget_us: int) -> boolSet measurement timing budget.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
timing_budget_us |
int |
positional or keyword | Yes | Measurement timing budget in microseconds. Must be at least 20000. |
bool True when the timing budget is accepted.
vl53l0x.get_timing_budget() -> int
vl53l0x.get_timing_budget() -> intReturn the current measurement timing budget.
int Integer timing budget in microseconds.
vl53l0x.set_vcsel_period(type: str, period_pclks: int) -> bool
vl53l0x.set_vcsel_period(type: str, period_pclks: int) -> boolSet a VCSEL pulse period.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
type |
str |
positional or keyword | Yes | VCSEL period type. Use "pre" or "final". |
period_pclks |
int |
positional or keyword | Yes | Pulse period in PCLKs. Pre-range accepts 12, 14, 16, or 18. Final-range accepts 8, 10, 12, or 14. |
bool True when the period is valid and calibration succeeds.
vl53l0x.get_vcsel_period(type: str) -> int
vl53l0x.get_vcsel_period(type: str) -> intReturn a VCSEL pulse period.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
type |
str |
positional or keyword | Yes | VCSEL period type. Use "pre" or "final". |
int Integer pulse period in PCLKs.
vl53l0x.set_address(address: int) -> bool
vl53l0x.set_address(address: int) -> boolChange the VL53L0X I2C address.
This is useful when multiple VL53L0X sensors are on the same bus and each sensor is brought out of shutdown one at a time.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
address |
int |
positional or keyword | Yes | New 7-bit I2C address. |
bool True when the device address is changed and the native handle is moved to the new address.
vl53l0x.id() -> dict
vl53l0x.id() -> dictRead VL53L0X identification registers.
dict Dict with ``model_id``, ``revision_id``, and ``address`` fields.
vl53l0x.timeout_occurred() -> bool
vl53l0x.timeout_occurred() -> boolReturn and clear the timeout flag.
bool True when a previous read timed out since the last check.
vl53l0x.reset() -> bool
vl53l0x.reset() -> boolSoft-reset and reinitialize the VL53L0X.
bool True when the sensor is reset, initialized, and calibrated again.
vl53l0x.info() -> dict
vl53l0x.info() -> dictReturn VL53L0X module state.
dict Dict with initialization state, I2C settings, timeout, profile, timing budget, signal-rate limit, VCSEL periods, and last I2C status.