Tilt Sensing - ADXL345

Hello tech people.

I am new to this forum. I have searched the forum and other places but can’t find my answer.

I want to understand how to use the ADXL345 (SEN-09836) with the SparkFun Redboard (DEV-13975) as described in the tutorial (https://learn.sparkfun.com/tutorials/ad … -guide/all).

I am getting data back as described but what does the data mean? If the scale is set to 2g max, how is it that I get whole numbers ranging from zero to several hundred? Are the units in milli-g’s? At the 2 or 4 g scale the resolution should be 10 or 11 bits according to the data sheet (https://www.sparkfun.com/datasheets/Sen … DXL345.pdf), so I would expect a calibration at 1 g to yield something like 1000, not 1 as in the calibration example.

Please help and forgive me if I am overlooking something simple

  • InventorDad

Hi InventorDad,

You’re definitely not overlooking something simple. From what I understand, the output is actually just the decimal value of the [10-bit buffer for each axis so, for example, with the ADXL345 set to +/-2g the output on the serial terminal should range from +/-512 (with a full range of 1024). This works well for applications that do not need precision measurements of acceleration data and why the ADXL345 works great for motion-detection applications with no calibration needed. If you need precision measurements, that is where the [Calibration Procedure comes in handy. The [Application Note from Analog Devices has some in-depth information on the calibration techniques and formulae involved.

I hope this helps explain what the example code outputs. Let us know if you have any other questions or concerns about the ADXL345 and we would be happy to help as much as we can.](AN-1057: Using an Accelerometer for Inclination Sensing | Analog Devices)](ADXL345 Hookup Guide - SparkFun Learn)](SparkFun_ADXL345_Arduino_Library/src/SparkFun_ADXL345.cpp at master · sparkfun/SparkFun_ADXL345_Arduino_Library · GitHub)

Yes, that is what I found but I forgot to go +/- 512 instead of 1024 one direction. Seems to work pretty well. I will optimize those calibration scaling formulas and share them.

But an additional question:

I see the header file that calls up alot of functions but where are the code lines for the functions? I would like to reconstruct the library for use with a pic or other chip but I would like to see how the arduino calls up the SPI communications with the specific 16 bit registers in the ADXL345.

Is there a .c file for the header somewhere?

Hi again,

The [source files for the library will have the header(.h) and C++(.cpp) files the library uses. Both of those files should have a few notes as well or at least “titles” for each function for you to search and adapt for your customization of the library.](SparkFun_ADXL345_Arduino_Library/src at master · sparkfun/SparkFun_ADXL345_Arduino_Library · GitHub)

I could not find .c files, just the .h files which is like watching movie trailers…I see the stuff I want but only enticing names with no details!

If you could send the link to the .c files that match the .h file that would be superb!

Here’s a [direct link to the .cpp file](SparkFun_ADXL345_Arduino_Library/src/SparkFun_ADXL345.cpp at master · sparkfun/SparkFun_ADXL345_Arduino_Library · GitHub)