Hello dear members,
Have been sitting for days now trying to solve my problem with these sensors. First, it appears that it works with one sensor, but then i encounter several problems when trying to implement several sensors together.
The values ??are, in other words totally crap, turns out that all the values ??are the same hehe.
Anyway, I have possibly solved it by using the wiring library instead (used I2Cdevlib before). The values ??I get now may be possibly correct, I am, however, skeptical of their accuracy and therefore I turn here to get it confirmed.
I will upload two photos, and also a part of the codes/settings im using.
First the code and settings:
///////////////////////////////////////////
///////////////ACCELEROMETER//////////////
/////////////////////////////////////////void ADXL345_init(){
Read_I2C(ADXL345_ADDR, ADXL345_WHO_AM_I, buffer, 1); // READS THE DEVICE_ID
DEV_ID = buffer[0];if(DEV_ID = 229){
Serial.print("ADXL345: CONNECTED ");
Write_I2C(ADXL345_ADDR, ADXL345_POWER_CTL, 0x00); // Sensor OFF
Write_I2C(ADXL345_ADDR, ADXL345_POWER_CTL, 0x08); // 0001 1000 Measuring ON, checks inactivity each 0.125s (f = 8hz) and autosleep enabled
Write_I2C(ADXL345_ADDR, ADXL345_DATA_FORMAT, 0x03); // 0000 0011 Sensitivity +-16g}
}
void ADXL345_read(){
Read_I2C_Val(ADXL345_ADDR, ADXL345_OUT_X_L, buffer, 6);ADXL345_x = (word(buffer[1], buffer[0]));
ADXL345_y = (word(buffer[3], buffer[2]));
ADXL345_z = (word(buffer[5], buffer[4]));// int pitch = (((atan2(accx,accz))*180)/PI);
// int roll = (((atan2(accy,accz))*180)/PI);}
///////////////////////////////////////////
///////////////GYROSCOPE//////////////////
/////////////////////////////////////////void L3G4200D_init(){
Read_I2C(ADXL345_ADDR, ADXL345_WHO_AM_I, buffer, 1); // READS THE DEVICE_ID
DEV_ID = buffer[0];if(DEV_ID = 211){
Serial.println("L3G4200D: CONNECTED");
Write_I2C(L3G4200D_ADDR, L3G4200D_CTRL_REG1, 0x00); // Power off sensor
Write_I2C(L3G4200D_ADDR, L3G4200D_CTRL_REG1, 0x0F); // 0000 1111(f = 100hz, B = 12.5) Sensor and all axis ON
Write_I2C(L3G4200D_ADDR, L3G4200D_CTRL_REG2, 0x00); // 0010 0000 Normal mode on
Write_I2C(L3G4200D_ADDR, L3G4200D_CTRL_REG3, 0x08); // FIFO and interrupts off
Write_I2C(L3G4200D_ADDR, L3G4200D_CTRL_REG4, 0x30); // 0011 000 (2000 DPS)
Write_I2C(L3G4200D_ADDR, L3G4200D_CTRL_REG5, 0x00); // 0000 0000 FIFO and highpass-filter OFF
}
}void L3G4200D_read(){
Read_I2C_Val(L3G4200D_ADDR, L3G4200D_OUT_X_L, buffer, 6);L3G4200D_x = (word(buffer[1], buffer[0]));
L3G4200D_y = (word(buffer[3], buffer[2]));
L3G4200D_z = (word(buffer[5], buffer[4]));}
And here is the part where the I2C Communication occurs:
void Write_I2C(int ADDRESS, byte POINTER, byte NEW){
Wire.beginTransmission(ADDRESS);
Wire.write(POINTER);
Wire.write(NEW);
Wire.endTransmission();}
void Read_I2C_Val(int ADDRESS, byte POINTER, byte READ[], int AMOUNT){
Wire.beginTransmission(ADDRESS);
Wire.write(POINTER | (1 << 7));
Wire.endTransmission();Wire.requestFrom(ADDRESS,AMOUNT);
for(int x = 0; x < AMOUNT; x++){
READ[x] = Wire.read();
}
}
(NOTE: THESE ARE RAW VALUES)
Sensor laying flat (Components looking upwards) - accel
So to simply make these values into g's you just multiplicate it with 32/2^10 ~= 0.031. Results should be x = 0, y = 0, z = +1
Sensor laying upsidedown (Components looking down) - accel
Rotating sensor - gyroscope
I hope Ive provided enough information!
Cheers
Edit:
ADXL345 +-16g
L3G4200D +-2000DPS