Package Tracker – Accelerometer

Understanding the accelerometer proved to be tricky. Finding answers required much searching and reading. The raw output collected in the CSV file may seem perplexing if you are new to microcontrollers. Upon first examination, I thought that my device was broken: several axes seemed to vacillate wildly between 0 and 255 with even the slightest movement.

Since the accelerometer measures to +/- 2g, and it senses the acceleration of gravity, I expected, with the device at rest to measure the X and Y axis at 128 and the Z axis at near 196. Section 2.2.2 of the LIS302DL datasheet,  explains several important points:

1. Output from the device is “expressed as a 2’s complement number“.
2. Zero g output “can slightly change after mounting the sensor onto a printed circuit board”.

Zero gravity then is measured as 0 binary, ignoring any offset. You may scour the remaining 41 pages of the document and you will not find the scaling factor. In other words, when the output changes by one bit, how much acceleration does this bit represent? To find out how acceleration is measured you’ll need ST’s application note AN2335. In section 9.3, it states that “each LSB corresponds to 18mg”. Thus 1.0 g = approximately 55 decimal (110111 binary). To scale the data in the CSV file you’ll need to use the handy basic linear equitation for each axis:

Y = mx +b

m = 0.018g
x = the normalized output of the accelerator (output in +127 to -128 form)
b = the offset from zero measured on your individual sensor

What about this two’s complement stuff? In Ms Excel, it is not pretty. Excel doesn’t seem to have many binary manipulation functions. After finding DEC2BIN I came up short and hacked a formula. Read numbers from zero to 127 as is and for larger numbers subtract 256. I may be off a digit. Calculations that are off a digit are a common mistake in binary math, and I didn’t check this work closely yet.

accelerometer output

accelerometer output


What remains for me to discover is: how can I separate the acceleration of gravity (g) from acceleration (a), the change in velocity / change in time? My recollection of the old electromechanical accelerometers is that they only measure change in motion, but I may be mistaken.


~ by ratdad on January 3, 2009.

5 Responses to “Package Tracker – Accelerometer”

  1. Hi,

    thank you very much for sharing your findings, I’ve found your pages very helpful in getting started with the package tracker.

    You mention the scaling factor is not listed in the document. In table 3 (on page 10) they list the sensitivity values for the accelerometers as typically 18 or 72 mg/digit depending on which measuring range mode you are operating in.

    The manual also has a common sense way of calibrating (in section 2.5.1 on page 14) by turning the unit over (perpendicular to earth) and hence putting it through an acceleration change of +/-1g.

    Regards to separating the acceleration of gravity. Any physical measuring device can not separate them (to the best of my knowledge) so you are into solving by measuring and then applying corrections based on tilt angle to gravity, etc. I’m not experienced in this but further reading on gyroscopes and inclinometers would be where I’d start. The rc groups seem to raise similar issues frequently.

    Thanks again, your pages are very helpful!


  2. Hi,
    I’m not a programmer, but for some reason my masters committed asked me to develop a thesis using this product. As a mechanical engineer I know a little about what’s going on, but most of it is over my head. Out of the box, I’m able to power on the ADXL345 and store data on the card. I can even pull the data off in the form if a CVS, but then I’m lost. I really only need the GPS and accelerometer information, I would like to turn off the other features and increase the accelerometer sample rate, and turn off the sleep mode. Being able to make scene of the CVS file would be a great start, any advice?

    • What is your thesis Title? How does the Package Tracker fit in?

      • The idea is to use the accelerometer on the package tracker to record motion characteristics on different animals, I don’t have a title yet.

  3. I hope you’re working on larger animals as the package tracker with battery, is too large for smaller animals like cats or most dogs. Also, I’m curious about how you retreive the package tracker to get obtain its data.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: