Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

Characteristic Locus
Inheritance object ObservableBase<Acceleration3D> SamplingSensorBase<Acceleration3D> PollingSensorBase<Acceleration3D> ByteCommsSensorBase<Acceleration3D> > Adxl345
Implements IObservable<IChangeResult<Acceleration3D>> IDisposable IAccelerometer ISamplingSensor<Acceleration3D> ISensor<Acceleration3D> II2cPeripheral
Inherited Members ByteCommsSensorBase<Acceleration3D>.BusComms ByteCommsSensorBase<Acceleration3D>.ReadBuffer ByteCommsSensorBase<Acceleration3D>.WriteBuffer ByteCommsSensorBase<Acceleration3D>.Init(int, int) ByteCommsSensorBase<Acceleration3D>.Dispose(bool) ByteCommsSensorBase<Acceleration3D>.Dispose() 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 Adxl345 : ByteCommsSensorBase<Acceleration3D>, IObservable<IChangeResult<Acceleration3D>>, IDisposable, IAccelerometer, ISamplingSensor<Acceleration3D>, ISensor<Acceleration3D>, II2cPeripheral

Constructors

Adxl345(II2cBus, Addresses)

Create a new instance of the ADXL345 communicating over the I2C interface

Declaration
public Adxl345(II2cBus i2cBus, Adxl345.Addresses address = Addresses.Address_0x53)

Parameters

Type Name Description
II2cBus i2cBus

I2C bus

Adxl345.Addresses address

Address of the I2C sensor

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

Adxl345(II2cBus, byte)

Create a new instance of the ADXL345 communicating over the I2C interface

Declaration
public Adxl345(II2cBus i2cBus, byte address)

Parameters

Type Name Description
II2cBus i2cBus

I2C bus

byte address

Address of the I2C sensor

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

Fields

MinimumPollingPeriod

Minimum value that can be used for the update interval when the sensor is being configured to generate interrupts

Declaration
public const ushort MinimumPollingPeriod = 100

Field Value

Type Description
ushort

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

Properties

Acceleration3D

Current acceleration

Declaration
public Acceleration3D? Acceleration3D { get; }

Property Value

Type Description
Acceleration3D?

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

DefaultI2cAddress

The default I2C address for the peripheral

Declaration
public byte DefaultI2cAddress { get; }

Property Value

Type Description
byte

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

OffsetX

Values stored in this register are automatically added to the X reading

Declaration
public sbyte OffsetX { get; set; }

Property Value

Type Description
sbyte

Remarks

Scale factor is 15.6 mg/LSB so 0x7f represents an offset of 2g

OffsetY

Values stored in this register are automatically added to the Y reading

Declaration
public sbyte OffsetY { get; set; }

Property Value

Type Description
sbyte

Remarks

Scale factor is 15.6 mg/LSB so 0x7f represents an offset of 2g

OffsetZ

Values stored in this register are automatically added to the Z reading

Declaration
public sbyte OffsetZ { get; set; }

Property Value

Type Description
sbyte

Remarks

Scale factor is 15.6 mg/LSB so 0x7f represents an offset of 2g

Methods

DisplayRegisters()

Dump the registers to the debug output stream.

Declaration
public void DisplayRegisters()

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

RaiseEventsAndNotify(IChangeResult<Acceleration3D>)

Raise changed event for subscribers

Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Acceleration3D> changeResult)

Parameters

Type Name Description
IChangeResult<Acceleration3D> changeResult

Overrides

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

ReadSensor()

Read sensor

Declaration
protected override Task<Acceleration3D> ReadSensor()

Returns

Type Description
Task<Acceleration3D>

Current acceleration

Overrides

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

SetDataFormat(bool, bool, bool, bool, GForceRanges)

Configure the data format (see pages 26 and 27 of the data sheet).

Declaration
public void SetDataFormat(bool selfTest, bool spiMode, bool fullResolution, bool justification, Adxl345.GForceRanges range)

Parameters

Type Name Description
bool selfTest

Put the device into self test mode when true

bool spiMode

Use 3-wire SPI (true) or 4-wire SPI (false)

bool fullResolution

Set to full resolution (true) or 10-bit mode using the range determined by the range parameter (false).

bool justification

Left-justified when true, right justified with sign extension when false

Adxl345.GForceRanges range

Set the range of the sensor to 2g, 4g, 8g or 16g

Remarks

The range of the sensor is determined by the following table: 0: +/- 2g 1: +/- 4g 2: +/- 8g 3: +/ 16g

SetDataRate(byte, bool)

Set the data rate and low power mode for the sensor.

Declaration
public void SetDataRate(byte dataRate, bool lowPower)

Parameters

Type Name Description
byte dataRate

Data rate for the sensor

bool lowPower

Setting this to true will enter low power mode (note measurement will encounter more noise in this mode).

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

SetPowerState(bool, bool, bool, bool, Frequencies)

Set the PowerControl register (see pages 25 and 26 of the data sheet)

Declaration
public void SetPowerState(bool linkActivityAndInactivity, bool autoSleep, bool measuring, bool sleep, Adxl345.Frequencies frequency)

Parameters

Type Name Description
bool linkActivityAndInactivity

Link the activity and inactivity events

bool autoSleep

Enable / disable auto sleep when the activity and inactivity are linked

bool measuring

Enable or disable measurements (turn on or off)

bool sleep

Put the part to sleep (true) or run in normal more (false)

Adxl345.Frequencies frequency

Frequency of measurements when the part is in sleep mode

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example

Events

Acceleration3DUpdated

Event raised when acceleration changes

Declaration
public event EventHandler<IChangeResult<Acceleration3D>> Acceleration3DUpdated

Event Type

Type Description
EventHandler<IChangeResult<Acceleration3D>>

Remarks

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

The ADXL345 is a small, low power, triple axis acceleration sensor capable of measuring up to +/-16g with a resolution of 13-bits.

The ADXL345 is controlled via I2C.

The ADXL345 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.

Code Example

Adxl345 sensor;

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

    sensor = new Adxl345(Device.CreateI2cBus());
    sensor.SetPowerState(false, false, true, false, Adxl345.Frequencies.TwoHz);

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

    //==== one-off read
    ReadConditions().Wait();

    // start updating
    sensor.StartUpdating(TimeSpan.FromMilliseconds(500));
}

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

Sample project(s) available on GitHub

Wiring Example