Understanding the MinIMU-9 output

Hi all,

I recently purchased a MinIMU-9 to use on a robotic project, but I am new to using gyros and accelerometers. I am using a Beagleboard-XM to communicate to the MinIMU-9 using an I2C link. I have used I2C with other devices which work OK. The comms to MinIML-9 also seems to work OK.
I first intended just to try the Compass and I found a sample Arduino program based on the LSM303DLH were my MinIMU-9 is based on the LSM303DLM. I modified the Arduino program to run on the Beagleboard which seems to run OK, but the values I am getting I am not sure how to interpret. The Beaglebroad is running Ubuntu and has a set of I2C tools that lets you dump the contents of some I2C device registers, using this I have confirmed that my program is reading the registers correctly.

From the datasheet for the LSM303DLM I understand that the raw data for each of the 3 axis is 12 bits in a range -2048 to 2027 in a 2’s complement form. When I examine the 3 pairs of registers from reg 0x03 I sometimes get values like ‘FF 8C’, should the top most ‘F’ be masked off before doing any calculations?

The other thing is that when I rotate the module through 90 degrees keeping the board horizontal I don’t seem get a meaningful change in the x / y values.

I have set the CRA_REG_M (0x00) to 0x14, output rate 30Hz
Left CRB_REG_M (0x01) to 0x20, Gain ±1.3g
MR_REG_M (0x02) to 0x00, continuous Conversion mode.

Please see attach screen shots of the registers before and after the 90 degree rotation.

Can anyone enlighten me to what I am doing wrong or at least what I am misunderstanding?

Thanks Ernie




Hello.

Have you calibrated the magnetometer? Are you sure you ported the code from the Arduino exactly correctly? I would recommend posting the simplest complete bit of your code that does not work as you expect it to.

- Ryan

Hi Ryan,

Thanks for your replay. No I have not done any calibration on the magnetometer as yet, not sure I understand what I need to do. Could you comment on the raw data dump in my screen shots, does the value of registers 03/04 look correct having a value of FF8C when I was only expecting a 12 bit value?

Ernie

Sorry, I don’t know what I am looking at when I look at that hex dump. Why do you need hex dumps? Can you post the simplest code that does not do what you want?

- Ryan

Hi Ryan,

Sorry if I am not explaining myself very well. Currently my code reads values that match the register dump, so I am happy that the I2C comms is working correctly. One of my enquiries is does the FF8C look like a reasonable value to get if the output is only expected to be 12 bit?
I will tidy my code and include it in the next post.

Ernie

FF8C should correspond to a decimal value of -116, or about -0.1 Gauss at the sensitivity you are at which isn’t an unreasonable magnetic field reading.

- Ryan

lsm303test1.c (7.8 KB)Ryan,

Thanks it’s good to know the value makes sense. I attach code of the modified code I have used so far, hope it makes sense.

I assume from what you have said that calibration is an important step in getting this to work correctly?

Ernie

According to your HEX dump you have a fairly strong magnetic field in the Z axis and not much in the X and Y. It isn’t too surprising that turning 90 degrees about Z would not change much.

I looked through your code briefly. It looks like you did not port our code for the heading calculations. It looks like, in getHeading(), are you assuming the magnetic field will be perpendicular to the Z axis. If you are still questioning your Magnetometer outputs, I recommend writing a program that outputs your Magnetometer readings constantly to some terminal so you can look at it while you move it around.

- Ryan

Ryan,
Thanks for your feedback, I’ll look at doing what you have suggested this weekend.
Is it normal to have to calibrate the Magnetometer & Accelerometer? Do you have to calibrate the gyro in the same way? I am not sure if I have a clear understanding of what the difference is between the accelerometer and gyro, do they not provide similar information i.e. the tilt of the device?
Following on from the last question, my project relates to balancing a robot, which is most useful the gyro or accelerometer for this purpose?

Thanks Ernie

The Magnetometer needs to be calibrated, in our code we do a simple shift and scale, but you can get more complex and possibly have better results by having a three-dimensional calibration matrix. The accelerometer and gyro do not have to be calibrated. The accelerometer measures acceleration, the gyro measures angular velocity. Both the gyro and the accelerometer are useful because the accelerometer corrects for slow movements and the gyro corrects for fast movements. The gyro is probably more useful.

- Ryan

Ryan,

Thanks for your useful comments.
Would it be an idea for me to try and collect some magnetometer data away from my test environment, perhaps in the back garden to see if that changes the Z axis results?

Ernie

Yes - Ryan