+-16 gauss setting

Hello, I am trying to make a magnetic field sensor by writing code on the Arduino ide platform and using lis3mdl. I use the default detection level setting of ±4. However, I would also like to see ±12 and 16 levels. But I don’t know how to do this. How can I set these values? In the library?
Another issue is; I see the detection values as two and three-digit numbers in the Serial.print(report) view. Shouldn’t these numbers have more digits? For example, like 6 or 7 steps.

Hello.

Changing the LIS3MDL magnetometer’s resolution requires writing to its registers, specifically, CTRL_REG2. If you are using our LIS3MDL Arduino library, then you can use the writeReg() function for this, and you can see examples of how that function is used in the definition of the enableDefault() function from the LIS3MDL.cpp file. You can find more information about each of the LIS3MDL’s registers in the “Registers description” section of its datasheet, which is available on the product page under the “Resources” tab.

As for the values from your magnetometer, can you provide more details about how you are using the magnetometer and what sorts of values you are expecting from it? For example, are you just looking at the output from one of our unmodified example programs, and have you done anything to try and calibrate your magnetometer yet?

In case you are not thinking about it already, keep in mind that it is especially important to calibrate magnetometers because their readings can be distorted enough to make their uncalibrated measurements more or less useless. Here are some links to threads with discussions about how you could go about calibrating magnetometers, though please note that they do not all refer the same hardware, programs, or libraries:

- Patrick

1 Like

Hello Patrick, first of all, thank you for your answer. Yes, I made a magnetic field sensor with Arduino Uno, using your library. I created an algorithm using data from lis3mdl’s 3 axes. My impression is that the data varies a lot. There is stability difficulty as if there is a parasite. Also, I think that the detection limit of an iron pliers that I move closer to the x-axis is very close. I reviewed the wiring diagrams and installed the necessary capacitors. I am using 3.7v battery. The magnetic sensor is located at a point far from the circuit.
I read articles about calibration, but there is no clear explanation. So, I could not find an article that suggested how to understand that the calibration setting was incorrect and how to eliminate this error.
I expect your help in these matters.
Respects,
Ahmet,

A basic approach to calibrate your magnetometer using our LIS3MDL library is to run the Calibrate.ino example sketch during which you should move the board in every possible orientation (i.e. like you are trying to paint the inside of a sphere). Then, you can record the min/max readings and calculate offsets to subtract from subsequent readings like we do in our “HeadingWithLSM6.ino” example program.

A calibration like that should be good enough to get you started, but you might need to a implement a more rigorous procedure (like the ones described in the posts I linked to) depending on what you are trying to do and the accuracy you are trying to achieve.

- Patrick

1 Like

Thank you. The caliber program is already included in the Arduino ide. Forgive my ignorance, I have to ask this; Do I need to make any changes to the code after pretending to paint the inside of a sphere, or does the sensor calibrate itself without me having to do anything?

Yes; to clarify my previous post, you would record the min/max readings after using the Calibrate.ino example so that you can calculate the offsets. Then you would modify your other programs to subtract those offsets from your readings like we do in our “HeadingWithLSM6.ino” example. (It might also be helpful to scale the readings uniformly if the ranges are different across axes.)

It might be helpful for you to look at this “Quick and Dirty Compass Calibration in 3d” blog post written by one of our customers. It describes and illustrates the calibration process with one of the older ST magnetometers in more detail.

- Patrick

1 Like