Skip to main content

Meadow.Foundation.Sensors.Motion.Adxl343

Adxl343
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Motion.Adxl3xx

Code Example

Adxl343 sensor;

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

sensor = new Adxl343(Device.CreateI2cBus(), Adxl343.Addresses.Default);
sensor.SetPowerState(false, false, true, false, Adxl343.Frequencies.TwoHz);

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

return Task.CompletedTask;
}

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

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

Sample project(s) available on GitHub