Remarks

Vl53l0x
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Vl53l0x
                <img src="https://img.shields.io/nuget/v/Meadow.Foundation.Sensors.Distance.Vl53l0x.svg?label=Meadow.Foundation.Sensors.Distance.Vl53l0x" 
                style="width: auto; height: -webkit-fill-available;" /></a> |

Code Example

Vl53l0x sensor;

public MeadowApp()
{
    Console.WriteLine("Initializing hardware...");
    var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);
    sensor = new Vl53l0x(Device, i2cBus, (byte)Vl53l0x.Addresses.Default);

    sensor.DistanceUpdated += Sensor_Updated;
    sensor.StartUpdating(TimeSpan.FromMilliseconds(250));
}

private void Sensor_Updated(object sender, IChangeResult<Length> result)
{
    if (result.New == null) { return; }

    if (result.New < new Length(0, LU.Millimeters))
    { 
        Console.WriteLine("out of range.");
    }
    else 
    {
        Console.WriteLine($"{result.New.Millimeters}mm / {result.New.Inches:n3}\"");
    }
}

Sample project(s) available on GitHub

Wiring Example

To wire a Vl53l0x to your Meadow board, connect the following:

Vl53l0x Meadow Pin
GND GND
SCL D08 (SCL)
SDA D07 (SDA)
VCC 3V3

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object ObservableBase<Length> SensorBase<Length> SamplingSensorBase<Length> ByteCommsSensorBase<Length> > Vl53l0x
Implements IDisposable IRangeFinder
Inherited Members ByteCommsSensorBase<Length>.Peripheral ByteCommsSensorBase<Length>.ReadBuffer ByteCommsSensorBase<Length>.WriteBuffer ByteCommsSensorBase<Length>.Init(Int32, Int32) ByteCommsSensorBase<Length>.Dispose(Boolean) ByteCommsSensorBase<Length>.Dispose() SamplingSensorBase<Length>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<Length>.StopUpdating() SensorBase<Length>.Updated SensorBase<Length>.samplingLock SensorBase<Length>.SamplingTokenSource SensorBase<Length>.Conditions SensorBase<Length>.IsSampling SensorBase<Length>.UpdateInterval SensorBase<Length>.RaiseEventsAndNotify(IChangeResult<>) SensorBase<Length>.Read() ObservableBase<Length>.observers ObservableBase<Length>.NotifyObservers(IChangeResult<>) Meadow.Foundation.ObservableBase<Length>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<Length>.CreateObserver(Action<>, System.Nullable<Predicate<IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Distance
Assembly Vl53l0x.dll

Syntax

public class Vl53l0x : ByteCommsSensorBase<Length>, IDisposable, IRangeFinder

Constructors

Vl53l0x(IDigitalOutputController, II2cBus, IPin, Byte)

Creates a new Vl53l0x object

Declaration
public Vl53l0x(IDigitalOutputController device, II2cBus i2cBus, IPin shutdownPin, byte address = null)

Parameters

Type Name Description
IDigitalOutputController device

Meadow device

II2cBus i2cBus

I2C bus

IPin shutdownPin

Shutdown pin

System.Byte address

VL53L0X address

Vl53l0x(IDigitalOutputController, II2cBus, Byte)

Creates a new Vl53l0x object

Declaration
public Vl53l0x(IDigitalOutputController device, II2cBus i2cBus, byte address = null)

Parameters

Type Name Description
IDigitalOutputController device

Meadow device

II2cBus i2cBus

I2C bus

System.Byte address

I2C address

Properties

Distance

The distance to the measured object.

Declaration
public Length? Distance { get; protected set; }

Property Value

Type Description
System.Nullable<Length>

IsShutdown

Is the hardware shutdown / off

Declaration
public bool IsShutdown { get; }

Property Value

Type Description
System.Boolean

MaximumDistance

Maximum valid distance in mm (CurrentDistance returns -1 if above).

Declaration
public Length MaximumDistance { get; }

Property Value

Type Description
Length

MinimumDistance

Minimum valid distance in mm.

Declaration
public Length MinimumDistance { get; }

Property Value

Type Description
Length

Methods

GetRawRangeData()

Declaration
protected Task<int> GetRawRangeData()

Returns

Type Description
Task<System.Int32>

GetSpadInfo()

Declaration
protected Tuple<int, bool> GetSpadInfo()

Returns

Type Description
Tuple<System.Int32, System.Boolean>

Initialize()

Initializes the VL53L0X

Declaration
protected Task Initialize()

Returns

Type Description
Task

MeasureDistance()

Declaration
public void MeasureDistance()

PerformSingleRefCalibration(Byte)

Declaration
protected void PerformSingleRefCalibration(byte vhvInitByte)

Parameters

Type Name Description
System.Byte vhvInitByte

RaiseEventsAndNotify(IChangeResult<Length>)

Raise distance change event and notify subscribers

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Length> changeResult)

Parameters

Type Name Description
IChangeResult<Length> changeResult

Read(Byte)

Declaration
protected byte Read(byte address)

Parameters

Type Name Description
System.Byte address

Returns

Type Description
System.Byte

Read16(Byte)

Declaration
protected int Read16(byte address)

Parameters

Type Name Description
System.Byte address

Returns

Type Description
System.Int32

ReadSensor()

Returns the current distance/range

Declaration
protected override Task<Length> ReadSensor()

Returns

Type Description
Task<Length>

The distance in the specified Units. Default mm. Returns -1 if the shutdown pin is used and is off

Overrides

Meadow.Foundation.SensorBase<Length>.ReadSensor()

SetAddress(Byte)

Set a new I2C address

Declaration
public void SetAddress(byte newAddress)

Parameters

Type Name Description
System.Byte newAddress

ShutDown()

Declaration
public void ShutDown()

ShutDown(Boolean)

Set the Shutdown state of the device

Declaration
public Task ShutDown(bool state)

Parameters

Type Name Description
System.Boolean state

true = off/shutdown. false = on

Returns

Type Description
Task

Events

DistanceUpdated

Distance updated event

Declaration
public event EventHandler<IChangeResult<Length>> DistanceUpdated

Event Type

Type Description
EventHandler<IChangeResult<Length>>