Ok, Here is the simple code you refering too. Well a part of if because it exceeds the 9500 characters
#include <Wire.h>
#define GRAVITY 256
#define ToRad(x) ((x)*0.01745329252)
#define ToDeg(x) ((x)*57.2957795131)
// L3G4200D gyro: 2000 dps full scale
// 70 mdps/digit; 1 dps = 0.07
#define Gyro_Gain_X 0.07
#define Gyro_Gain_Y 0.07
#define Gyro_Gain_Z 0.07
#define Gyro_Scaled_X(x) ((x)*ToRad(Gyro_Gain_X))
#define Gyro_Scaled_Y(x) ((x)*ToRad(Gyro_Gain_Y))
#define Gyro_Scaled_Z(x) ((x)*ToRad(Gyro_Gain_Z))
#define M_X_MIN -421
#define M_Y_MIN -639
#define M_Z_MIN -238
#define M_X_MAX 424
#define M_Y_MAX 295
#define M_Z_MAX 472
#define Kp_ROLLPITCH 0.02
#define Ki_ROLLPITCH 0.00002
#define Kp_YAW 1.2
#define Ki_YAW 0.00002
#define OUTPUTMODE 1
#define PRINT_ANALOGS 0
#define PRINT_EULER 1
#define STATUS_LED 13
float G_Dt=0.02; // Integration time (DCM algorithm) We will run the integration loop at 50Hz if possible
long timer=0; //general purpuse timer
long timer_old;
long timer24=0; //Second timer used to print values
int AN[6]; //array that stores the gyro and accelerometer data
int AN_OFFSET[6]={0,0,0,0,0,0}; //Array that stores the Offset of the sensors
.................
AN[0] = gyro.g.x;
AN[1] = gyro.g.y;
AN[2] = gyro.g.z;
gyro_x = SENSOR_SIGN[0] * (AN[0] - AN_OFFSET[0]);
gyro_y = SENSOR_SIGN[1] * (AN[1] - AN_OFFSET[1]);
gyro_z = SENSOR_SIGN[2] * (AN[2] - AN_OFFSET[2]);
}
void Accel_Init()
{
compass.init();
if (compass.getDeviceType() == LSM303DLHC_DEVICE)
{
compass.writeAccReg(LSM303_CTRL_REG1_A, 0x47); // normal power mode, all axes enabled, 50 Hz
compass.writeAccReg(LSM303_CTRL_REG4_A, 0x08); // high resolution output mode
compass.writeAccReg(LSM303_CTRL_REG4_A, 0x20); // 8 g full scale: FS = 10 on DLHC
}
else
{
compass.writeAccReg(LSM303_CTRL_REG1_A, 0x27); // normal power mode, all axes enabled, 50 Hz
compass.writeAccReg(LSM303_CTRL_REG4_A, 0x30); // 8 g full scale: FS = 11 on DLH, DLM
}
}
// Reads x,y and z accelerometer registers
void Read_Accel()
{
compass.readAcc();
AN[3] = compass.a.x;
AN[4] = compass.a.y;
AN[5] = compass.a.z;
accel_x = SENSOR_SIGN[3] * (AN[3] - AN_OFFSET[3]);
accel_y = SENSOR_SIGN[4] * (AN[4] - AN_OFFSET[4]);
accel_z = SENSOR_SIGN[5] * (AN[5] - AN_OFFSET[5]);
}
void Compass_Init()
{
compass.writeMagReg(LSM303_MR_REG_M, 0x00); // continuous conversion mode
// 15 Hz default
}
void Read_Compass()
{
compass.readMag();
magnetom_x = SENSOR_SIGN[6] * compass.m.x;
magnetom_y = SENSOR_SIGN[7] * compass.m.y;
magnetom_z = SENSOR_SIGN[8] * compass.m.z;
}
void printdata(void)
{
Serial.print("!");
#if PRINT_EULER == 1
Serial.print("ANG:");
Serial.print(ToDeg(roll));
Serial.print(",");
Serial.print(ToDeg(pitch));
Serial.print(",");
Serial.print(ToDeg(yaw));
#endif
#if PRINT_ANALOGS==1
Serial.print(",AN:");
Serial.print(AN[0]); //(int)read_adc(0)
Serial.print(",");
Serial.print(AN[1]);
Serial.print(",");
Serial.print(AN[2]);
Serial.print(",");
Serial.print(AN[3]);
Serial.print (",");
Serial.print(AN[4]);
Serial.print (",");
Serial.print(AN[5]);
Serial.print(",");
Serial.print(c_magnetom_x);
Serial.print (",");
Serial.print(c_magnetom_y);
Serial.print (",");
Serial.print(c_magnetom_z);
#endif
/#if PRINT_DCM == 1
Serial.print (",DCM:");
Serial.print(convert_to_dec(DCM_Matrix[0][0]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[0][1]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[0][2]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[1][0]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[1][1]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[1][2]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[2][0]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[2][1]));
Serial.print (",");
Serial.print(convert_to_dec(DCM_Matrix[2][2]));
#endif/
Serial.println();
}
long convert_to_dec(float x)
{
return x*10000000;
}
It may be simple to you but for me is greek...
So can you please help me with a simpler code? or that code is the simplest to implement a reading from I2C?