MMA7260QT Accelerometer Help

Hi,

I am very new to the whole Arduino community, I recently started working on a project that would monitor the motion of a persons chest, basically what I am planning on doing is using an accelerometer that would be placed on the persons chest (while they are laying down) and measure the z component to figure out how much movement is occurring.

Since I don't know much about what I am doing yet, I'm trying to take babysteps till I can accomplish this. The accelerometer I have is a Modern Device MMA7260QT 3-axis accelerometer but mine looks like this one:

I found this datasheet for it: http://www.freescale.com/files/sensors/doc/data_sheet/MMA7260QT.pdf

What I've done so far is hooked it up like this : (Sorry I don't have an image of it. I saw a link somewhere on how to generate a picture of the schematic but now I can't seem to find it!)

Arduino Accelerometer
3v3 Vin
3v3 GS1
GND GS2
GND GND
Analog 0 X0
Analog 1 Y0
Analog 2 Z0

I also have Sl not hooked up to anything.

It seems to be working "fine" when I run this code:

int x0;
int y0;
int z0;

void setup() 
{
  Serial.begin(9600);
}

void loop () 
{
  x0 = analogRead(0);
  y0 = analogRead(1);
  z0 = analogRead(2);
  
  Serial.print("X: ");
  Serial.print(x0);
  
  Serial.print(" Y: ");
  Serial.print(y0);
  
  Serial.print(" Z: ");
  Serial.println(z0);

  delay(100);
}

I get these outputs:

X: 276 Y: 310 Z: 195
X: 278 Y: 310 Z: 195
X: 275 Y: 311 Z: 194
X: 278 Y: 310 Z: 193
X: 278 Y: 311 Z: 196
X: 277 Y: 309 Z: 194
X: 277 Y: 310 Z: 195
X: 278 Y: 310 Z: 194
X: 265 Y: 311 Z: 196
X: 292 Y: 311 Z: 195
X: 279 Y: 311 Z: 195
X: 278 Y: 310 Z: 195
X: 277 Y: 310 Z: 196

These are from the sensor just sitting on my desk without any movement

I've spent the last few days searching arduino.cc and google on accelerometers and how to work with them and everything and I've found a few insightful websites but I can't seem to generate anything that corresponds to their examples.

I've read through this a few times: http://www.instructables.com/id/Accelerometer-Gyro-Tutorial/?ALLSTEPS (focussing on just the accelerometer part) but when I try to do this equation:

Rz = (AdcRz * Vref / 1023 - VzeroG) / Sensitivity

which would be:

Rz = (195 * 3.3 / 1023 - 1.65) / .6
Rz = -1.7

Like wise if I would do this with X (277) and Y (310) I get -1.2 for X and -1.08 for Y. Yet in the article he gets:

Rx = 0.5g
Ry = 0.79g
Rz = 0.33g

How come my initial numbers (that I see directly from the accelerometer displayed in the serial monitor) are so low that they turn out negative? or are they not that low. Everywhere I look online seems that people are having much higher readings than mine! I don't know what I'm doing wrong if anything I can't seem to figure this out!

I guess what I am trying to do is take the readings from the accelerometer and then be able to calculate a distance of how much movement occurred when the persons chest raised/lowered.

One last question, being that this accelerometer has a range of sensitivity modes, 1.5g, 2g, 4g, and 6g, what would you reccomend I use for the type of measurement I am monitoring.

Thanks for your time!
-Will

What's your AREF pin connected to?

If you want to measure 3.3V values consider calling "analogReference(EXTERNAL);" in setup() and then connecting 3V3 supply to AREF. The equations you give are assuming this. Alternatively use 5.0 as Vref in those equations to match the hardware setup.

Mark,

Thanks for the response. I didn't have my AREF pin connected to anything because I wasn't really aware of what it did.

I connected the AREF to 3V3 and added the analogReference(EXTERNAL); to my setup function, this resulted in the values going up to this:

X: 427 Y: 480 Z: 300
X: 426 Y: 475 Z: 300
X: 426 Y: 478 Z: 302
X: 425 Y: 480 Z: 301
X: 426 Y: 477 Z: 301
X: 427 Y: 479 Z: 302
X: 429 Y: 479 Z: 301
X: 427 Y: 478 Z: 300
X: 423 Y: 478 Z: 298
X: 426 Y: 478 Z: 302

Applying the formula:

X at 426 and Vref at 3.3 (would it be 5 even though I am still on 3V3 and now using AREF?) is -0.45
Y at 478 is -0.18
Z at 302 is -1.12

Trying out using 5.0 as my Vref with the original hardware setup (using the 3V3 pin without AREF) I still end up with all negative numbers.

Sorry for being such a novice in this matter!

Thanks
-Will

If you use your sensor just as in the photo, is it upside-down ?

If you check the datasheet, the zero-g is about 1.65V, but it's not calibrated. So you might have to calibrate the zero-g values to zero in program code.

I tried to calibrate the zero-g values.

This is my code:
I found something online and just changed it a bit to fit mine. I'm not sure if this is entirely correct.

const int ACC_X=A0; 
const int ACC_Y=A1;
const int ACC_Z=A2;

int acc_x_raw=0;
double center_x=0;
double acc_x=0.0;
  
int acc_y_raw=0;
double center_y=0;
double acc_y=0.0;
  
int acc_z_raw=0;
double center_z=0;
double acc_z=0.0;

void setup()
{
  Serial.begin(9600);
  analogReference(EXTERNAL);
  
  pinMode(ACC_X,INPUT);
  pinMode(ACC_Y,INPUT);
  pinMode(ACC_Z,INPUT);
  
  center_x = (double)analogRead(ACC_X) * 5.0 / 1024.0;
  center_y = (double)analogRead(ACC_Y) * 5.0 / 1024.0;
  center_z = (double)analogRead(ACC_Z) * 5.0 / 1024.0;
}

void loop()
{
    acc_x_raw = analogRead(ACC_X);
    acc_y_raw = analogRead(ACC_Y);
    acc_z_raw = analogRead(ACC_Z);
    
    Serial.print("X: "); 
    acc_x = ((double)acc_x_raw * 5.0 / 1024.0 - center_x ) / 0.6;
    Serial.print(acc_x);
    
    Serial.print(" Y: "); 
    acc_y = ((double)acc_y_raw * 5.0 / 1024.0 - center_y ) / 0.6;
    Serial.print(acc_y);
    
    Serial.print(" Z: "); 
    acc_z = ((double)acc_z_raw * 5.0 / 1024.0 - center_z ) / 0.6;
    Serial.println(acc_z);

    delay(200);
}

Here is the output when my accelerometer is just sitting on my desk:

X: 0.02 Y: 0.00 Z: 0.01
X: 0.01 Y: 0.00 Z: 0.01
X: 0.02 Y: -0.01 Z: 0.02
X: 0.03 Y: 0.00 Z: 0.01
X: 0.00 Y: 0.04 Z: 0.02
X: 0.02 Y: 0.01 Z: 0.02
X: 0.02 Y: 0.00 Z: 0.03
X: 0.01 Y: 0.00 Z: 0.02
X: 0.00 Y: -0.01 Z: 0.02
X: 0.01 Y: 0.01 Z: 0.01
X: 0.00 Y: 0.01 Z: 0.02
X: 0.00 Y: 0.01 Z: 0.01
X: 0.02 Y: 0.02 Z: 0.02

and here are the "raw" values (after changing the Serial.print and running the program again, so not the same values as above)

X: 427 Y: 477 Z: 299
X: 429 Y: 474 Z: 299
X: 427 Y: 476 Z: 300
X: 428 Y: 477 Z: 304
X: 428 Y: 473 Z: 300
X: 430 Y: 475 Z: 301
X: 430 Y: 476 Z: 301
X: 430 Y: 476 Z: 299
X: 428 Y: 476 Z: 300
X: 428 Y: 474 Z: 300
X: 428 Y: 473 Z: 298
X: 434 Y: 472 Z: 299
X: 426 Y: 475 Z: 298
X: 431 Y: 475 Z: 300

Is this a good way of doing it? Do these values seem valid?

Also, I don't know if its upside down because when I flip the accelerometer while its recording data the Z values go to around 2

Thanks!
-Will

That's good I think.

I don't know if your values are good 'g-force' values.

You use the offset to get everything close to 0.0.
For a balancing robot for example, the default for the Z-axis should be 1 g.
If the sensor is horizontal flat, the Z-axis is pointing up, and that would be 1g.
This could be done in the setup() part.
Flipping it upside-down would make the Z-axis -1 g.

In your case, you need to measure the motion, so you need the relative acceleration. So in your case calibrating everything to 0.0 might also be okay.

You might to change your code. Use the offset eighter as the real 'g-force' or as the analogRead() values. At this moment it is not obvious what the unit of "center_z" is. And you also need to add some comments.

Here is the website I found that I based the calibration code off of: http://www.e-shore.com.my/homepage/all-projects/136-reading-triple-axis-accelerometer-mma7260-using-arduino-duemilanove.html

I pretty much copied and pasted it moved things around and just got rid of all the LED stuff that wasn't necessary.

What would be the benefit of changing the offset to the real 'g-force' or as the analogRead() values?

Would the units of the center_z be in g? Sorry about not having comments I'll try to add them next time.

Thanks a lot
-Will

The benefit of the real 'g-force' or the raw analogRead() value for the offset is better to read code.

This is your module: http://www.liquidware.com/shop/show/SEN-3AX/3-axis+Accelerometer+Module
That module is 5V tolerant. It looks as if there is a voltage regulator for 3.3V on the module.
So you should connect it to 5V.
According to the cheatsheet, also the range selection pins could be connected to 5V or GND.

Mostly the z-axis is up.

If AREF is not connected (to 3.3V) anymore, the default range of the analog input is 5V again.
So you have range 2g selected.

The way you adapted the example code is okay.
I would like to take it one step further (expect some errors in the code, I didn't test it):

// MMA7260QT Accelerometer
//
// The range is set with two pins (g-Select1 and g-Select2).
// It can be set to : 1.5, 2.0, 4.0 or 6.0 g
// The output signal is regardless of the voltage.
// It is : 
//      800mV/g for range 1.5 g
//      600mV/g for range 2 g
//      300mV/g for range 4 g
//      200mV/g for range 6 g
//
// For 2 g range, and the accelerometer at 3.3V,
// and an analog input with 5V reference (=DEFAULT),
// the calculation is this:
//     voltage = raw * 5V / 1023steps
//     g =  voltage / 600mV
//
// However, if the Aref is connected to 3.3V, the
// full range is 0 ... 3.3V for 1024 steps.
//     g = analogRead(channel) * 3.3 / 1023.0 / 0.6;
//

...

void setup()
{
  // The y-axis points up, so the y value should be 1g for the earth gravity.
  // The values are the values at start. The 1g for the z-axis is taken
  // care for later in the program.
  center_x = give_me_my_g (ACC_X);  // value at 0g (horizontal)
  center_y = give_me_my_g (ACC_Y);  // value at 0g (horizontal)
  center_z = give_me_my_g (ACC_Z);  // value at 1g (pointing up)
}

void loop()
{
  // The z-axis offset "center_z" is not at zero g, but at 1 g.
  // So add 1 to the acc_z.
  acc_x = give_me_my_g (ACC_X) - center_x;             // remove the center (the offset)
  acc_y = give_me_my_g (ACC_Y) - center_y;             // remove the center (the offset)
  acc_z = give_me_my_g (ACC_Z) - center_z + 1.0;  // remove the center (the offset), add 1
}

double give_me_my_g (int channel)
{
  double g;
  
  // analogRead can be used without setting the pinMode.
  // 5.0 : The default range of the ADC, (3.3 if Aref connected to 3.3V)
  // 1023.0 : the maximum raw value at the maximum voltage
  // 0.6 : the number of mV/g. It is 600mv/G for 2g range.
  g = (double) analogRead(channel) * 5.0 / 1023.0 / 0.6;
  return (g);
}

An example of someone with that kind of module: Antipasto Hardware Blog: The Making of: Gravitational RC Driving by Arduino

->edit: I thought that the y-axis was up, but it is the z-axis, this post changed for z-axis.

Currently I have this set up :

Sorry if its hard to see but here is what is connected:

GND -> GND
Vin -> 5V
Gs2 -> GND
Gs1 -> 5v

X0 -> A2
Y0 -> A1
Z0 -> A0

I wasn't using AREF at 3V3 anymore because you said to just use the 5V.
According to the data sheet I should have 2g sensitivity selected by having Gs2 -> 0 and Gs1 -> 1

Thanks a lot for the code, definitely is much cleaner than what I had previously.

Here is my output:

X: 0.00 Y: 0.99 Z: 0.00
X: 0.00 Y: 0.99 Z: 0.00
X: 0.01 Y: 0.99 Z: 0.00
X: 0.00 Y: 0.99 Z: 0.00
X: 0.01 Y: 0.99 Z: 0.00
X: 0.00 Y: 0.99 Z: 0.00
X: 0.00 Y: 0.99 Z: 0.00
X: 0.00 Y: 0.99 Z: -0.01
X: 0.00 Y: 0.99 Z: 0.00
X: 0.01 Y: 0.99 Z: 0.00
X: 0.00 Y: 0.99 Z: 0.00

That run went pretty smoothly, there usually seems to be much more error and changing in the values!

One thing, are you sure that it has the y-axis pointing up? It's hard for me to tell in the datasheet because it can be kind of confusing but after looking at the datasheet on page 6 the top view, so looking down at the chip, is showing that +Y is pointing "up" but that isn't out of the page or out of the chip its just directed towards the top, the z-axis is out of the chip from either top or bottom, correct?

So, shouldn't the code be adding one to the acc_z instead of acc_y?

  acc_x = give_me_my_g (ACC_X);
  acc_y = give_me_my_g (ACC_Y) - center_y;
  acc_z = give_me_my_g (ACC_Z) - center_z + 1.0;

Now, having that it obviously makes the output like so:

X: 0.01 Y: 0.01 Z: 1.01
X: 0.02 Y: 0.01 Z: 1.00
X: 0.01 Y: 0.01 Z: 1.00
X: 0.02 Y: 0.02 Z: 1.01
X: 0.01 Y: 0.01 Z: 1.00
X: 0.01 Y: 0.01 Z: 1.00
X: 0.02 Y: 0.00 Z: 1.01
X: 0.01 Y: 0.00 Z: 1.01
X: 0.01 Y: 0.01 Z: 0.99
X: 0.02 Y: 0.01 Z: 1.00
X: 0.01 Y: 0.01 Z: 1.00
X: 0.02 Y: 0.01 Z: 0.99
X: 0.02 Y: 0.01 Z: 1.01

According to the datasheet:

With my accelerometer oriented like the top chip it looks like I have the same data. Awesome!

But (of course), when I flip over my accelerometer, I think I should expect to have my outputs like the bottom portion of the image above where x and y = 0g but now z = -1g. But on my output, I have z =~ 2

Here is my full code (I made a few modifications from what Krodal wrote)

// MMA7260QT Accelerometer
//
// The range is set with two pins (g-Select1 and g-Select2).
// It can be set to : 1.5, 2.0, 4.0 or 6.0 g
// The output signal is regardless of the voltage.
// It is : 
//      800mV/g for range 1.5 g
//      600mV/g for range 2 g
//      300mV/g for range 4 g
//      200mV/g for range 6 g
//
// For 2 g range, and the accelerometer at 3.3V,
// and an analog input with 5V reference (=DEFAULT),
// the calculation is this:
//     voltage = raw * 5V / 1023steps
//     g =  voltage / 600mV
//
// However, if the Aref is connected to 3.3V, the
// full range is 0 ... 3.3V for 1024 steps.
//
//     g = analogRead(channel) * 3.3 / 1023.0 / 0.6;
//

// constants
const int ACC_X = A2; 
const int ACC_Y = A1;
const int ACC_Z = A0;

// variables
double center_x, center_y, center_z;
double acc_x, acc_y, acc_z;

void setup()
{
  Serial.begin(9600);
  
  // The y-axis points up, so the y value should be 1g for the earth gravity.
  // The values are the values at start. The 1g for the y-axis is taken
  // care for later in the program.
  center_x = give_me_my_g (ACC_X);  // value at 0g (horizontal)
  center_y = give_me_my_g (ACC_Y);  // value at 1g (pointing up)
  center_z = give_me_my_g (ACC_Z);  // value at 0g (horizontal)
}

void loop()
{
  // The z-axis offset "center_z" is not at zero g, but at 1 g.
  // So add 1 to the acc_z.
  acc_x = give_me_my_g (ACC_X) - center_x;         // remove the center (the offset)
  acc_y = give_me_my_g (ACC_Y) - center_y;         // remove the center (the offset)
  acc_z = give_me_my_g (ACC_Z) - center_z + 1;     // remove the center (the offset), add 1.
  
  Serial.print("X: "); 
  Serial.print(acc_x);
    
  Serial.print(" Y: "); 
  Serial.print(acc_y);
    
  Serial.print(" Z: "); 
  Serial.println(acc_z);
    
  delay(200);
}

double give_me_my_g (int channel)
{
  double g;
  
  // analogRead can be used without setting the pinMode.
  // 3.3 : The range of the ADC, 3.3V or 5V
  // 1023.0 : the maximum raw value at the maximum voltage
  // 0.6 : the number of mV/g. It is 600mv/G for 2g range.
  
  g = (double) analogRead(channel) * 3.3 / 1023.0 / 0.6;
  return (g);
}

One last note, I think this article is pretty decent it gives a little more detail on the chip.

Thanks so much for the help
-Will

Sorry, you are right. The z-axis points up.
I have adapted my previous post, because I don't want to send out wrong information.

The formula in the function should be changed for the range of +5V for the analog input.
I assume that Aref is not connected, and the reference is DEFAULT (which is +5V).
Also change the comment please, otherwise you might get confused if you read it later (I would).
g = (double) analogRead(channel) * 5.0 / 1023.0 / 0.6;

The comment "value at 1g (pointing up)" should now be at the z-axis.

I don't know what to think of your -2 value. It is better now that 3.3 is replaced by 5.0 in the formula?
If you rotate the sensor in all axis, you should see changes in x,y,z-values.
They should make sense.
Place it on its right side, and the 'z' should have 0g.
Place it on its left side, and the 'z' should have 0g again.

willstumpf,
I have a similar accelerometer, MMA 7361, and the sl pin needs to be connected to vcc to enable the chip. I returned the first one because i got readings like yours, felt like a fool when I found the problem. Using an analog pin as an output works, then you can put the accelerometer to sleep if you want.
TomJ

Thanks Tumbleweed! I hooked up a wire from Analog 5 to the sleep pin and as you can see in the code below I set it to high, I can't even tell the difference though I don't think!

I updated the equation by adding 5.0 instead of having it 3.3.

Code:

// MMA7260QT Accelerometer
//
// The range is set with two pins (g-Select1 and g-Select2).
// It can be set to : 1.5, 2.0, 4.0 or 6.0 g
// The output signal is regardless of the voltage.
// It is : 
//      800mV/g for range 1.5 g
//      600mV/g for range 2 g
//      300mV/g for range 4 g
//      200mV/g for range 6 g
//
// For 2 g range, and the accelerometer at 3.3V,
// and an analog input with 5V reference (=DEFAULT),
// the calculation is this:
//     voltage = raw * 5V / 1023steps
//     g =  voltage / 600mV
//
// However, if the Aref is connected to 3.3V, the
// full range is 0 ... 3.3V for 1024 steps.
//
//     g = analogRead(channel) * 3.3 / 1023.0 / 0.6;
//

// constants
const int ACC_X = A2; 
const int ACC_Y = A1;
const int ACC_Z = A0;
const int SLEEP = 1; // 1 = sleep is off, 0 = sleep is on

// variables
double center_x, center_y, center_z;
double acc_x, acc_y, acc_z;
int sleep_pin = 5;

void setup()
{
  Serial.begin(9600);
  
  // set the sleep mode
  pinMode(sleep_pin, OUTPUT);
  analogWrite(sleep_pin, SLEEP);
  
  // The z-axis points up, so the z value should be 1g for the earth gravity.
  // The values are the values at start. The 1g for the zvalue at 1g-axis is taken
  // care for later in the program.
  center_x = give_me_my_g (ACC_X);  // value at 0g (horizontal)
  center_y = give_me_my_g (ACC_Y);  // value at 0g (horizontal)
  center_z = give_me_my_g (ACC_Z);  // value at 1g (pointing up)
}

void loop()
{
  // The z-axis offset "center_z" is not at zero g, but at 1 g.
  // So add 1 to the acc_z.
  acc_x = give_me_my_g (ACC_X) - center_x;         // remove the center (the offset)
  acc_y = give_me_my_g (ACC_Y) - center_y;         // remove the center (the offset)
  acc_z = give_me_my_g (ACC_Z) - center_z + 1;     // remove the center (the offset), add 1.
  
  // Display the data
  
  Serial.print("X: "); 
  Serial.print(acc_x);
    
  Serial.print(" Y: "); 
  Serial.print(acc_y);
    
  Serial.print(" Z: "); 
  Serial.println(acc_z);
  
  delay(200);
}

double give_me_my_g (int channel)
{
  double g;
  
  // analogRead can be used without setting the pinMode.
  // 5.0 : The range of the ADC, 3.3V or 5V
  // 1023.0 : the maximum raw value at the maximum voltage
  // 0.6 : the number of mV/g. It is 600mv/G for 2g range.
  
  g = (double) analogRead(channel) * 5.0 / 1023.0 / 0.6;
  return (g);
}

Here is some of my output with it sitting on my desk:

X: -0.02 Y: 0.00 Z: 1.00
X: 0.00 Y: -0.01 Z: 0.99
X: 0.00 Y: -0.01 Z: 0.99
X: -0.01 Y: 0.00 Z: 0.99
X: 0.00 Y: -0.01 Z: 1.00
X: -0.01 Y: 0.02 Z: 1.00
X: -0.02 Y: 0.01 Z: 1.00
X: -0.02 Y: 0.00 Z: 1.01
X: -0.02 Y: 0.01 Z: 1.01

Here is what I get when I flip it over: (Trying to hold it as steady and level as I could)

X: 0.05 Y: 0.00 Z: 2.78
X: 0.02 Y: 0.02 Z: 2.79
X: 0.01 Y: 0.02 Z: 2.78
X: 0.01 Y: 0.01 Z: 2.79
X: 0.02 Y: 0.02 Z: 2.78
X: 0.02 Y: 0.02 Z: 2.78
X: 0.04 Y: 0.05 Z: 2.78
X: 0.01 Y: 0.03 Z: 2.79
X: 0.02 Y: 0.02 Z: 2.78
X: 0.02 Y: 0.01 Z: 2.78
X: 0.02 Y: 0.02 Z: 2.79

The Z output should be -1 correct? Not around 2 and 3?

Thanks
-Will

If I could hold it and rotate it in all directions, I could tell immediately what's the problem with the 2.78 for the z-axis.
Perhaps the z-axis is indeed inverted, and should be -1 when leveled.

Can you measure a few values for x,y,z ?

Horizontal leveled:
x = 0.0
y = 0.0
z = 1.0

rotated 90 degrees to the left
x =
y =
z =

and so on, for:
rotated 90 degrees to the right.
rotated 90 degrees forward.
rotated 90 degrees backward.
upside down (180 degrees rotated)

Left side:

X: 0.89 Y: 0.03 Z: 1.94
X: 0.88 Y: 0.02 Z: 1.94
X: 0.89 Y: 0.02 Z: 1.94
X: 0.88 Y: 0.02 Z: 1.96
X: 0.89 Y: 0.02 Z: 1.94
X: 0.88 Y: 0.03 Z: 1.95
X: 0.88 Y: 0.02 Z: 1.94
X: 0.88 Y: 0.02 Z: 1.95
X: 0.89 Y: 0.02 Z: 1.95
X: 0.88 Y: 0.02 Z: 1.94

Right side:

X: -0.90 Y: 0.02 Z: 1.95
X: -0.90 Y: 0.01 Z: 1.95
X: -0.90 Y: 0.02 Z: 1.96
X: -0.90 Y: 0.02 Z: 1.95
X: -0.91 Y: 0.02 Z: 1.96
X: -0.90 Y: 0.02 Z: 1.96
X: -0.90 Y: 0.02 Z: 1.96
X: -0.91 Y: 0.02 Z: 1.96
X: -0.91 Y: 0.01 Z: 1.95

Forward:

X: -0.02 Y: 0.91 Z: 1.90
X: -0.01 Y: 0.93 Z: 1.90
X: -0.01 Y: 0.92 Z: 1.90
X: -0.02 Y: 0.93 Z: 1.89
X: -0.02 Y: 0.91 Z: 1.89
X: -0.02 Y: 0.93 Z: 1.90
X: -0.02 Y: 0.93 Z: 1.91
X: -0.02 Y: 0.92 Z: 1.90
X: -0.02 Y: 0.94 Z: 1.90
X: -0.02 Y: 0.92 Z: 1.90

Backward:

X: -0.02 Y: -0.90 Z: 1.90
X: -0.02 Y: -0.88 Z: 1.93
X: -0.02 Y: -0.89 Z: 1.94
X: -0.02 Y: -0.89 Z: 1.93
X: -0.02 Y: -0.90 Z: 1.94
X: -0.02 Y: -0.90 Z: 1.92
X: -0.02 Y: -0.89 Z: 1.91
X: -0.02 Y: -0.89 Z: 1.92
X: -0.02 Y: -0.90 Z: 1.93
X: -0.02 Y: -0.88 Z: 1.90

Upside down:

X: 0.02 Y: -0.01 Z: 2.78
X: 0.02 Y: 0.02 Z: 2.76
X: 0.00 Y: -0.01 Z: 2.77
X: 0.00 Y: -0.02 Z: 2.78
X: -0.02 Y: 0.00 Z: 2.79
X: 0.02 Y: -0.02 Z: 2.79
X: 0.01 Y: 0.01 Z: 2.77
X: 0.00 Y: 0.01 Z: 2.77
X: -0.01 Y: 0.00 Z: 2.78
X: -0.02 Y: -0.02 Z: 2.78

Thanks!
-Will

Thank you for the data.

I recently made this: Arduino Playground - MMA7455
So I grabbed my MMA7455 (accelerometer with I2C) placed it upside down, calibrated the offset, and ..... got the same as you.

Because the chip is on the bottom the the circuit board, the chip is upside down.
The Z-axis is pointing down !
I suggest to correct that in code.

This is the old code:

  // The z-axis offset "center_z" is not at zero g, but at 1 g.
  // So add 1 to the acc_z.
  acc_x = give_me_my_g (ACC_X) - center_x;         // remove the center (the offset)
  acc_y = give_me_my_g (ACC_Y) - center_y;         // remove the center (the offset)
  acc_z = give_me_my_g (ACC_Z) - center_z + 1;     // remove the center (the offset), add 1.

This could be the new code (untested):

  // The MMA7260QT chip is soldered upside down on the circuit board.
  // Therefor is the z-axis pointing downwards.
  // Everything is calibrated while the MMA7260QT is horizontal flat,
  // but the chip was upside down !
  // 
  // The actual g-force for the X and Y-axis =
  //        g-force = g_now - g_offset;
  // The actual g-force for the Z-axis =
  //        g-force = - (g_now - g_offset);
  // And a g-force of 1 g should still be added, since the
  // offset calibration was done at 1 g earth gravity.
  // The value of 1 g is after correcting it for upside-down,
  // otherwise the correction should be -1 g.
  acc_x = give_me_my_g (ACC_X) - center_x;       // remove the center (the offset)
  acc_y = give_me_my_g (ACC_Y) - center_y;       // remove the center (the offset)
  acc_z = -(give_me_my_g (ACC_Z) - center_z) + 1.0;  // z-axis inverse, 1 g for earth gravity.

You could rewrite it as : acc_z = 1.0 - give_me_my_g (ACC_Z) + center_z;
But I just like the same style for X,Y, and Z.

I also changed "+ 1" to "+ 1.0" to indicate that the calculation is done with floating point numbers.

You might not get every axis to +1 and -1, it looks as if you need some gain correction. But that's just fine tuning.
I checked the datasheet, and at 2g range the sensitivity is 600mV/g, but it could be 555 ... 645 g/mV. That's almost 10% inaccuracy.

GREAT! Thank you so much for your help. I really apperciate it. When it's sitting untouched on my desk its X: 0, Y: 0, and Z: 1. When I flip it its X: 0, Y: 0, and Z: -1 !

You might not get every axis to +1 and -1, it looks as if you need some gain correction. But that's just fine tuning.
I checked the datasheet, and at 2g range the sensitivity is 600mV/g, but it could be 555 ... 645 g/mV. That's almost 10% inaccuracy.

Hmm, okay do you have any suggestions on how to fine tune it to get rid of the inaccuracy?

Again, thank you!
-Will

I'm glad you have it working.

The name of the function "give_me_my_g" was just for fun.
You could give it a more serious name: getG() or getGforce()
That function should return the real g-force value, so any gain correction should be done there.

For example with an extra code line for the gain:
g = (double) analogRead(channel) * 5.0 / 1023.0 / 0.6;
g *= 1.08; // gain

Okay I added that to my code. I'm a little confused on the gain though, what is it and why would you times it by 1.08? Where'd you get that number?

Thanks for all the help!
-Will

The gain is just a factor to multiply with either the 'raw' value or with the 'g' value. It doesn't matter which one is used, the result is the same.
The number of 1.08 was made up by me. I should have mentioned that, sorry. It looks as if you needed a gain that was a little less than 10%.
But you have to measure what the actual gain should be.

Hi i'am getting G-values from accelerometer and i need convert acceleration to orbit?
i think i must du second derivation acceleration and i get the orbit? but i don't know how i can derivate values?
anybody knows?