vl53l1x-uld

Crates.iovl53l1x-uld
lib.rsvl53l1x-uld
version2.0.1
sourcesrc
created_at2022-05-20 17:52:41.832467
updated_at2023-12-07 19:01:11.391655
descriptionLibrary source port of the ULD driver for the VL53L1X
homepage
repositoryhttps://github.com/TomSievers/vl53l1x-rs
max_upload_size
id590400
size69,219
(TomSievers)

documentation

README

build docs crates.io

vl53l1x-uld

This crate is a port of the STM VL53L1X IMG009 driver to native rust.

Minimal example

Below is minimal example for using this driver. Other more complex examples can be found in the examples folder.

use vl53l1x_uld::{self, VL53L1X, IOVoltage, RangeStatus};

// Create hardware specific I2C instance.
let i2c = ...;
// Create sensor with default address. 
let mut vl = VL53L1X::new(i2c, vl53l1x_uld::DEFAULT_ADDRESS);

const ERR : &str = "Failed to communicate";

// Check if the sensor id is correct.
if (vl.get_sensor_id().expect(ERR) == 0xEACC)
{
    // Initialize the sensor before any usage.
    // Set the voltage of the IO pins to be 2.8 volts
    vl.init(IOVoltage::Volt2_8).expect(ERR);

    // Start a ranging operation, needed to retrieve a distance
    vl.start_ranging().expect(ERR);

    // Wait until distance data is ready to be read.
    while !vl.is_data_ready().expect(ERR) {}

    // Check if distance measurement is valid.
    if (vl.get_range_status().expect(ERR) == RangeStatus::Valid)
    {
        // Retrieve measured distance.
        let distance = vl.get_distance().expect(ERR);
    }
}

Commit count: 53

cargo fmt