Calibrating the MMA7260Q Accelerometer

I’m having a few problems calibrating the correct g readout for the accelerometer. I have set the accelerometer to 4g sensitivity.

I have managed to get a value for all three axis displaying on a LCD. Ive also read a couple of other threads trying to find out the correct map values, but they dont seam to work. Should i be getting X=0,Y=0 and Z=1 at rest too? Here is my code.

// include the library code:
#include <LiquidCrystal.h>
#define pinx 0
#define piny 1
#define pinz 2

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float valx;
float valy;
float valz;

void setup() {
  lcd.begin(20, 4);                   //Set up the LCD's number of columns and rows 
  Serial.begin(9600);                 //Begin sending serial data back to the connected PC

void loop() {  
  // X Axis
  valx = analogRead(pinx);
  Serial.print(map((valx-370), 0, 1023, 0, 255),DEC);
  lcd.print(map((valx-370), 0, 1023, 0, 255),DEC);
  // Y Axis
  valy = analogRead(piny);
  Serial.print(map((valy-360), 0, 1023, 0, 255),DEC);
  lcd.print(map((valy-360), 0, 1023, 0, 255),DEC);
  // Z Axis
  valz = analogRead(pinz);
  Serial.print(map((valz-160), 0, 1023, 0, 255),DEC);
  lcd.print(map((valz-421.5), 0, 1023, 0, 255),DEC);

  delay (100);                        //Loop every 1/10th second
  lcd.clear();                        //Clear LCD before next write

Any help would be great!

Thank you!

but they dont seam to work.

I don't seem to be able to see the values you actually are getting.

Using the code posted I currently have displayed on the LCD:

X=0 Y=0 Z=1

I achieved this by subtracting the values shown from valx, valy & valz. Now when i move the accelorometer the values jump up too high.

Im not sure that the way i have calibrated it is correct. I would like the LCD to display 1 as 1g etc. So at rest am i correct in saying that the values for the x & y axis should be 0g while z 1g. How would i be able to calibrate this in the code to display as such.

If i just have valx, valy & valz without subtracting anything from them i have the following values:

X=92 Y=89 Z=107

Any help would be greatly appreciated, if theres any other information you require please ask.

Kind Reagrds