Reply To: Altitude & Temp

Home Forums Forums Technical Support for BerryIMU Altitude & Temp Reply To: Altitude & Temp

#7931
jgreen
Participant

yes,

 

void setup() {
// join i2c bus (address optional for master)
Serial.begin(115200); // start serial for output

detectIMU();
enableIMU();

delay(1000);
}

void enableIMU(){

if (LSM9DS0){//For BerryIMUv1
//Enable accelerometer
writeTo(LSM9DS0_ACC_ADDRESS,LSM9DS0_CTRL_REG1_XM, 0b01100111); // z,y,x axis enabled, continuos update, 100Hz data rate
writeTo(LSM9DS0_ACC_ADDRESS,LSM9DS0_CTRL_REG2_XM, 0b00100000); // +/- 16G full scale

//Enable the magnetometer
writeTo(LSM9DS0_MAG_ADDRESS,LSM9DS0_CTRL_REG5_XM, 0b11110000); // Temp enable, M data rate = 50Hz
writeTo(LSM9DS0_MAG_ADDRESS,LSM9DS0_CTRL_REG6_XM, 0b01100000); // +/-12gauss
writeTo(LSM9DS0_MAG_ADDRESS,LSM9DS0_CTRL_REG7_XM, 0b00000000); // Continuous-conversion mode

// Enable Gyro
writeTo(LSM9DS0_GYR_ADDRESS, LSM9DS0_CTRL_REG1_G, 0b00001111); // Normal power mode, all axes enabled
writeTo(LSM9DS0_GYR_ADDRESS, LSM9DS0_CTRL_REG4_G, 0b00110000); // Continuos update, 2000 dps full scale
}
else if(LSM9DS1){//For BerryIMUv2
// Enable the gyroscope
writeTo(LSM9DS1_GYR_ADDRESS,LSM9DS1_CTRL_REG4,0b00111000); // z, y, x axis enabled for gyro
writeTo(LSM9DS1_GYR_ADDRESS,LSM9DS1_CTRL_REG1_G,0b10111000); // Gyro ODR = 476Hz, 2000 dps
writeTo(LSM9DS1_GYR_ADDRESS,LSM9DS1_ORIENT_CFG_G,0b10111000); // Swap orientation

// Enable the accelerometer
writeTo(LSM9DS1_ACC_ADDRESS,LSM9DS1_CTRL_REG5_XL,0b00111000); // z, y, x axis enabled for accelerometer
writeTo(LSM9DS1_ACC_ADDRESS,LSM9DS1_CTRL_REG6_XL,0b00101000); // +/- 16g

//Enable the magnetometer
writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG1_M, 0b10011100); // Temp compensation enabled,Low power mode mode,80Hz ODR
writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG2_M, 0b01000000); // +/-12gauss
writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG3_M, 0b00000000); // continuos update
writeTo(LSM9DS1_MAG_ADDRESS,LSM9DS1_CTRL_REG4_M, 0b00000000); // lower power mode for Z axis

}
}

  • This reply was modified 3 years, 5 months ago by jgreen.

Blip, blop, bloop…