Change Fulle Scale LSM303DLHC

Hello-

I have an adafruit 10-DOF IMU breakout board which includes a LSM303DLHC sensor on the board. I am trying to change the full scale on the accelerometer from +/- 2g to +/- 8 g. Based on my research, I thought that you had to change one of the registers in the library. This is the code that I added to the library Adafruit_LSM303_U.cpp (my addition is the 'custom settings section"):

bool Adafruit_LSM303_Accel_Unified::begin()
{
  // Enable I2C
  Wire.begin();

  // Enable the accelerometer (400Hz)
  write8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A, 0x77);

  ///////////////////////////////////////////
  // CUSTOM SETTINGS
  // 0x38 = 0b00111000 to set 16 G range and 400 Hz update
  // 0x28 = 0b00101000 to set 8 G range and 400 Hz update
  write8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG4_A, 0x28);
  ///////////////////////////////////////////
  
  // LSM303DLHC has no WHOAMI register so read CTRL_REG1_A back to check
  // if we are connected or not
  uint8_t reg1_a = read8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A);
  if (reg1_a != 0x77)
  {
    return false;
  }  
  
  return true;
}

However, it changes nothing. The full scale of the accelerometer is still set at +/- 2g (default). Could I get help setting the full scale of this sensor?

I have also attached my code which calls the sensor. Note that it also connects to another sensor (an analog pitot tube).

Thanks

pitchrollheading3.ino (4.91 KB)

How do you know that the sensor full scale range has not been changed?

What is the point of the following read/check?

uint8_t reg1_a = read8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A)
 if (reg1_a != 0x77)
  {
    return false;
  }

I would read LSM303_REGISTER_ACCEL_CTRL_REG4_A instead, and see if it is set to 0x28.

Thanks for your reply!

When I run the code, shake the IMU and look at the results it is very easy to see that it is not reporting anything higher or lower than +/- 2g (it reports the data in newtons).

That is a good question about the read/check, but unfortunately I do not quite know myself. It is from the library which is provided by adafruit for this sensor. It is referenced in the code that I upload to my Arduino in an include statement (see attachment from original post). However, I can add the code you suggest to check the register.

Thanks again for your help!

shake the IMU

How do you know that this should produce accelerations larger than +/- 2 g?

The correct test is to measure the acceleration due to gravity. That should be 1/2 full scale when in the 2g mode, and 1/8 full scale when in the 8 g mode.

Hello-

I apologize for not responding sooner. The notifications from the forum don't seem to be reaching me.

Anyway, this IMU converts the voltage measurement to units of acceleration (m/s^2) for me so I don't have to mess around with adjusting the scale. Therefore I could see that the output was clearly flat lining at +/- 2g (+/- 19.62 m/s^2). That being said, I was able to adjust the range by having it read the register before writing to it.

Thanks for your help!