Skip to main content

Meadow.Foundation.Sensors.Distance.Vl53l0x

Vl53l0x
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Distance.Vl53l0x

Code Example

Vl53l0x sensor;

public override Task Initialize()
{
Resolver.Log.Info("Initializing hardware...");

var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);
sensor = new Vl53l0x(i2cBus);

sensor.DistanceUpdated += Sensor_Updated;

return Task.CompletedTask;
}

public override Task Run()
{
sensor.StartUpdating(TimeSpan.FromMilliseconds(250));

return Task.CompletedTask;
}

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

if (result.New < new Length(0, LU.Millimeters))
{
Resolver.Log.Info("out of range.");
}
else
{
Resolver.Log.Info($"{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:

Vl53l0xMeadow Pin
GNDGND
SCLD08 (SCL)
SDAD07 (SDA)
VCC3V3

It should look like the following diagram:

Class Vl53l0x

Represents the Vl53l0x distance sensor

Assembly: Vl53l0x.dll
View Source
Declaration
public class Vl53l0x : ByteCommsSensorBase<Length>, IObservable<IChangeResult<Length>>, IDisposable, IRangeFinder, ISamplingSensor<Length>, ISensor<Length>, ISensor, ISamplingSensor, II2cPeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:
System.IObservable<Meadow.IChangeResult<Meadow.Units.Length>>, System.IDisposable, Meadow.Peripherals.Sensors.Distance.IRangeFinder, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Length>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Length>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Hardware.II2cPeripheral

Properties

IsShutdown

Is the hardware shutdown / off

View Source
Declaration
public bool IsShutdown { get; }

Distance

The distance to the measured object

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

DefaultI2cAddress

The default I2C address for the peripheral

View Source
Declaration
public byte DefaultI2cAddress { get; }

Fields

MinimumDistance

Minimum valid distance

View Source
Declaration
public static Length MinimumDistance

MaximumDistance

Maximum valid distance

View Source
Declaration
public static Length MaximumDistance

Methods

Initialize()

Initializes the VL53L0X

View Source
Declaration
protected Task Initialize()
Returns

System.Threading.Tasks.Task

MeasureDistance()

Tell the sensor to take a measurement

View Source
Declaration
public void MeasureDistance()

ReadSensor()

Returns the current distance/range

View Source
Declaration
protected override Task<Length> ReadSensor()
Returns

System.Threading.Tasks.Task<Meadow.Units.Length>: The current distance, returns 0 if the shutdown pin is used and is off### SetAddress(byte) Set a new I2C address

View Source
Declaration
public void SetAddress(byte newAddress)
Parameters
TypeName
System.BytenewAddress

ShutDown(bool)

Set the Shutdown state of the device

View Source
Declaration
public Task ShutDown(bool state)
Returns

System.Threading.Tasks.Task

Parameters
TypeNameDescription
System.Booleanstatereturns true if off/shutdown, false if on

GetSpadInfo()

Get the SPAD info

View Source
Declaration
protected Tuple<int, bool> GetSpadInfo()
Returns

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

PerformSingleRefCalibration(byte)

perform a sensor self calibration

View Source
Declaration
protected void PerformSingleRefCalibration(byte vhvInitByte)
Parameters
TypeNameDescription
System.BytevhvInitByteThe VHV init byte
Exceptions

System.Exception

ShutDown()

Shut down/power down the sensor

View Source
Declaration
public void ShutDown()

Implements

  • System.IObservable<Meadow.IChangeResult<Meadow.Units.Length>>
  • System.IDisposable
  • Meadow.Peripherals.Sensors.Distance.IRangeFinder
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Length>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Length>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Hardware.II2cPeripheral