Characteristic | Locus |
---|---|
Inheritance | System.Object > ADXL362 |
Inherited Members | System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone() |
Namespace | Meadow.Foundation.Sensors.Motion |
Assembly | ADXL362.dll |
Syntax
public class ADXL362
Remarks
ADXL362 is an ultralow 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.
Purchasing
The ADXL362 is available on a small breakout board:
Examples
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.
Interrupt Example
The application below demonstrates how to connect an interrupt handler to the ADXL362 sensor and display changes only when the acceleration changes in the x, y or z axis by more than the acceleration threshold (default is 5 units):
using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Motion;
namespace ADXL362_Sample
{
public class Program
{
static IApp _app;
public static void Main()
{
_app = new App();
}
}
public class App : AppBase<F7Micro, App>
{
public App ()
{
Console.WriteLine("\n\n");
Console.WriteLine("ADXL362 Interrupt Example.");
Console.WriteLine("--------------------------");
var adxl362 = new ADXL362();
Console.WriteLine("Device ID: " + adxl362.DeviceID);
// Attach an interrupt handler.
adxl362.AccelerationChanged += (s, e) =>
{
Console.WriteLine(
"X: " + e.CurrentValue.X.ToString() +
", Y: " + e.CurrentValue.Y.ToString() +
", Z: " + e.CurrentValue.Z.ToString());
};
// Interrupts are attached so power on the sensor.
adxl362.SetPowerState(false, false, true, false, ADXL362.Frequency.EightHz);
// Put Meadow to sleep as the interrupt handler will deal
// with changes in acceleration.
Thread.Sleep(Timeout.Infinite);
}
}
}
Polling Example
The sensor is put into polling mode by setting the updateInterval
in the constructor to 0 milliseconds. The following application will read the sensor and output to the debug console every 500 milliseconds:
using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Motion;
namespace ADXL362_Sample
{
public class Program
{
static IApp _app;
public static void Main()
{
_app = new App();
}
}
public class App : AppBase<F7Micro, App>
{
public App ()
{
Console.WriteLine("\n\n");
Console.WriteLine("ADXL362 Polling Example.");
Console.WriteLine("------------------------");
ADXL362 adxl362 = new ADXL362(updateInterval: 0);
Console.WriteLine("Device ID: " + adxl362.DeviceID);
adxl362.SetPowerState(false, false, true, false, ADXL362.Frequency.EightHz);
while (true)
{
adxl362.Update();
Console.WriteLine(
"X: " + adxl362.X.ToString() +
", Y: " + adxl362.Y.ToString() +
", Z: " + adxl362.Z.ToString());
Thread.Sleep(500);
}
}
}
}
Example Circuit
Constructors
View SourceADXL362(IIODevice, ISpiBus, IPin, UInt16)
Create a new ADXL362 object using the specified SPI module.
Declaration
public ADXL362(IIODevice device, ISpiBus spiBus, IPin chipSelect, ushort speed = 10)
Parameters
Type | Name | Description |
---|---|---|
IIODevice | device | |
ISpiBus | spiBus | Spi Bus object |
IPin | chipSelect | Chip select pin. |
System.UInt16 | speed |
Fields
View Source_adxl362
ADXL362 sensor object.
Declaration
protected readonly ISpiPeripheral _adxl362
Field Value
Type | Description |
---|---|
ISpiPeripheral |
Properties
View SourceActivityDetected
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 |
Awake
Indicate if the sensor is awake or inactive.
Declaration
public bool Awake { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
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 |
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
Sensor temperature.
Declaration
public double Temperature { get; }
Property Value
Type | Description |
---|---|
System.Double |
X
X-axis sensor reading.
Declaration
public short X { get; }
Property Value
Type | Description |
---|---|
System.Int16 |
Remarks
Read must be called before this property is valid.
Y
Y-axis sensor reading.
Declaration
public short Y { get; }
Property Value
Type | Description |
---|---|
System.Int16 |
Remarks
Read must be called before this property is valid.
Z
Z-axis sensor reading.
Declaration
public short Z { get; }
Property Value
Type | Description |
---|---|
System.Int16 |
Remarks
Read must be called before this property is valid.
Methods
View SourceConfigureActivityThreshold(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 |
ConfigureInterrupts(IIODevice, Byte, IPin, Byte, IPin)
Configure the interrupts for the ADXL362.
Declaration
public void ConfigureInterrupts(IIODevice device, byte interruptMap1, IPin interruptPin1, byte interruptMap2 = 0, IPin interruptPin2 = null)
Parameters
Type | Name | Description |
---|---|---|
IIODevice | device | |
System.Byte | interruptMap1 | Bit mask for interrupt pin 1 |
IPin | interruptPin1 | Pin connected to interrupt pin 1 on the ADXL362. |
System.Byte | interruptMap2 | Bit mask for interrupt pin 2 |
IPin | interruptPin2 | Pin connected to interrupt pin 2 on the ADXL362. |
DisplayRegisters()
Display the register contents.
Declaration
public void DisplayRegisters()
Reset()
Reset the sensor.
Declaration
public void Reset()
Start()
Start making sensor readings.
Declaration
public void Start()
Stop()
Stop sensor readings.
Declaration
public void Stop()
Update()
Read the sensors and make the readings available through the X, Y and Z properties.
Declaration
public void Update()
Events
View SourceAccelerationChanged
Event to be raised when the acceleration is greater than the activity registers.
Declaration
public event SensorVectorEventHandler AccelerationChanged
Event Type
Type | Description |
---|---|
SensorVectorEventHandler |