problem with value of output adxl345 connect i2c for arduino

Hello
i am beginner
I connect adxl345 to Arduino Uno via I2C.the . if fixed the adxl345 in board and i want the value of axis z=1g and x=0 y=0.the ouput in z give me 511 so i used the normalization method in z give me 20.4
in logique the ouput in z you should be 1g
I2C mode:
CS ->3V3
SDO -> GND
SDA ->A4
SCL -> A5
VCC ->3V3
GND -> GND

//float gravityFactor=9,81;
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"

// I2Cdev and ADXL345 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "ADXL345.h"

// class default I2C address is 0x53
// specific I2C addresses may be passed as a parameter here
// ALT low = 0x53 (default for SparkFun 6DOF board)
// ALT high = 0x1D
ADXL345 accel;
int i=0;
int16_t ax, ay, az;
double nx,ny,nz;

void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
Wire.begin();
accel.setRange(ADXL345_RANGE_2G);
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(38400);

// initialize device
Serial.println("Initializing I2C devices...");
accel.initialize();

// accel.setTapDetectionXYZ(1);
// verify connection
Serial.println("Testing device connections...");
Serial.println(accel.testConnection() ? "ADXL345 connection successful" : "ADXL345 connection failed");
accel.setOffset(0,0,1);

}

void loop() {
i=i+1;
// read raw accel measurements from device
accel.getAcceleration(&ax, &ay, &az);

nx = ax * 0.004 * 9.8;
ny = ay * 0.004 * 9.8;
nz = az * 0.004 * 9.8;

// display tab-separated accel x/y/z values
Serial.print(i);
Serial.print(" accel:\t");
Serial.print(nx); Serial.print("\t");
Serial.print(ny); Serial.print("\t");
Serial.println(nz);
delay(5000);

}

any help to get x=0 y=0 and z=1g ?

any help to get x=0 y=0 and z=1g ?

One way (probably not the best):

    nx = 0; // ax * 0.004 * 9.8;
    ny = 0; // ay * 0.004 * 9.8;
    nz = 1; // az * 0.004 * 9.8;

Now, what numbers are you getting? Where did this formula come from?

thnx pauls but I don't understand

I don't understand

In my code snippet, I simply hardcoded the results you wanted.

That, obviously is not the right answer.

So, we need to understand why you are getting other answers.

Is there a way to normalization ?