Meadow.Foundation.Sensors.Motion.Adxl345
| Adxl345 | |
|---|---|
| Status | |
| Source code | GitHub | 
| Datasheet(s) | GitHub | 
| NuGet package | 
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 override Task Initialize()
{
    Resolver.Log.Info("Initialize...");
    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) =>
    {
        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