#raspberry-pi #driver #raspberry #pi #adxl345

adxl345_driver

Driver for Analog Device ADXL345/ADXL346 3-Axis Digital Accelerometer

1 unstable release

0.0.6 Oct 24, 2020

#1643 in Embedded development

MIT license

63KB
586 lines

adxl345_driver

This is an implementation of a hardware driver for a ADXL345 type 3-Axis Digital Accelerometer write in Rust using the rppal library. It exposes a simple trait-based API for the command set which minimizes the coupling between the hardware driver (I²C, etc) and the code that passes commands and data to and from the accelerometer.

Through the name says ADXL345 the driver should also work with the ADXL346 device as well since the only difference between them is the physical packaging and not the internal workings.

Table Of Contents

Getting Started

You will need to have a recent version of Rust installed. Any version of Rust that supports version 0.11.3 or later of rppal should work but versions from 1.43 to 1.47 of Rust have been used during initial development on both the nightly and release channels. Earlier versions might work as well but have not been tested.

Development can be done on any OS that Rust supports but the only expected output target is a Raspberry Pi running a Linux OS. All initial development has been done with a combination of a laptop running Windows 10 and a 4GB Raspberry Pi 4 running the Raspberry Pi OS (Raspbian).

Using The Crate

To use the crate in your own project all you need to do is include it in [dependencies] of you project like you would any other crate. If you have cargo-edit install then on the command line you can use:

cargo add adxl345_driver

Which should add something like this in your Cargo.toml:

[dependencies]
adxl345_driver = "0.0.5"

Examples

You will find examples in the examples directory. The Raspberry Pi I²C example was used for testing during initial development on a RPi 4.

To build the I²C example start by clone this project somewhere on your Raspberry Pi:

git clone https://github.com/Dragonrun1/adxl345_driver

Next execute the follow to build the example:

cargo build --example i2c

And finally execute:

sudo ./target/debug/examples/i2c

You should see the series of x, y, z values displayed in the terminal if your device has been hooked up using the primary I²C that the example expects.

Output example:

axis: {'x': 1.6083, 'y': 0.0392, 'z': 8.7868} m/s²
axis: {'x': 1.6867, 'y': 0.1177, 'z': 8.7868} m/s²
axis: {'x': 1.6475, 'y': 0.1177, 'z': 8.8260} m/s²
...

You can find the latest version by go to adxl345_driver on the crates.io website.

Contributing

Contributors are welcome. I would like to see the hardware drives extended beyond just the I²C interface but I currently don't have access to other hardware for development or testing using the SPI interface. Make sure you have read the Contributor Covenant Code of Conduct. All contributed code will be considered to also be contributed under a MIT license. Please include your information in a comment on all code files for the copyright etc.

All contributed documentation or non-code text like this README etc. will be consider to be under the same CC-BY-SA license.

Licenses

All code is available under the MIT license. You can find a copy of the license in the LICENSE file.

All documentation like this README is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License (CC-BY-SA).


Creative Commons License

Dependencies

~2MB
~46K SLoC