Characteristic Locus
Inheritance System.Object > ADXL335
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Sensors.Motion
Assembly ADXL335.dll

Syntax

public class ADXL335

Remarks

The ADXL335 is a low power accelerometer capable of measuring +/- 3g of acceleration along three axes.

Purchasing

The ADXL335 sensor can be purchased on a breakout board from the following suppliers:

Examples

The ADXL335 can operate in interrupt and polling mode.

Interrupt Mode

The example below uses the default setting to check the sensor every 100 milliseconds. The sensor will generate and interrupt if the acceleration changes by more than 0.1g:

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Motion;

namespace ADXL335_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            var adxl335 = new ADXL335(AnalogChannels.ANALOG_PIN_A0, AnalogChannels.ANALOG_PIN_A1, AnalogChannels.ANALOG_PIN_A2);
            adxl335.SupplyVoltage = 3.3;
            adxl335.XVoltsPerG = 0.343;
            adxl335.YVoltsPerG = 0.287;
            adxl335.ZVoltsPerG = 0.541;

            // Attach an interrupt handler.            
            adxl335.AccelerationChanged += (s, e) =>
            {
                var rawData = adxl335.GetRawSensorData();
                Console.WriteLine("\n");
                Console.WriteLine("X: " + adxl335.X.ToString("F2") + ", " + rawData.X.ToString("F2"));
                Console.WriteLine("Y: " + adxl335.Y.ToString("F2") + ", " + rawData.Y.ToString("F2"));
                Console.WriteLine("Z: " + adxl335.Z.ToString("F2") + ", " + rawData.Z.ToString("F2"));
            };

            // Meadow can now go to sleep as the data will be processed
            // by the interrupt handler.
            Thread.Sleep(Timeout.Infinite);
        }
    }
}

Polling Mode

The following code will set up the sensor and display the G force and raw sensor data every 250 milliseconds:

using System.Threading;
using Meadow;
using Meadow.Foundation.Sensors.Motion;

namespace ADXL335_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        public App ()
        {
            ADXL335 adxl335 = new ADXL335(AnalogChannels.ANALOG_PIN_A0, AnalogChannels.ANALOG_PIN_A1, AnalogChannels.ANALOG_PIN_A2);
            adxl335.SupplyVoltage = 3.3;
            adxl335.XVoltsPerG = 0.343;
            adxl335.YVoltsPerG = 0.287;
            adxl335.ZVoltsPerG = 0.541;

            while (true)
            {
                ADXL335.Readings acceleration = adxl335.GetAcceleration();
                ADXL335.Readings rawData = adxl335.GetRawSensorData();

                Console.WriteLine("\n");
                Console.WriteLine("X: " + acceleration.X.ToString("F2") + ", " + rawData.X.ToString("F2"));
                Console.WriteLine("Y: " + acceleration.Y.ToString("F2") + ", " + rawData.Y.ToString("F2"));
                Console.WriteLine("Z: " + acceleration.Z.ToString("F2") + ", " + rawData.Z.ToString("F2"));
                Thread.Sleep(250);
            }
        }
    }
}
Example Circuit

The datasheet notes that bypass capacitors should be installed for the X, Y and Z outputs from the sensor. Both the Sparkfun and Adafruit breakout boards have 0.1uF capacitors installed on the board.

Constructors

View Source

ADXL335(IIODevice, IPin, IPin, IPin, UInt16, Double)

Declaration
public ADXL335(IIODevice device, IPin x, IPin y, IPin z, ushort updateInterval = 100, double accelerationChangeNotificationThreshold = 0.10000000149011612)

Parameters

Type Name Description
IIODevice device
IPin x
IPin y
IPin z
System.UInt16 updateInterval
System.Double accelerationChangeNotificationThreshold

Fields

View Source

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
System.UInt16

Properties

View Source

AccelerationChangeNotificationThreshold

Any changes in the acceleration that are greater than the acceleration threshold will cause an event to be raised when the instance is set to update automatically.

Declaration
public double AccelerationChangeNotificationThreshold { get; set; }

Property Value

Type Description
System.Double
View Source

SupplyVoltage

Declaration
public double SupplyVoltage { get; set; }

Property Value

Type Description
System.Double
View Source

X

Acceleration along the X-axis.

Declaration
public double X { get; }

Property Value

Type Description
System.Double

Remarks

This property will only contain valid data after a call to Read or after an interrupt has been generated.

View Source

XVoltsPerG

Volts per G for the X axis.

Declaration
public double XVoltsPerG { get; set; }

Property Value

Type Description
System.Double
View Source

Y

Acceleration along the Y-axis.

Declaration
public double Y { get; }

Property Value

Type Description
System.Double

Remarks

This property will only contain valid data after a call to Read or after an interrupt has been generated.

View Source

YVoltsPerG

Volts per G for the X axis.

Declaration
public double YVoltsPerG { get; set; }

Property Value

Type Description
System.Double
View Source

Z

Acceleration along the Z-axis.

Declaration
public double Z { get; }

Property Value

Type Description
System.Double

Remarks

This property will only contain valid data after a call to Read or after an interrupt has been generated.

View Source

ZVoltsPerG

Volts per G for the X axis.

Declaration
public double ZVoltsPerG { get; set; }

Property Value

Type Description
System.Double

Methods

View Source

GetRawSensorData()

Get the raw analog input values from the sensor.

Declaration
public Task<Vector> GetRawSensorData()

Returns

Type Description
System.Threading.Tasks.Task<Vector>

Vector object containing the raw sensor data from the analog pins.

View Source

Update()

Read the sensor output and convert the sensor readings into acceleration values.

Declaration
public Task Update()

Returns

Type Description
System.Threading.Tasks.Task

Events

View Source

AccelerationChanged

Event to be raised when the acceleration is greater than +/- AccelerationChangeNotificationThreshold.

Declaration
public event SensorVectorEventHandler AccelerationChanged

Event Type

Type Description
SensorVectorEventHandler