Go Down

Topic: Magnetometer - acting weird (?) (Read 242 times) previous topic - next topic

cpt_Misomosi

Sep 03, 2019, 10:04 am Last Edit: Sep 03, 2019, 10:24 am by cpt_Misomosi
Hello,
I'm about to make compass using magnetometer (MLX90393), but I want a compass showing north instantly after turning it on. No calibration, no rotating.
Altough magnetometers require calibration to get the values of surrounding magnetic field, i decided not to use only single magnetometer but 24 of them periodically placed in the circle, so they map surrounding magnetic field.

Now I'm testing one piece of MLX90393 on Sparkfun's breakout board, but i keep getting some strange values. If it's still, i get x160 y280.6590 z-61 (microteslas) which is perfectly ok, but... I assume, that if i rotate it 90° the x and y values should flip, right? Because they dont, the values are like this: x170 y240.6590 z-61.
I understand 3-axis magnetometer as 3 pieces of 1-axis magnetometers, so i expect they would measure the same values, when pointed at the same direction. Am I getting it wrong?
I know the question is probably lame and there is something elementary behind it. :smiley-sad:
Thank you.


Sensor I am using: https://learn.sparkfun.com/tutorials/qwiic-magnetometer-mlx90393-hookup-guide/all
Code:
Code: [Select]

#include <Wire.h>
#include "Adafruit_MLX90393.h"

Adafruit_MLX90393 sensor = Adafruit_MLX90393();

void setup(void)
{
  Serial.begin(9600);

  /* Wait for serial on USB platforms. */
  while(!Serial) {
      delay(10);
  }

  Serial.println("Starting Adafruit MLX90393 Demo");

  if (sensor.begin())
  {
    Serial.println("Found a MLX90393 sensor");
  }
  else
  {
    Serial.println("No sensor found ... check your wiring?");
    while (1);
  }
}

void loop(void)
{
    float x, y, z;

    if(sensor.readData(&x, &y, &z)) {
        Serial.print(x, 4); Serial.print(" ");
         Serial.print(y, 4); Serial.print(" ");
         Serial.print(z, 4); Serial.println(" ");
    } else {
        Serial.println("Unable to read XYZ data from the sensor.");
    }

    delay(50);
}

TomGeorge

Hi,
Welcome to the forum.

What happens if you move a magnet around the magnetometer?

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

jremington

#2
Sep 03, 2019, 04:26 pm Last Edit: Sep 03, 2019, 04:31 pm by jremington
Magnetometers need to be carefully calibrated to be useful as a compass.

Calibrate them in their final environment, and if that doesn't change, one calibration pass may be enough.  Comprehensive overview and tutorial here.

If there is something wrong with your code or the magnetometer, that will become obvious during the calibration process.

MarkT

Hi,
Welcome to the forum.

What happens if you move a magnet around the magnetometer?

Tom... :)
You'll permanently magnetize them and everything on the PCB and make them useless.  Never do this with a compass chip.  Its hard enough to calibrate out the hard and soft iron corrections without sabotaging the thing!
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

cpt_Misomosi

Magnetometers need to be carefully calibrated to be useful as a compass.

Calibrate them in their final environment, and if that doesn't change, one calibration pass may be enough.  Comprehensive overview and tutorial here.

If there is something wrong with your code or the magnetometer, that will become obvious during the calibration process.
And that's the problem. It's meant to be used in a meteorological module, of which weight is about 50kg, so it has to be calibrated when still (bc it would be hard to turn it around to calibrate, i guess) and it has to be reliable wherever it's placed.

So it needs to be calibrated only bc of the surrounding magnetic fields? If i had this board with 24 of them (15° between every 2 of them), can I say where cca North is by just looking for the one with the highest value measured? Suppose that it is calibrated for iron in the module.

cpt_Misomosi

Hi,
Welcome to the forum.

What happens if you move a magnet around the magnetometer?

Tom... :)
Hi,
yeah, it sees the magnet, the values it's showing, when magnet is around seem to be legit (and very sensitive). I can imagine that when used in joysticks or something it may be very precise, but I don't think it's capable of being a compass :D
I was using hmc5883l which is precious enough when calibrated (I tried to calibrate MLX90393-not worked, it is sensitive enough to register a magnet, but not north). The problem with hmc5883l is, that i can't have 24 of them connected to one arduino without multiplexor (because the I2C address can't be changed). Now I'm thinking about using LSM303D, It can communicate via both,SPI and I2C (address can be set).

jremington

#6
Sep 04, 2019, 04:42 pm Last Edit: Sep 04, 2019, 04:43 pm by jremington
Quote
So it needs to be calibrated only bc of the surrounding magnetic fields?
Incorrect.  Magnetometers need to be calibrated because of:

1) individual manufacturing inaccuracies
2) distortions of the Earth's magnetic field by nearby iron objects
3) magnetic fields due to magnetized objects and current carrying wires in the vicinity

If you can't figure out a way to calibrate your magnetometers, you will not be able to use them as compasses.

MarkT

Calibration is required for both hard-iron (permanent magnetic fields in the vicinity) and soft-iron (distortion
of the field by ferromagnetic materials in the vicinity).  Both of these can be caused by the module itself, most
surface mount components use steel end-caps for instance, and these may or may not be magnetized.

The flux-concentrator inside the magnetometer itself needs to be calibrated out too.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up