IMU Magnetometer values all zero

I’m accessing IMU data in ReachRS via Egor’s (@egor.fedorov) MPUtest library. Most sensor values are working as expected (accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z, and temperature). However, magnetometer readings only work sporadically, mostly the values returned are zero for all three axes.

Restarting ReachRS sometimes results in good data but usually not.

I know that the IMU is not yet officially supported but I am asking for help on the small chance that somebody has already solved this issue.

@JR_MH I see you had a similar problem. Did you find a solution?

I think I’ve found the answer to my own question.

I will try disabling the first reset of the AK8963 magnetometer in the initialization routine tomorrow (MPU9250.cpp) (I don’t have access to the hardware right now).

//{0x80, MPUREG_PWR_MGMT_1}, // Reset Device - Disabled because it seems to corrupt initialisation of AK8963

1 Like

i did use this with my arduino maybe someone can port this …

The calibration of the magnetometer is required to compensate for Magnetic Declination. The exact value of the correction depends on the location. There are two variables that have to calibrated: yaw and magbias.
i did use Permanent Calibration…

Thanks @Andreas_Ortner, this was just what I needed.

I now have IMU data streaming from ReachRS. The magnetometer passes the self-test but the values do not look right. I will implement the calibration procedure you have pointed me to and see it this improves things.

1 Like

First imu needs calibrations and values according to your magnetical place
Then Data needs some filters like in this github…

i have only poor programming skills…

so i would be happy if you keep me updated…

I am able to stream IMU accel, Gryo and Mag value using a python script.

How can these be converted to heading, yaw, pitch, and roll?

Here’s an example of the data I’m able to get out:

Acc: +0.417 +0.210 +0.916 Gyr: -0.122 -0.183 -0.549 Mag: -19.122 +4.857 +14.048 Temp: +58.8
Acc: +0.423 +0.214 +0.917 Gyr: -0.305 -0.061 -0.671 Mag: -15.548 +5.217 +11.273 Temp: +58.8
Acc: +0.418 +0.211 +0.907 Gyr: -0.122 -0.183 -0.671 Mag: -19.122 +7.735 +12.314 Temp: +58.7
Acc: +0.422 +0.212 +0.919 Gyr: -0.061 -0.366 -0.610 Mag: -20.552 +8.454 +11.273 Temp: +58.8
Acc: +0.425 +0.217 +0.914 Gyr: -0.061 -0.061 -0.732 Mag: -17.871 +6.116 +10.406 Temp: +58.7
Acc: +0.426 +0.218 +0.903 Gyr: +0.000 -0.366 -0.732 Mag: -19.122 +4.497 +14.395 Temp: +58.8
Acc: +0.424 +0.224 +0.926 Gyr: -0.122 -0.244 -0.549 Mag: -16.441 +6.476 +11.100 Temp: +58.8
Acc: +0.421 +0.218 +0.910 Gyr: -0.305 -0.488 -0.732 Mag: -18.407 +8.454 +12.661 Temp: +58.7
Acc: +0.422 +0.216 +0.910 Gyr: -0.244 -0.244 -0.610 Mag: -15.012 +8.994 +10.753 Temp: +58.8
Acc: +0.424 +0.218 +0.908 Gyr: -0.122 -0.122 -0.549 Mag: -18.765 +7.015 +14.742 Temp: +58.7
Acc: +0.425 +0.219 +0.917 Gyr: -0.244 -0.183 -0.671 Mag: -16.620 +6.296 +14.048 Temp: +58.8
Acc: +0.422 +0.216 +0.903 Gyr: -0.122 -0.244 -0.732 Mag: -20.194 +6.296 +11.967 Temp: +58.8

Hi @feepyj,

You need the formulas for a “tilt compensated compass”.

These links will get you started.

The tilt compensated compass only works while Reach is static. If you what the orientation of Reach while dynamic then you will need to use one of the more complicated sensor fusion libraries like this one (https://github.com/micropython-IMU/micropython-fusion).

Hi ben,
i woudl also be very thankful if you could share the steps to get the data streamed…
Thanks!

@Johannes_Eberenz,

Unfortunately I can’t provide my code but I can list the basic steps.

If all goes well you will have IMU data streaming to your application.

1 Like

thanks that will get me started!

This topic was automatically closed after 100 days. New replies are no longer allowed.