Remarks

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

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 override Task Initialize()
{
    Console.WriteLine("Initialize...");

    // 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);

    return Task.CompletedTask;
}

public async override Task Run()
{
    Console.WriteLine($"Device ID: {sensor.DeviceID}");

    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");

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

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 > Adxl362
Implements IAccelerometer ITemperatureSensor
Namespace Meadow.Foundation.Sensors.Motion
Assembly Adxl3xx.dll

Syntax

public class Adxl362 : ByteCommsSensorBase<(Acceleration3D? Acceleration3D, Units.Temperature? Temperature)>, 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

The device connected to the sensor

ISpiBus spiBus

Spi Bus object

IPin chipSelect

Chip select pin

Properties

Acceleration3D

The current acceleration value

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

The current temperature value

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)>)

Raise events for subcribers and notify of value changes

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

The updated sensor data

Read()

Read data from the sensor

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

Returns

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

The sensor data

ReadSensor()

Reads data from the sensor

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

Returns

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

The latest sensor reading

Reset()

Reset the sensor

Declaration
public void Reset()

Start()

Start making sensor readings

Declaration
public void Start()

StartUpdating(Nullable<TimeSpan>)

Start updates

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

Parameters

Type Name Description
System.Nullable<TimeSpan> updateInterval

The update interval

Stop()

Stop sensor readings

Declaration
public void Stop()

StopUpdating()

Stop updating

Declaration
public override void StopUpdating()

Events

Acceleration3DUpdated

Raised when the acceleration value changes

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> Acceleration3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>

TemperatureUpdated

Raised when the temperature value changes

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

Event Type

Type Description
EventHandler<IChangeResult<Units.Temperature>>