Magnetometer gives me no values

Hi, I want to read out the IMU values like gyro, accel and magnetometer. For a certain time it works, but then I get only 0 for the magnetometer and only a restart of the Reach RTK fixed that issue and I get back normal magnetometer values. Is there a possibility to fix that without an restart or does someone know what’s the problem?

I used the MPU9250.cpp from this repository.

Thank you.

Quite possible that there is some issue with the driver, but this is not officially supported yet. We will get to it and everything will work just fine :slight_smile:

Is there any update on supporting magnetometer? I have the same issue, that sometimes I get all 0 values. It happens in 5% cases. When I restart initialize the MPUtest again, then I get the readings.
My main question is, can magnetometer be used to find out the heading (yaw)? As it seems to me, if I turn the module on ground, the magnetometer readings do not change much. Should I read something in addition?

Thanks!

Hi @ago, the magnetometer can definitely be used to obtain heading. You do however need to calibrate it first to compensate for both hard iron and soft iron distortions. You also need to compensate for magnetic variation and deviation.

If the IUM will be tilted by any significant amount you will also need to use the accelerator data to compensate for tilt.

I did experience the magnetometer returning zero values when I first started playing around with it but I haven’t experienced it for a long time. Form memory, I think I fixed this problem by running the magnetometer self-test and only starting the data feed after it passed the test (sometimes it takes multiple attempts). But I could be wrong here, it has been a while since I looked at the code.

Hi @BenLewis
Thank you for a quick reply!

I checked your links and this seems promising. I have however a question. The raw magnetic data coming from the module seems quite static when changing the heading (yaw). When turning the model around in other directions, the magnetic values change. Is this normal? I cannot see a way how a correct heading can be calculated based on those “static” values. By “static” I mean they change a bit, but in general they stay in the same range (+/- 10 or so, depending how smooth I can turn the module).
Am I missing something here?

Just a small example, I made the full turn with the module. That’s what MPUtest gives me:

Acc: -0.025 +0.003 +0.930 Gyr: -0.976 +0.976 +5.915 Mag: +22.316 +14.175 +23.600
...
Acc: -0.158 +0.195 +0.900 Gyr: +17.622 -16.707 -27.500 Mag: +25.848 +16.575 +23.600
...
Acc: +0.085 -0.062 +1.073 Gyr: -5.488 -9.207 -126.220 Mag: +23.440 +17.850 +24.462
...
Acc: +0.006 +0.018 +0.667 Gyr: +1.037 +2.012 +65.976 Mag: +15.734 +17.250 +19.294

Those are just some lines. But as you can see, the mag part is basically the same (all those remain in the range 15 … 26 or so).
Am I missing something?

Hi @ago, I had the same thought when I first started testing the magnetometer. But there are a few factors at play here.

  • Inclination - Where I’m located (Ballarat, Australia) the magnetic inclination is about 68°. This means that there is only a small component of the total magnetic filed in the horizontal plane.
    image
  • Hard-iron distortion - In my case, the magnetic distortion, due to hard-iron effects, was so great that it shifted the entire field into the positive (or negative) range.

By performing a hard-iron calibration you will shift the field into the center (you will get both positive and negative values). By performing a soft-iron calibration the magnetic field will be scaled equally in all directions.

After performing the above calibrations, the small magnetic field present in the horizontal plane will work as expected.

1 Like

Hi again @BenLewis

I understand the idea behind the calibration. I have tried several different tools to calibrate the magnetometer. But still no luck. So, I have the following questions:

  1. Did you get it working with Emlid Reach RTK kit?
  2. What software did you use to read data from IMU and magnetometer?
  3. What software did you use to do the calibration?
  4. How did you apply the calibration data? Like, did you change the software you use to read data? Or do you apply it later on somehow?
  5. Is there a difference how the module is placed on the moving device? Like, should the forward moving direction be x-axis and z points up? Or something else?

Some soft try to do calibration themselves. All my tries end up with the result where the magnetometer doesn’t recognize any change in yaw. This is tested so that z points up. I apply the calibration after the magnetometer readings. So, from the module itself, I still get the same data, but use calibrated values to normalize the result.
I have tried two modules. One was inside a metal construction, the other was plain module with not significant metal near-by. Both have the same result - no change in yaw when rotating.

Thanks in advance!

Hi @ago,

It’s been a while since I did this so I may not have all the details correct. I hope this helps.

With Reach RS

Data was sent over a TCP connection. I then used HW VSP to create a virtual serial port.

MagMaster

The raw calibrated data is send from Reach RS, calibration in applied in my application.

It is important that you use a consistent convention with the accelerator, magnetometer and Reach RS. From memory the magnetometer and accelerator do not have the same orientation and both were different to the orientation that made sense for my application so I ended up transforming both axes to match the desired orientation for Reach RS.

If after this you still can’t get it working please PM me and we can set up a time to have a chat about it.

A post was split to a new topic: Read out the IMU values