Calibrating ADXL345 as per Sparkfun and Adafruit Guides - Calculations assist?


I am trying to calibrate a ADXL345 accelerator using the sparkfun and adafruit guides as per:

I used both as 1 was better in one area, and the other in another area, but regardless I am not sure how I go from the result to the calculated offsets and gain to modify the raw data.

As per the sparkfun guide linked above:


The offset values and gain factors are calculated with the following equations as stated in the Application Note from Analog Devices (page 8: equations 17 and 18).

In the DEFINED VARIABLES section of the code is where we will place the new calculated values for offset and gain.

/************** DEFINED VARIABLES **************/

/* */
#define offsetX 0 // OFFSET values
#define offsetY 0
#define offsetZ 0

#define gainX 1 // GAIN factors
#define gainY 1
#define gainZ 1

I am sorry if I am just being slow or if I am not clear on this, but I performed the calibration steps and the results for the 6 tests were:

Accel Minimums: -4  0  0
Accel Maximums: 0  3  276

Accel Minimums: -4  0  0
Accel Maximums: 12  258  276

Accel Minimums: -250  0  -6
Accel Maximums: 12  258  276

Accel Minimums: -250  -259  -6
Accel Maximums: 12  258  276

Accel Minimums: -250  -259  -6
Accel Maximums: 264  258  276

Accel Minimums: -250  -259  -230
Accel Maximums: 264  258  276

What I am missing is how do I go from those calibration results to the offset and gain values as per their formula?

Best overview here: Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers

I did a similar calibration using the SparkFun guide.

I made a little excel spreadsheet with the values (such as the ones at the bottom of your serial port's readout):
+1g -1g Gain Offset
X 246 -268 257 -5.5
Y 243 -264 253.5 -5.25
Z 238 -265 251.5 -6.75

The gain and offset values are from the two equations you posted:
For example: Gain for x = 0.5*(236-(-268)) and Offset for x = 0.5*(236+(-268)).

How did it work out for you? I'm still not getting the results I was expecting exactly (with the default increments of 62.5 mg per increment my z-axis is reading ~30 which looks like ~1.8g).