Hi
I wrote below sketch to get the raw data from the ADXL345. I’m trying to calibrate the sensor but the output doesnt make sense to m.
the output when the IMU flat and still is
accel_x = 14
accel_y = –2
accel_z = 220. (correspond to 1G output)
the datasheet for the ADXL345 says that the minimum output for Zout is 230 and maximum is 282 and Im getting a value of 220. is there anything wrong with the IMU?
Also when I tilt the IMU 90 degrees it gives
accel_x = 298 – 1G (out of datasheet bounds)
accel_y = –2
accel_z = –40
the code
#include <Wire.h>
float accel_x;
float accel_y;
float accel_z;
void setup()
{
Serial.begin(57600);
I2C_Init();
Accel_Init();
}
void loop() //Main Loop
{
Read_Accel(); // Read I2C accelerometer
Serial.print(accel_x);
Serial.print (“,”);
Serial.print(accel_y);
Serial.print (“,”);
Serial.print(accel_z);
Serial.println();
}
int AccelAddress = 0x53;
int CompassAddress = 0x1E; //0x3C //0x3D; //(0x42>>1);
void I2C_Init()
{
Wire.begin();
}
void Accel_Init()
{
Wire.beginTransmission(AccelAddress);
Wire.send(0x2D); // power register
Wire.send(0x08); // measurement mode
Wire.endTransmission();
delay(20);
Wire.beginTransmission(AccelAddress);
Wire.send(0x31); // Data format register
Wire.send(0x08); // set to full resolution
Wire.endTransmission();
delay(20);
}
// Reads x,y and z accelerometer registers
void Read_Accel()
{
int i = 0;
byte buff[6];
Wire.beginTransmission(AccelAddress);
Wire.send(0x32); //sends address to read from
Wire.endTransmission(); //end transmission
Wire.beginTransmission(AccelAddress); //start transmission to device
Wire.requestFrom(AccelAddress, 6); // request 6 bytes from device
while(Wire.available()) // ((Wire.available())&&(i<6))
{
buff = Wire.receive(); // receive one byte
i++;
}
Wire.endTransmission(); //end transmission
if (i==6) // All bytes received?
{
accel_x =(((int)buff[1]) << 8) | buff[0]; // Y axis (internal sensor x axis)
accel_y =(((int)buff[3]) << 8) | buff[2]; // X axis (internal sensor y axis)
accel_z =(((int)buff[5]) << 8) | buff[4]; // Z axis
}
else
Serial.println(“!ERR: Error reading accelerometer info!”);
}