Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object ObservableBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> PollingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> > Lsm303agr
Implements IObservable<IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>> ISamplingSensor<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> ISensor<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> IMagnetometer ISamplingSensor<MagneticField3D> ISensor<MagneticField3D> IAccelerometer ISamplingSensor<Acceleration3D> ISensor<Acceleration3D> II2cPeripheral
Inherited Members PollingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.StartUpdating(TimeSpan?) PollingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.StopUpdating() SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.samplingLock SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.Updated SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.SamplingTokenSource SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.Conditions SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.IsSampling SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.UpdateInterval SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.ReadSensor() SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.RaiseEventsAndNotify(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>) SamplingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.Read() ObservableBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.observers ObservableBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.NotifyObservers(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>) ObservableBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.Subscribe(IObserver<IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>>) ObservableBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>.CreateObserver(Action<IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>>, Predicate<IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>>) 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 Lsm303agr.dll

Syntax

public class Lsm303agr : PollingSensorBase<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>, IObservable<IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>>, ISamplingSensor<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>, ISensor<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>, IMagnetometer, ISamplingSensor<MagneticField3D>, ISensor<MagneticField3D>, IAccelerometer, ISamplingSensor<Acceleration3D>, ISensor<Acceleration3D>, II2cPeripheral

Constructors

Lsm303agr(II2cBus)

Create a new Lsm303agr instance

Declaration
public Lsm303agr(II2cBus i2cBus)

Parameters

Type Name Description
II2cBus i2cBus

The I2C bus connected to the sensor

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Properties

Acceleration3D

Current Acceleration 3D

Declaration
public Acceleration3D? Acceleration3D { get; }

Property Value

Type Description
Acceleration3D?

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

DefaultI2cAddress

The default I2C address for the peripheral

Declaration
public byte DefaultI2cAddress { get; }

Property Value

Type Description
byte

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={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

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Methods

GetAccelerometerOutputDataRate()

Retrieves the current output data rate setting for the accelerometer.

Declaration
public Lsm303agr.AccOutputDataRate GetAccelerometerOutputDataRate()

Returns

Type Description
Lsm303agr.AccOutputDataRate

The current output data rate setting.

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

GetAccelerometerSensitivity()

Retrieves the current sensitivity setting of the accelerometer

Declaration
public Lsm303agr.AccSensitivity GetAccelerometerSensitivity()

Returns

Type Description
Lsm303agr.AccSensitivity

The current sensitivity setting, represented by the AccSensitivity enum.

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

GetMagnetometerOutputDataRate()

Retrieves the current output data rate setting for the magnetometer.

Declaration
public Lsm303agr.MagOutputDataRate GetMagnetometerOutputDataRate()

Returns

Type Description
Lsm303agr.MagOutputDataRate

The current output data rate setting.

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

RaiseEventsAndNotify(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>)

Raise events for subscribers and notify of value changes

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

Parameters

Type Name Description
IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> changeResult

The updated sensor data

Overrides

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

ReadSensor()

Reads data from the sensor

Declaration
protected override Task<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> ReadSensor()

Returns

Type Description
Task<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)>

The latest sensor reading

Overrides

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetAccelerometerOutputDataRate(AccOutputDataRate)

Sets the output data rate for the accelerometer.

Declaration
public void SetAccelerometerOutputDataRate(Lsm303agr.AccOutputDataRate dataRate)

Parameters

Type Name Description
Lsm303agr.AccOutputDataRate dataRate

The desired output data rate setting.

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetAccelerometerSensitivity(AccSensitivity)

Sets the sensitivity of the accelerometer

Declaration
public void SetAccelerometerSensitivity(Lsm303agr.AccSensitivity sensitivity)

Parameters

Type Name Description
Lsm303agr.AccSensitivity sensitivity

The desired sensitivity setting, specified by the AccSensitivity enum.

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

SetMagnetometerOutputDataRate(MagOutputDataRate)

Sets the output data rate for the magnetometer.

Declaration
public void SetMagnetometerOutputDataRate(Lsm303agr.MagOutputDataRate dataRate)

Parameters

Type Name Description
Lsm303agr.MagOutputDataRate dataRate

The desired output data rate setting.

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

Events

Acceleration3DUpdated

Event raised when acceleration changes

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> Acceleration3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub

MagneticField3DUpdated

Event raised when magnetic field changes

Declaration
public event EventHandler<IChangeResult<MagneticField3D>> MagneticField3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<MagneticField3D>>

Remarks

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

Code Example

Lsm303agr sensor;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize hardware...");
    sensor = new Lsm303agr(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 = Lsm303agr.CreateObserver(handler: result => HandleResult(this, result),
                                         filter: result => FilterResult(result));

    sensor.Subscribe(consumer);

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

    return base.Initialize();
}

bool FilterResult(IChangeResult<(Acceleration3D? Acceleration3D, MagneticField3D? MagneticField3D)> result)
{
    return result.New.Acceleration3D.Value.Z > new Acceleration(0.1, Acceleration.UnitType.Gravity);
}

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

    Resolver.Log.Info($"AccelX={accel.X.Gravity:0.##}g, AccelY={accel.Y.Gravity:0.##}g, AccelZ={accel.Z.Gravity:0.##}g, MagX={mag.X.Gauss:0.##}gauss, MagY={mag.Y.Gauss:0.##}gauss, MagZ={mag.Z.Gauss:0.##}gauss");
}

Sample project(s) available on GitHub