Skip to main content

Iot.Device.Adxl345 assembly for .NET nanoFramework C# projects

Total Downloads
34.6K
34,591
Published
Aug 31, 2026
1mo ago

Get Started

dotnet add package nanoFramework.Iot.Device.Adxl345 --version 1.2.1040

No framework information available.

README

ADXL345 - Accelerometer

ADXL345 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16g.

Documentation

In Chinese

In English

Sensor Image

sensor

Usage

Important: make sure you properly setup the SPI pins especially for ESP32 before creating the SpiDevice, make sure you install the nanoFramework.Hardware.ESP32 nuget:

//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the SPI GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(22, DeviceFunction.SPI1_MISO);
Configuration.SetPinFunction(23, DeviceFunction.SPI1_CLOCK);
// Make sure as well you are using the right chip select

For other devices like STM32, please make sure you're using the preset pins for the SPI bus you want to use. The chip select can as well be pre setup.

SpiConnectionSettings settings = new SpiConnectionSettings(1, 42)
{
    ClockFrequency = Adxl345.SpiClockFrequency,
    Mode = Adxl345.SpiMode
};

var device = SpiDevice.Create(settings);

// set gravity measurement range ±4G
using (Adxl345 sensor = new Adxl345(device, GravityRange.Range04))
{
    // read acceleration
    Vector3 data = sensor.Acceleration;

    //use sensor
}

Example

Hardware Required

  • ADXL345
  • Male/Female Jumper Wires

Circuit

cicuit

  • VCC - 3.3 V
  • GND - GND
  • CS - CS
  • SDO - SPI1 MISO
  • SDA - SPI1 MOSI
  • SCL - SPI1 SCLK

Code

SpiConnectionSettings settings = new SpiConnectionSettings(1, 42)
{
    ClockFrequency = Adxl345.SpiClockFrequency,
    Mode = Adxl345.SpiMode
};
var device = SpiDevice.Create(settings);

// Set gravity measurement range ±4G
using (Adxl345 sensor = new Adxl345(device, GravityRange.Range04))
{
    // loop
    while (true)
    {
        // read data
        Vector3 data = sensor.Acceleration;

        Debug.WriteLine($"X: {data.X.ToString("0.00")} g");
        Debug.WriteLine($"Y: {data.Y.ToString("0.00")} g");
        Debug.WriteLine($"Z: {data.Z.ToString("0.00")} g");
        Debug.WriteLine();

        // wait for 500ms
        Thread.Sleep(500);
    }
}

Result

running result

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

No SPDX license expression is published. Review the license text and your organisation's policy before redistribution.No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.