Skip to main content

Meadow.Foundation.Sensors.Motion.Adxl345

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