Meadow.Foundation.Sensors.Distance.Vl53l0x
Vl53l0x | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Vl53l0x sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing hardware...");
var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);
sensor = new Vl53l0x(i2cBus);
sensor.Updated += 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:
Vl53l0x | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Class Vl53l0x
Represents the Vl53l0x distance sensor
Assembly: Vl53l0x.dll
View Source
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
public bool IsShutdown { get; }
Distance
The distance to the measured object
View Source
public Length? Distance { get; protected set; }
DefaultI2cAddress
The default I2C address for the peripheral
View Source
public byte DefaultI2cAddress { get; }
Fields
MinimumDistance
Minimum valid distance
View Source
public static Length MinimumDistance
MaximumDistance
Maximum valid distance
View Source
public static Length MaximumDistance
Methods
Initialize()
Initializes the VL53L0X
View Source
protected Task Initialize()
Returns
System.Threading.Tasks.Task
MeasureDistance()
Tell the sensor to take a measurement
View Source
public void MeasureDistance()
ReadSensor()
Returns the current distance/range
View Source
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
public void SetAddress(byte newAddress)
Parameters
Type | Name |
---|---|
System.Byte | newAddress |
ShutDown(bool)
Set the Shutdown state of the device
View Source
public Task ShutDown(bool state)
Returns
System.Threading.Tasks.Task
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | state | returns true if off/shutdown, false if on |
GetSpadInfo()
Get the SPAD info
View Source
protected Tuple<int, bool> GetSpadInfo()
Returns
System.Tuple<System.Int32,System.Boolean>
PerformSingleRefCalibration(byte)
perform a sensor self calibration
View Source
protected void PerformSingleRefCalibration(byte vhvInitByte)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | vhvInitByte | The VHV init byte |
Exceptions
System.Exception
ShutDown()
Shut down/power down the sensor
View Source
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