Remarks

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

The ADXL337 is a low power accelerometer capable of measuring +/- 3g of acceleration along three axes. The ADXL337 is controlled via I2C.

Code Example

Adxl337 sensor;

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

    // create the sensor driver
    sensor = new Adxl337(Device.Pins.A00, Device.Pins.A01, Device.Pins.A02, null);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Accel: [X:{result.New.X.MetersPerSecondSquared:N2}," +
            $"Y:{result.New.Y.MetersPerSecondSquared:N2}," +
            $"Z:{result.New.Z.MetersPerSecondSquared:N2} (m/s^2)]");
    };

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Adxl337.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: [x] changed by threshold; new [x]: X:{result.New.X:N2}, old: X:{result.Old?.X:N2}"),
        // only notify if there's a greater than 1G change in the Z direction
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return ((result.New - old).Z > new Acceleration(1, AU.Gravity));
            }
            return false;
        });
    sensor.Subscribe(consumer);

    return Task.CompletedTask;
}

public async override Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($"Accel: [X:{result.X.MetersPerSecondSquared:N2}," +
        $"Y:{result.Y.MetersPerSecondSquared:N2}," +
        $"Z:{result.Z.MetersPerSecondSquared:N2} (m/s^2)]");

    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

Sample project(s) available on GitHub

Wiring Example

Characteristic Locus
Inheritance object ObservableBase<Acceleration3D> SamplingSensorBase<Acceleration3D> PollingSensorBase<Acceleration3D> Adxl3xxBase > Adxl337
Implements IObservable<IChangeResult<Acceleration3D>> IAccelerometer ISamplingSensor<Acceleration3D> ISensor<Acceleration3D> IDisposable
Inherited Members Adxl3xxBase.Acceleration3DUpdated Adxl3xxBase.XAnalogInputPort Adxl3xxBase.YAnalogInputPort Adxl3xxBase.ZAnalogInputPort Adxl3xxBase.SupplyVoltage Adxl3xxBase.GravityRange Adxl3xxBase.Acceleration3D Adxl3xxBase.IsDisposed Adxl3xxBase.RaiseEventsAndNotify(IChangeResult<Acceleration3D>) Adxl3xxBase.ReadSensor() Adxl3xxBase.VoltageToGravity(Voltage) Adxl3xxBase.Dispose() Adxl3xxBase.Dispose(bool) PollingSensorBase<Acceleration3D>.StartUpdating(TimeSpan?) PollingSensorBase<Acceleration3D>.StopUpdating() SamplingSensorBase<Acceleration3D>.samplingLock SamplingSensorBase<Acceleration3D>.Updated SamplingSensorBase<Acceleration3D>.SamplingTokenSource SamplingSensorBase<Acceleration3D>.Conditions SamplingSensorBase<Acceleration3D>.IsSampling SamplingSensorBase<Acceleration3D>.UpdateInterval SamplingSensorBase<Acceleration3D>.Read() ObservableBase<Acceleration3D>.observers ObservableBase<Acceleration3D>.NotifyObservers(IChangeResult<Acceleration3D>) ObservableBase<Acceleration3D>.Subscribe(IObserver<IChangeResult<Acceleration3D>>) ObservableBase<Acceleration3D>.CreateObserver(Action<IChangeResult<Acceleration3D>>, Predicate<IChangeResult<Acceleration3D>>) 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 Adxl3xx.dll

Syntax

public class Adxl337 : Adxl3xxBase, IObservable<IChangeResult<Acceleration3D>>, IAccelerometer, ISamplingSensor<Acceleration3D>, ISensor<Acceleration3D>, IDisposable

Constructors

Adxl337(IPin, IPin, IPin, Voltage?)

Create a new ADXL335 sensor object

Declaration
public Adxl337(IPin xPin, IPin yPin, IPin zPin, Voltage? supplyVoltage)

Parameters

Type Name Description
IPin xPin

Analog pin connected to the X axis output from the ADXL335 sensor

IPin yPin

Analog pin connected to the Y axis output from the ADXL335 sensor

IPin zPin

Analog pin connected to the Z axis output from the ADXL335 sensor

Voltage? supplyVoltage

The voltage supplied to the sensor. Defaults to 3.3V if null

Remarks

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

The ADXL337 is a low power accelerometer capable of measuring +/- 3g of acceleration along three axes. The ADXL337 is controlled via I2C.

Code Example

Adxl337 sensor;

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

    // create the sensor driver
    sensor = new Adxl337(Device.Pins.A00, Device.Pins.A01, Device.Pins.A02, null);

    // classical .NET events can also be used:
    sensor.Updated += (sender, result) =>
    {
        Resolver.Log.Info($"Accel: [X:{result.New.X.MetersPerSecondSquared:N2}," +
            $"Y:{result.New.Y.MetersPerSecondSquared:N2}," +
            $"Z:{result.New.Z.MetersPerSecondSquared:N2} (m/s^2)]");
    };

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Adxl337.CreateObserver(
        handler: result => Resolver.Log.Info($"Observer: [x] changed by threshold; new [x]: X:{result.New.X:N2}, old: X:{result.Old?.X:N2}"),
        // only notify if there's a greater than 1G change in the Z direction
        filter: result =>
        {
            if (result.Old is { } old)
            {
                return ((result.New - old).Z > new Acceleration(1, AU.Gravity));
            }
            return false;
        });
    sensor.Subscribe(consumer);

    return Task.CompletedTask;
}

public async override Task Run()
{
    var result = await sensor.Read();
    Resolver.Log.Info("Initial Readings:");
    Resolver.Log.Info($"Accel: [X:{result.X.MetersPerSecondSquared:N2}," +
        $"Y:{result.Y.MetersPerSecondSquared:N2}," +
        $"Z:{result.Z.MetersPerSecondSquared:N2} (m/s^2)]");

    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

Sample project(s) available on GitHub

Wiring Example