Remarks

Adxl362
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Adxl362

ADXL362 is an ultra-low power, 3-axis MEMS accelerometer that consumes less than 2 μA at a 100 Hz output data rate and 270 nA when in motion triggered wake-up mode.

The ADXL362 is controlled via I2C.

Sample projects available on GitHub

Purchasing

The ADXL362 is available on a small breakout board:

Code Example

Adxl362 sensor;

public MeadowApp()
{
    Console.WriteLine("Initializing");

    // create the sensor driver
    sensor = new Adxl362(Device, Device.CreateSpiBus(), Device.Pins.D00);

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

        Console.WriteLine($"Temp: {result.New.Temperature?.Celsius:N2}C");
    };

    // Example that uses an IObservable subscription to only be notified when the filter is satisfied
    var consumer = Adxl362.CreateObserver(
        handler: result => Console.WriteLine($"Observer: [x] changed by threshold; new [x]: X:{result.New.Acceleration3D?.X.MetersPerSecondSquared:N2}, old: X:{result.Old?.Acceleration3D?.X.MetersPerSecondSquared:N2}"),
        filter: result => {
            if (result.Old is { } old) { //c# 8 pattern match syntax. checks for !null and assigns var.
                return ((result.New.Acceleration3D - old.Acceleration3D)?.Y > new Acceleration(1, AU.MetersPerSecondSquared));
            }
            return false;
        });
    sensor.Subscribe(consumer);
    //==== get the device id
    Console.WriteLine($"Device ID: {sensor.DeviceID}");
    //==== one-off read
    ReadConditions().Wait();
    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));
}

protected async Task ReadConditions()
{
    var result = await sensor.Read();
    Console.WriteLine("Initial Readings:");
    Console.WriteLine($"Accel: [X:{result.Acceleration3D?.X.MetersPerSecondSquared:N2}," +
        $"Y:{result.Acceleration3D?.Y.MetersPerSecondSquared:N2}," +
        $"Z:{result.Acceleration3D?.Z.MetersPerSecondSquared:N2} (m/s^2)]");

    Console.WriteLine($"Temp: {result.Temperature?.Celsius:N2}C");
}

Sample project(s) available on GitHub

Usage

The ADXL362 can operating in interrupt and polling mode. Polling applications are responsible for determining when a sensor is read. Interrupt applications will be notified when the sensor reading changes by + / - a threshold value.

Wiring Example

Characteristic Locus
Inheritance System.Object ObservableBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>> SensorBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>> SamplingSensorBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>> ByteCommsSensorBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>> > Adxl362
Implements IDisposable IAccelerometer ITemperatureSensor
Inherited Members ByteCommsSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.Peripheral ByteCommsSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.ReadBuffer ByteCommsSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.WriteBuffer ByteCommsSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.Init(Int32, Int32) ByteCommsSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.Dispose(Boolean) ByteCommsSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.Dispose() SamplingSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.StartUpdating(Nullable<TimeSpan>) SamplingSensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.StopUpdating() SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.Updated SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.samplingLock SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.SamplingTokenSource SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.Conditions SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.IsSampling SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.UpdateInterval SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.ReadSensor() SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.RaiseEventsAndNotify(IChangeResult<ValueTuple<Nullable<Acceleration3D>, Nullable<Units.Temperature>>>) SensorBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.Read() ObservableBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.observers ObservableBase<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>.NotifyObservers(IChangeResult<ValueTuple<Nullable<Acceleration3D>, Nullable<Units.Temperature>>>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>>.Subscribe(IObserver<>) Meadow.Foundation.ObservableBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>>.CreateObserver(Action<>, System.Nullable<Predicate<Meadow.IChangeResult<UNIT>>>)
Namespace Meadow.Foundation.Sensors.Motion
Assembly Adxl3xx.dll

Syntax

public class Adxl362 : ByteCommsSensorBase<(Acceleration3D? Acceleration3D, Units.Temperature? Temperature)>, IDisposable, IAccelerometer, ITemperatureSensor

Constructors

Adxl362(IDigitalOutputController, ISpiBus, IPin)

Create a new ADXL362 object using the specified SPI module.

Declaration
public Adxl362(IDigitalOutputController device, ISpiBus spiBus, IPin chipSelect)

Parameters

Type Name Description
IDigitalOutputController device
ISpiBus spiBus

Spi Bus object

IPin chipSelect

Chip select pin.

Properties

Acceleration3D

Declaration
public Acceleration3D? Acceleration3D { get; }

Property Value

Type Description
System.Nullable<Acceleration3D>

ActivityDetected

Indicate if any activity has been detected over the specified threshold.

Declaration
public bool ActivityDetected { get; }

Property Value

Type Description
System.Boolean

ActivityInactivityControl

Activity / Inactivity control register (see page 29 of the data sheet).

Declaration
public byte ActivityInactivityControl { get; set; }

Property Value

Type Description
System.Byte

DataReady

Indicate of data is ready to be read.

Declaration
public bool DataReady { get; }

Property Value

Type Description
System.Boolean

DeviceID

Read the device ID, MEMS ID, Part ID and silicon revision ID and encode the value in a 32-bit integer.

Declaration
public int DeviceID { get; }

Property Value

Type Description
System.Int32

FIFOOverrun

Indicate if the FIFO buffer has overrun (newly generated data is overwriting data already stored in the FIFO buffer.

Declaration
public bool FIFOOverrun { get; }

Property Value

Type Description
System.Boolean

FIFOReady

Indicate if there is any data in the FIFO buffer.

Declaration
public bool FIFOReady { get; }

Property Value

Type Description
System.Boolean

FIFOWatermark

Indicate if there are at least the desired number of samples in the FIFO buffer.

Declaration
public bool FIFOWatermark { get; }

Property Value

Type Description
System.Boolean

FilterControl

Get / set the filter control register (see page 33 of the data sheet).

Declaration
public byte FilterControl { get; set; }

Property Value

Type Description
System.Byte

InactivityDetected

Indicate if the sensor has detected inactivity or a free fall condition.

Declaration
public bool InactivityDetected { get; }

Property Value

Type Description
System.Boolean

IsAwake

Indicate if the sensor is awake or inactive.

Declaration
public bool IsAwake { get; }

Property Value

Type Description
System.Boolean

SelfTest

Set the value of the self test register. Setting this to true will put the device into self test mode, setting this to false will turn off the self test.

Declaration
public bool SelfTest { set; }

Property Value

Type Description
System.Boolean

Status

Read the status register.

Declaration
public byte Status { get; }

Property Value

Type Description
System.Byte

Temperature

Declaration
public Units.Temperature? Temperature { get; }

Property Value

Type Description
System.Nullable<Units.Temperature>

Methods

ConfigureActivityThreshold(UInt16, Byte)

Configure the activity threshold and activity time. Once configured it will be necessary to set the activity/inactivity control and interrupts if required.

Declaration
public void ConfigureActivityThreshold(ushort threshold, byte numberOfSamples)

Parameters

Type Name Description
System.UInt16 threshold

11-bit unsigned value for the activity threshold.

System.Byte numberOfSamples

Number of consecutive samples that must exceed the threshold

ConfigureInactivityThreshold(UInt16, UInt16)

Configure the inactivity threshold and activity time. Once configured it will be necessary to set the activity/inactivity control and interrupts if required.

Declaration
public void ConfigureInactivityThreshold(ushort threshold, ushort numberOfSamples)

Parameters

Type Name Description
System.UInt16 threshold

11-bit unsigned value for the activity threshold.

System.UInt16 numberOfSamples

Number of consecutive samples that must exceed the threshold

RaiseEventsAndNotify(IChangeResult<(Nullable<Acceleration3D> Acceleration3D, Nullable<Units.Temperature> Temperature)>)

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Acceleration3D? Acceleration3D, Units.Temperature? Temperature)> changeResult)

Parameters

Type Name Description
IChangeResult<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>> changeResult

Read()

Declaration
public override Task<(Acceleration3D? Acceleration3D, Units.Temperature? Temperature)> Read()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>>.Read()

ReadSensor()

Declaration
protected override Task<(Acceleration3D? Acceleration3D, Units.Temperature? Temperature)> ReadSensor()

Returns

Type Description
Task<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>>

Overrides

Meadow.Foundation.SensorBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>>.ReadSensor()

Reset()

Reset the sensor.

Declaration
public void Reset()

Start()

Start making sensor readings.

Declaration
public void Start()

StartUpdating(Nullable<TimeSpan>)

Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)

Parameters

Type Name Description
System.Nullable<TimeSpan> updateInterval

Stop()

Stop sensor readings.

Declaration
public void Stop()

StopUpdating()

Declaration
public override void StopUpdating()

Overrides

Meadow.Foundation.SamplingSensorBase<System.ValueTuple<System.Nullable<Acceleration3D>, System.Nullable<Units.Temperature>>>.StopUpdating()

Events

Acceleration3DUpdated

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> Acceleration3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>

TemperatureUpdated

Declaration
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>