Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object ObservableBase<MagneticField3D> SamplingSensorBase<MagneticField3D> PollingSensorBase<MagneticField3D> > Lis2Mdl
Implements IObservable<IChangeResult<MagneticField3D>> IMagnetometer ISamplingSensor<MagneticField3D> ISensor<MagneticField3D> II2cPeripheral
Inherited Members PollingSensorBase<MagneticField3D>.StartUpdating(TimeSpan?) PollingSensorBase<MagneticField3D>.StopUpdating() SamplingSensorBase<MagneticField3D>.samplingLock SamplingSensorBase<MagneticField3D>.Read() SamplingSensorBase<MagneticField3D>.SamplingTokenSource SamplingSensorBase<MagneticField3D>.Conditions SamplingSensorBase<MagneticField3D>.IsSampling SamplingSensorBase<MagneticField3D>.UpdateInterval SamplingSensorBase<MagneticField3D>.Updated ObservableBase<MagneticField3D>.NotifyObservers(IChangeResult<MagneticField3D>) ObservableBase<MagneticField3D>.Subscribe(IObserver<IChangeResult<MagneticField3D>>) ObservableBase<MagneticField3D>.CreateObserver(Action<IChangeResult<MagneticField3D>>, Predicate<IChangeResult<MagneticField3D>>) ObservableBase<MagneticField3D>.observers object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.Sensors.Motion
Assembly Lis2Mdl.dll

Syntax

public class Lis2Mdl : PollingSensorBase<MagneticField3D>, IObservable<IChangeResult<MagneticField3D>>, IMagnetometer, ISamplingSensor<MagneticField3D>, ISensor<MagneticField3D>, II2cPeripheral

Constructors

Lis2Mdl(II2cBus, byte)

Create a new Lis2Mdl instance

Declaration
public Lis2Mdl(II2cBus i2cBus, byte address = 30)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus connected to the sensor

byte address

The I2C address

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Fields

i2cComms

I2C Communication bus used to communicate with the peripheral

Declaration
protected readonly II2cCommunications i2cComms

Field Value

Type Description
II2cCommunications

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Properties

DefaultI2cAddress

The default I2C address for the peripheral

Declaration
public byte DefaultI2cAddress { get; }

Property Value

Type Description
byte

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

MagneticField3D

Current Magnetic Field 3D

Declaration
public MagneticField3D? MagneticField3D { get; }

Property Value

Type Description
MagneticField3D?

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Methods

GetBlockDataUpdate()

Gets the status of the Block Data Update (BDU) feature.

Declaration
public bool GetBlockDataUpdate()

Returns

Type Description
bool

true if BDU is enabled, false otherwise.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

GetFastRead()

Gets the status of the Fast Read feature.

Declaration
public bool GetFastRead()

Returns

Type Description
bool

true if Fast Read is enabled, false otherwise.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

GetOperatingMode()

Gets the operating mode of the magnetometer.

Declaration
public Lis2Mdl.OperatingMode GetOperatingMode()

Returns

Type Description
Lis2Mdl.OperatingMode

The operating mode as a Lis2Mdl.OperatingMode enum.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

GetOutputDataRate()

Gets the output data rate (ODR) of the magnetometer.

Declaration
public Lis2Mdl.OutputDataRate GetOutputDataRate()

Returns

Type Description
Lis2Mdl.OutputDataRate

The output data rate as a Lis2Mdl.OutputDataRate enum.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

GetTemperatureCompensation()

Gets the status of the temperature compensation feature.

Declaration
public bool GetTemperatureCompensation()

Returns

Type Description
bool

true if temperature compensation is enabled, false otherwise.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

RaiseEventsAndNotify(IChangeResult<MagneticField3D>)

Raise events for subscribers and notify of value changes

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

Parameters

Type Name Description
IChangeResult<MagneticField3D> changeResult

The updated sensor data

Overrides

Meadow.Foundation.SamplingSensorBase<Meadow.Units.MagneticField3D>.RaiseEventsAndNotify(Meadow.IChangeResult<Meadow.Units.MagneticField3D>)

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

ReadSensor()

Reads data from the sensor

Declaration
protected override Task<MagneticField3D> ReadSensor()

Returns

Type Description
Task<MagneticField3D>

The latest sensor reading

Overrides

Meadow.Foundation.SamplingSensorBase<Meadow.Units.MagneticField3D>.ReadSensor()

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetBlockDataUpdate(bool)

Sets the status of the Block Data Update (BDU) feature.

Declaration
public void SetBlockDataUpdate(bool enable)

Parameters

Type Name Description
bool enable

true to enable BDU, false to disable it.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetFastRead(bool)

Sets the status of the Fast Read feature.

Declaration
public void SetFastRead(bool enable)

Parameters

Type Name Description
bool enable

true to enable Fast Read, false to disable it.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetOperatingMode(OperatingMode)

Sets the operating mode of the magnetometer.

Declaration
public void SetOperatingMode(Lis2Mdl.OperatingMode mode)

Parameters

Type Name Description
Lis2Mdl.OperatingMode mode

The desired operating mode as a Lis2Mdl.OperatingMode enum.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetOutputDataRate(OutputDataRate)

Sets the output data rate (ODR) of the magnetometer.

Declaration
public void SetOutputDataRate(Lis2Mdl.OutputDataRate odr)

Parameters

Type Name Description
Lis2Mdl.OutputDataRate odr

The desired output data rate as a Lis2Mdl.OutputDataRate enum.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetTemperatureCompensation(bool)

Sets the status of the temperature compensation feature.

Declaration
public void SetTemperatureCompensation(bool enable)

Parameters

Type Name Description
bool enable

true to enable temperature compensation, false to disable it.

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Events

MagneticField3DUpdated

Event raised when magnetic field changes

Declaration
public event EventHandler<IChangeResult<MagneticField3D>> MagneticField3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<MagneticField3D>>

Remarks

Lis2Mdl
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Sensors.Motion.Lis2Mdl

Code Example

Lis2Mdl sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lis2Mdl(Device.CreateI2cBus());

    // classical .NET events can also be used:
    sensor.Updated += HandleResult;

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Lis2Mdl.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

    sensor.StartUpdating(TimeSpan.FromMilliseconds(2000));

    return base.Initialize();
}

bool FilterResult(IChangeResult<MagneticField3D> result)
{
    return result.New.Z > new MagneticField(0.1, MagneticField.UnitType.Gauss);
}

void HandleResult(object sender,
    IChangeResult<MagneticField3D> result)
{
    var mag = result.New;

    Resolver.Log.Info($"MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, GyroZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub