Skip to main content

Meadow.Foundation.Sensors.Motion.Adxl362

Adxl362
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet 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

Code Example

Adxl362 sensor;

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

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

// classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($"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)]");

Resolver.Log.Info($"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 => Resolver.Log.Info($"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)
{
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()
{
Resolver.Log.Info($"Device ID: {sensor.DeviceID}");

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

Resolver.Log.Info($"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

Class Adxl362

Driver for the ADXL362 triple axis accelerometer

Assembly: Adxl3xx.dll
View Source
Declaration
public class Adxl362 : ByteCommsSensorBase<(Acceleration3D? Acceleration3D, Temperature? Temperature)>, IObservable<IChangeResult<(Acceleration3D? Acceleration3D, Temperature? Temperature)>>, ISamplingSensor<(Acceleration3D? Acceleration3D, Temperature? Temperature)>, ISensor<(Acceleration3D? Acceleration3D, Temperature? Temperature)>, IDisposable, IAccelerometer, ISamplingSensor<Acceleration3D>, ISensor<Acceleration3D>, ITemperatureSensor, ISamplingSensor<Temperature>, ISensor<Temperature>, ISensor, ISamplingSensor, ISpiPeripheral

Inheritance: System.Object -> Meadow.Foundation.ObservableBase<UNIT>

Implements:

Expand

System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>>, Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>, Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>, System.IDisposable, Meadow.Peripherals.Sensors.Motion.IAccelerometer, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Acceleration3D>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Acceleration3D>, Meadow.Peripherals.Sensors.ITemperatureSensor, Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Temperature>, Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Temperature>, Meadow.Peripherals.Sensors.ISensor, Meadow.Peripherals.Sensors.ISamplingSensor, Meadow.Hardware.ISpiPeripheral

Properties

Acceleration3D

The current acceleration value

View Source
Declaration
public Acceleration3D? Acceleration3D { get; }

Temperature

The current temperature value

View Source
Declaration
public Temperature? Temperature { get; }

DefaultSpiBusSpeed

The default SPI bus speed for the device

View Source
Declaration
public Frequency DefaultSpiBusSpeed { get; }

SpiBusSpeed

The SPI bus speed for the device

View Source
Declaration
public Frequency SpiBusSpeed { get; set; }

DefaultSpiBusMode

The default SPI bus mode for the device

View Source
Declaration
public SpiClockConfiguration.Mode DefaultSpiBusMode { get; }

SpiBusMode

The SPI bus mode for the device

View Source
Declaration
public SpiClockConfiguration.Mode SpiBusMode { get; set; }

DataReady

Indicate of data is ready to be read

View Source
Declaration
public bool DataReady { get; }

FIFOReady

Indicate if there is any data in the FIFO buffer

View Source
Declaration
public bool FIFOReady { get; }

FIFOWatermark

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

View Source
Declaration
public bool FIFOWatermark { get; }

FIFOOverrun

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

View Source
Declaration
public bool FIFOOverrun { get; }

ActivityDetected

Indicate if any activity has been detected over the specified threshold

View Source
Declaration
public bool ActivityDetected { get; }

InactivityDetected

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

View Source
Declaration
public bool InactivityDetected { get; }

IsAwake

Indicate if the sensor is awake or inactive

View Source
Declaration
public bool IsAwake { get; }

DeviceID

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

View Source
Declaration
public int DeviceID { get; }

Status

Read the status register

View Source
Declaration
public byte Status { get; }

ActivityInactivityControl

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

View Source
Declaration
public byte ActivityInactivityControl { get; set; }

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

View Source
Declaration
public bool SelfTest { set; }

FilterControl

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

View Source
Declaration
public byte FilterControl { get; set; }

Methods

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

Raise events for subscribers and notify of value changes

View Source
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Acceleration3D? Acceleration3D, Temperature? Temperature)> changeResult)
Parameters
TypeNameDescription
Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>changeResultThe updated sensor data

Reset()

Reset the sensor

View Source
Declaration
public void Reset()

Start()

Start making sensor readings

View Source
Declaration
public void Start()

Stop()

Stop sensor readings

View Source
Declaration
public void Stop()

Read()

Read data from the sensor

View Source
Declaration
public override Task<(Acceleration3D? Acceleration3D, Temperature? Temperature)> Read()
Returns

System.Threading.Tasks.Task<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>: The sensor data### StartUpdating(TimeSpan?) Start updates

View Source
Declaration
public override void StartUpdating(TimeSpan? updateInterval = null)
Parameters
TypeNameDescription
System.Nullable<System.TimeSpan>updateIntervalThe update interval

StopUpdating()

Stop updating

View Source
Declaration
public override void StopUpdating()

ReadSensor()

Reads data from the sensor

View Source
Declaration
protected override Task<(Acceleration3D? Acceleration3D, Temperature? Temperature)> ReadSensor()
Returns

System.Threading.Tasks.Task<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>: The latest sensor reading### ConfigureActivityThreshold(ushort, byte) Configure the activity threshold and activity time. Once configured it will be necessary to set the activity/inactivity control and interrupts if required.

View Source
Declaration
public void ConfigureActivityThreshold(ushort threshold, byte numberOfSamples)
Parameters
TypeNameDescription
System.UInt16threshold11-bit unsigned value for the activity threshold.
System.BytenumberOfSamplesNumber of consecutive samples that must exceed the threshold

ConfigureInactivityThreshold(ushort, ushort)

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

View Source
Declaration
public void ConfigureInactivityThreshold(ushort threshold, ushort numberOfSamples)
Parameters
TypeNameDescription
System.UInt16threshold11-bit unsigned value for the activity threshold.
System.UInt16numberOfSamplesNumber of consecutive samples that must exceed the threshold

Implements

  • System.IObservable<Meadow.IChangeResult<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>>
  • Meadow.Peripherals.Sensors.ISamplingSensor<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>
  • Meadow.Peripherals.Sensors.ISensor<System.ValueTuple<System.Nullable<Meadow.Units.Acceleration3D>,System.Nullable<Meadow.Units.Temperature>>>
  • System.IDisposable
  • Meadow.Peripherals.Sensors.Motion.IAccelerometer
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Acceleration3D>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Acceleration3D>
  • Meadow.Peripherals.Sensors.ITemperatureSensor
  • Meadow.Peripherals.Sensors.ISamplingSensor<Meadow.Units.Temperature>
  • Meadow.Peripherals.Sensors.ISensor<Meadow.Units.Temperature>
  • Meadow.Peripherals.Sensors.ISensor
  • Meadow.Peripherals.Sensors.ISamplingSensor
  • Meadow.Hardware.ISpiPeripheral