Setting gain/ranges on 9-DOF IMU with new _U drivers?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Adrian_Land
 
Posts: 14
Joined: Sat Sep 27, 2014 1:00 pm

Setting gain/ranges on 9-DOF IMU with new _U drivers?

Post by Adrian_Land »

I'd like to use the 9DOF IMU as the heart of an Arduino inertial navigation system for my model planes. The rate of turn of the models requires using the higher ranges of both the accelerometer and the gyro. On this forum I've found your guidance for making these changes with the original Adafruit_L3GD20.h and Adafruit_LSM303.h libraries, but I've had no joy with the updated _U libraries.
Any guidance would be much appreciated. (I'm a novice programmer, so please 'scale' advice accordingly!)

Regards
Adrian Land

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting gain/ranges on 9-DOF IMU with new _U drivers?

Post by adafruit_support_mike »

The unified driver for the LSM303 has a function named 'setMagGain()' and a list of constants from lines 94-103 of the header file:

https://github.com/adafruit/Adafruit_LS ... LSM303_U.h

To set the LSM303 to its +/-8.1g setting, you'd use something like this:

Code: Select all

    mag.setMagGain( LSM303_MAGGAIN_8_1 );
The unified library for the L3GD20 takes the gain setting as an argument to the 'begin()' method:

Code: Select all

    gyro.begin( GYRO_RANGE_2000DPS );
The constants there are defined on lines 77-82 of the header file:

https://github.com/adafruit/Adafruit_L3 ... L3GD20_U.h

User avatar
Adrian_Land
 
Posts: 14
Joined: Sat Sep 27, 2014 1:00 pm

Re: Setting gain/ranges on 9-DOF IMU with new _U drivers?

Post by Adrian_Land »

Hello Mike, thanks for the prompt reply.

The pointer for the gyro settings on the L3GD20 looks good.

Unfortunately, setMagGain for the LSM303 only looks at the magnetometer range settings (gauss), not the accelerometer ranges (+/- 2, 4, 8, 16g; see data sheet P.9). Guidance on how to set the accelerometer ranges would be much appreciated.

Best,
Adrian Land

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting gain/ranges on 9-DOF IMU with new _U drivers?

Post by adafruit_support_mike »

Hmm.. that wasn't included in the library.

Attached is a modified version of the library that adds a function named setGain() to the accelerometer class. The options are:

Code: Select all

    LSM303_ACCELGAIN_02                        = 0x00,  // +/- 2G
    LSM303_ACCELGAIN_04                        = 0x10,  // +/- 4G
    LSM303_ACCELGAIN_08                        = 0x20,  // +/- 8G
    LSM303_ACCELGAIN_16                        = 0x30,  // +/- 16G
and the line you want will look something like:

Code: Select all

    accel.setGain( LSM303_ACCELGAIN_16 );
Give it a try and see how it works.
Attachments
Adafruit_LSM303DLHC.zip
(75.37 KiB) Downloaded 76 times

User avatar
Adrian_Land
 
Posts: 14
Joined: Sat Sep 27, 2014 1:00 pm

Re: Setting gain/ranges on 9-DOF IMU with new _U drivers?

Post by Adrian_Land »

Hello Mike,

Many thanks for the great support - very much appreciated! I've just had a quick check and your updates look good. I did remember to change:
static float _lsm303Accel_MG_LSB = 0.012F; // 1, 2, 4 or 12 mg per lsb
in Adafruit_LSM303_U.cpp to match the new gain!

Best,
Adrian

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Setting gain/ranges on 9-DOF IMU with new _U drivers?

Post by adafruit_support_mike »

Cool.. it's always nice when code I couldn't test on the actual hardware does what it should. ;-)

Happy hacking!

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”