Giter Site home page Giter Site logo

sparkfun_adxl345_arduino_library's Introduction

ADXL345

Sparkfun's I2C/SPI Arduino Library for ADXL345

Using this Arduino Library, you have the option of using either SPI or I2C to communicate with the ADXL345.

It is fairly reasonable to use and straight forward.

You will also be able to calibrate the ADXL345 whenever necessary as shown in the example.

SparkFun ADXL345 Arduino Library

SparkFun ADXL345

SparkFun Triple Axis Accelerometer Breakout - ADXL345

The ADXL345 is a small, thin, low power, 3-axis MEMS accelerometer with high resolution (13-bit) measurement at up to +-16 g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface.

The ADXL345 is well suited to measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (4 mg/LSB) enables measurement of inclination changes less than 1.0 degrees.

This Arduino library allows for both SPI or I2C communication. It also gives the user the ability to explore the following customizable features: tap/double tap detection, acvitivty/inactivity monitoring, and free fall detection.

Repository Contents

  • /examples - Example sketches for the library (SparkFun_ADXL345_Example.ino and SparkFun_ADXL345_Calibration.ino). Run these from the Arduino IDE.
  • Source files for the library (SparkFun_ADXL345.cpp and SparkFun_ADXL345.h).
  • keywords.txt - Keywords from this library that will be highlighted in the Arduino IDE.

Documentation

Products that use this Library

  • SparkFun Triple Axis Accelerometer Breakout - ADXL345 - PRT-9836- The ADXL345 is a small, thin, low power, 3-axis MEMS accelerometer with high resolution (13-bit) measurement at up to +-16 g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface.

Version History

  • 1.0.0 - Initial release of the Triple Axis Accelerometer Breakout - ADXL345 SparkFun Library.

License Information

This product is open source!

Please review the LICENSE.md file for license information.

If you have any questions or concerns on licensing, please contact [email protected].

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

sparkfun_adxl345_arduino_library's People

Contributors

elizabethsrobert avatar loricrotser avatar nseidle avatar paulstoffregen avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparkfun_adxl345_arduino_library's Issues

Interrupt

Has anyone successfully tested and found the interrupt to work when a freefall, tap, or activity event occurred?

SPI.setDataMode() deprecated

I was wondering if it would be valuable to update some of the SPI code. I'm referring to lines 49-52 in "SparkFun_ADXL345.cpp":

SPI.begin();
SPI.setDataMode(SPI_MODE3);
pinMode(_CS, OUTPUT);
digitalWrite(_CS, HIGH);

It seems that SPI.setDataMode() is deprecated (https://www.arduino.cc/en/Reference/SPISetDataMode) and that SPISettings(), SPI.beginTransaction() and SPI.endTransaction() should be used in the writeToSPI() and readFromSPI() functions.

Also, is it necessary to pull CS/SS high, since SPI.begin() says it does this already? https://www.arduino.cc/en/Reference/SPIBegin

No Wire.endTransmission() needed after Wire.requestFrom().

In the file "SparkFun_ADXL345.cpp", in the function "readFromI2C()", there is a Wire.endTransmission() after the Wire.requestFrom(). The Wire.endTransmission() should only be used when writing data, because the Wire.requestFrom() is a complete i2c session on its own.

No LICENSE.md

README.md mentions a non-existent LICENSE.md file. There is no clear license attached to the code but SparkFun_ADXL345.cpp states:

Modified Bildr ADXL345 Source File @ http://code.bildr.org/download/959.zip to support both I2C and SPI Communication

The linked zip is no longer available but appears to be mirrored at https://github.com/bildr-org/ADXL345

The original library is licensed under GPLv2 with only the example licensed under MIT.

Has the GPLv2 license therefore been inherited by the library in this fork and MIT license on at least one of the examples? Is that combination even valid?

Negative values not working?

When reading the values via readAccel(int* x, int* y, int* z), three integers are returned. But their values are never negative. Instead small negative values become huge positive numbers (e.g. 65540).

Is that supposed to happen? Am I using it wrong?

PS: I used your example code, unmodified. I compiled with PlatformIO and ran it on a SparkFun ESP32Thing.

g calculation correct for 2g range but wrong for other ranges

The floating point gains built into the library are handy, but are correct only for the 2g range; you'll get erroneous results when using the .get_Gxyz() function and a range other than 2. A solution in .get_Gxyz() would be to multiply each result by (range/2), e.g. 8 for the 16g range.

New release and platformio registry update

Hello

There are a few very important updates on the repo, specially this one: 6d795cc

Without that commit the communication though i2c doesn't work, at least using the Espressive arduino framework (ESP32, ESP8266, etc)

Are there plans to release a new version and update the platformio registry?

https://registry.platformio.org/libraries/sparkfun/SparkFun%20ADXL345%20Arduino%20Library

Tell me if I can help with that somehow.

Thank you and appreciated in advance.

Strange actions in powerOn()

Hello, in function powerOn() I see that whole register POWER_CTL value instantly being changed from 0 to 16 and eventually to 8.

writeTo(ADXL345_POWER_CTL, 0);	// Wakeup
writeTo(ADXL345_POWER_CTL, 16);	// Auto_Sleep
writeTo(ADXL345_POWER_CTL, 8);	// Measure

Maybe you wanted to set all these bits ( 8Hz Frequency and AutoSleep and Measuring mode )? e.g. 24?

Library not working correctly on Feather nRF52 SPI connection

Hello,
I’m experiencing some issue in trying to make ADXL345 accelerometer works in SPI by using an nRF52 feather.

Here are the connections

nrf52              ADXL345
SCK                SCL
MISO              SDO
MOSI              SDA
PIN 11              CS

The same code I’m posting works perfectly on my Arduino Uno, but if I try to run it on the feather it get stuck on powerOn method.

#include <SparkFun_ADXL345.h>         // SparkFun ADXL345 Library

ADXL345 adxl = ADXL345(11);           // USE FOR SPI COMMUNICATION, ADXL345(CS_PIN);

void setup(){
  
  Serial.begin(115200);                 // Start the serial terminal
    while ( !Serial ) delay(10);   // for nrf52840 with native usb
  pinMode(11, OUTPUT);
  Serial.println("SparkFun ADXL345 Accelerometer Hook Up Guide Example");
  Serial.println();
  adxl.powerOn();                     // Power on the ADXL345
  Serial.println("Setting range");

  adxl.setRangeSetting(16);           
  Serial.println("Setting 4 wire");
  adxl.setSpiBit(0);                  // Configure the device to be in 4 wire SPI mode when set to '0' or 3 wire SPI mode when set to 1

}

void loop(){
  
  // Accelerometer Readings
  int x,y,z;   
  adxl.readAccel(&x, &y, &z);         // Read the accelerometer values and store them in variables declared above x,y,z

  // Output Results to Serial
  Serial.print(x);
  Serial.print(", ");
  Serial.print(y);
  Serial.print(", ");
  Serial.println(z); 

}

To manage the ADXL345 I’m using the SparkFun library, investigating it’s source code I’m trying to figure out what could be wrong.
The initialization code in sparkfun starts the SPI Library and sets the mode to 3, it also configure the CS pin to OUTPUT as it supposed to be, the it puts the CS to HIGH.

ADXL345::ADXL345(int CS) {
	// ... other code
	_CS = CS;
	I2C = false;
	SPI.begin();
	SPI.setDataMode(SPI_MODE3);
	pinMode(_CS, OUTPUT);
	digitalWrite(_CS, HIGH);
}

The powerOn function sets the power settings on the sensor:

void ADXL345::powerOn() {
	// ... other code
	//ADXL345 TURN ON
	writeTo(ADXL345_POWER_CTL, 0);	// Wakeup     
	writeTo(ADXL345_POWER_CTL, 16);	// Auto_Sleep
	writeTo(ADXL345_POWER_CTL, 8);	// Measure
}

My code hangs exactly when I call powerOn(). I do not understand why since on my Arduino Uno works perfectly.

Thanks,
Andrea

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.