Remarks

3-AxisDigitalAccelerometer1_5g
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Grove.Sensors.Motion.3-AxisDigitalAccelerometer1_5g

Code Example

ThreeAxisDigitalAccelerometer1_5g sensor;

public override Task Initialize()
{
    Console.WriteLine("Initializing");

    // create the sensor driver
    sensor = new ThreeAxisDigitalAccelerometer1_5g(Device.CreateI2cBus());

    // 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)]" +
            $" Direction: {sensor.Direction}" +
            $" Orientation: {sensor.Orientation}");
    };

    // Example that uses an IObersvable subscription to only be notified when the filter is satisfied
    var consumer = ThreeAxisDigitalAccelerometer1_5g.CreateObserver(
        handler: result => Console.WriteLine($"Observer: [x] changed by threshold; new [x]: X:{result.New.X:N2}, old: X:{result.Old?.X:N2}"),
        // only notify if there's a greater than 0.5G change in the Z direction
        filter: result => {
            if (result.Old is { } old)
            { //c# 8 pattern match syntax. checks for !null and assigns var.
                return (result.New - old).Z > new Acceleration(0.5, AU.Gravity);
            }
            return false;
        });
    sensor.Subscribe(consumer);

    return Task.CompletedTask;
}

public override Task Run()
{
    sensor.StartUpdating(TimeSpan.FromMilliseconds(1000));

    return Task.CompletedTask;
}

Sample project(s) available on GitHub

Wiring Example

To wire a Yx5300 to your Meadow board, connect the following:

ThreeAxisDigitalAccelerometer1_5g Meadow Pin
GND GND
VCC 3.3V
RX D01
TX D00
Characteristic Locus
Inheritance System.Object Mma7660fc > ThreeAxisDigitalAccelerometer1_5g
Implements IAccelerometer
Inherited Members Mma7660fc.Acceleration3DUpdated Mma7660fc.Acceleration3D Mma7660fc.Direction Mma7660fc.Orientation Mma7660fc.SetSampleRate(Mma7660fc.SampleRate) Mma7660fc.ReadSensor() Meadow.Foundation.Sensors.Motion.Mma7660fc.RaiseEventsAndNotify(IChangeResult<>)
Namespace Meadow.Foundation.Grove.Sensors.Motion
Assembly 3-AxisDigitalAccelerometer1_5g.dll

Syntax

public class ThreeAxisDigitalAccelerometer1_5g : Mma7660fc, IAccelerometer

Constructors

ThreeAxisDigitalAccelerometer1_5g(II2cBus)

Creates a new MoistureSensor driver

Declaration
public ThreeAxisDigitalAccelerometer1_5g(II2cBus i2cBus)

Parameters

Type Name Description
II2cBus i2cBus