MinImu-9 V2 Pitch and Roll

Hi guys,

Just got one of these and loaded the MinIMU9AHRS code from the repository but I don’t seem to be getting any good values. It’s been calibrated several times and the values I get are consident from one measurement to another, no metal or magnets close by. Pitch and Roll start at near 0, when the sensor is moved they show very briefly the new position but shortly after values go back to 0 even though the sensor is still tilted. Basically pitch and roll return to around 0 no mater which way I move the sensor.

When reading the raw data using the example code all 3 acc axes seem to read the exact same value:
A X: 514 Y: 514 Z: 514 M X: -6 Y: 55 Z: -457
A X: 883 Y: 883 Z: 883 M X: -11 Y: 71 Z: -456
A X: 1140 Y: 1140 Z: 1140 M X: -11 Y: 80 Z: -455
A X: 1285 Y: 1285 Z: 1285 M X: -11 Y: 81 Z: -454

I’m using these with an Arduino Due. The code has not been altered in any way, just downloaded and flashed.

Thanks in advance,
Andrei

Ok, the Init function in the LSM303 library seems to detect the wrong chip and populates the wrong I2C address for the accelerometer. Not experienced enough to find the fault i nthe code so just hardcoded the address and bypassed the autodetection. What’s strange is that I just used the library and examples I downloaded. Is this an incompatibility with Arduino Due?

Hello, Andrei.

I have not looked into the details of this problem, but I do know that the Arduino’s I2C library (Wire) behaves differently on the Due than it does on the 8-bit Arduinos. This github issue is one example:

github.com/arduino/Arduino/issues/1251

Since the auto-detection isn’t working for you, you could try supplying the two optional parameters when you call the LSM303 library’s init method. These parameters allow you to specify exactly what model of LSM303 you are talking to, and whether its SA0 line is high or low. For the MinIMU9-v2, the correct arguments to init would be “LSM303DLHC_DEVICE, LSM303_SA0_A_HIGH”.

–David

Thanks David, serves me right for not reading TFM. There’s a note there that says :

Note: Automatic detection of the device type currently does not work with the Arduino Due because of issues with its Wire library. To work around this, specify the device and SA0_A state manually (e.g. init(LSM303DLM_DEVICE, LSM303_SA0_A_HIGH)).

My problem now is that everything is calibrated, magnetic heading is fine, but I get a maximum value of 24 degrees instead of 90. So I Should have 90 deg roll or pitch and I only get max 24. I can see the python animation jump to 90 deg but then it ramps down to 24 and stays there. It’s like there is a filter limiting the maximum value.

Is there any fix for that?

Makes me regret I bought the Due instead of regular Uno as a beginner board.

I am sorry you are having trouble with the MinIMU-9 v2. I do not know why the roll and pitch angles would be capped at 24 degrees. I would like to see what is going on in your system, so could you connect to the Arduino Due using the Serial Monitor and post some sample output from the serial monitor that demonstrates the problem?

–David

Hi David,

I’ve attached the output of the Minimu 9AHRS program when suddenly turning the sensor 90 deg around the x axis after having held it level. You can see that it jumps to -60 roll (should be -90) and then slowly climbs to -14 roll (should still be -90).

Program and library are standard except for bypassing the chip autodetect code.
x_axis_90_roll.txt (2.94 KB)

Thank you for the data and the description of how you generated it. I suspect that the gyro is detecting your quick 90-degree turn, but then the drift-correct provided by the accelerometer and magnetometer is slowly cancelling it out. The LSM303 library comes with an example named “Serial” that prints the raw values. You might use that to make sure that each axis of your accelerometer is working correctly. For a given axis, you should get a positive number when the axis pointing up and a negative number of the same magnitude when the axis is pointing down. It would also be good to make sure that the magnitude of the values given by the accelerometer match what you would expect. However, one caveat is that the Serial example uses different register settings than the MinIMU-9-Arduino-AHRS example.

–David

Raw values look OK, at least they change as expected. I assume there are some issues because the DUE is 32 bit and int has a different range.

I was unable to get to it today, but I intend to try to recreate the problem here and see if I can fix it. You might be right about that 32-bit integer problem. Have you found any places in the code that should be fixed? For reference, here are the three pieces of code that matter:

github.com/pololu/MinIMU-9-Arduino-AHRS
github.com/pololu/LSM303
github.com/pololu/L3G

–David

I’ll try and replace all int declarations with int16_t and see if it does the trick. Tried it with a different library and it worked, to some extent … :). However, having not touched C in 7 years, to say that I’m rusty would be a huge understatement.

Edit: tried but no luck, results are exactly the same.

I tried to recreate the problem you are were having with the MinIMU-9 v2, Arduino Due, and the MinIMU-9-Arduino-AHRS sketch. I encountered a different problem: sometimes the calculations become corrupted and the device starts reporting “nan” for all the angles.

Unfortunately, it seems like there is more than one bug to fix and the MinIMU-9-Arduino-AHRS sketch just does not work on the Arduino Due. This is something we would like to fix eventually, but we are not currently devoting time to it. If you want to continue, I would suggest either debugging the code or getting an Arduino Uno.

–David

Thanks David!

I’ve pulled out the raw data and only computed the data that I needed. I’ll get an Arduino uno in the future, but for now I’m set, the device is doing what I needed it to do.