2024-10-22
02:07 AM
- last edited on
2024-10-22
04:27 AM
by
Maxime_MARCHETT
We are conducting research using 9 IIS2MDC sensors to detect the position of a magnetic material (e.g., N52 grade neodymium magnet). Since we expect the distance between the magnetic material and the sensors to be large, the sensors need to accurately detect the magnitude and direction of the magnetic field generated by the material. However, we have identified that the IIS2MDC sensors we are using have an error margin of approximately ±1300 mG, and we are encountering the following issues:
1. The offset indicated in the datasheet is approximately ±60 mG. However, even after completely removing the influence of the magnetic material, the initial magnetic field values measured by each sensor still range from 0 to 1000 mG. Since these initial values vary between sensors, we predict that this is not due to the Earth's magnetic field. We are curious about the possible cause of this.
2. We have already applied the basic register settings recommended in the datasheet, such as offset cancellation, low-pass filter, and reboot, but the issue has not been fully resolved. We wonder if an initial calibration procedure is necessary for each sensor. If so, we would like to know the details of this procedure.
#include <Wire.h>
#include <IIS2MDCSensor.h>
#define SerialPort Serial
#define dev_i2c Wire
IIS2MDCSensor Magneto(&dev_i2c);
void enableLowPassFilter() {
uint8_t currentRegB;
Magneto.WriteReg(0x61, currentRegB | 0x01);
SerialPort.println("Low-pass filter enabled");
}
void enableOffsetCancellation() {
uint8_t currentRegB;
Magneto.ReadReg(0x61, ¤tRegB);
Magneto.WriteReg(0x61, currentRegB | 0x10);
SerialPort.println("Offset cancellation enabled");
}
void rebootMemory() {
Magneto.WriteReg(0x60, 0x40);
delay(10);
SerialPort.println("Memory reboot completed");
}
void setup() {
SerialPort.begin(115200);
dev_i2c.begin();
Magneto.begin();
enableLowPassFilter();
enableOffsetCancellation();
rebootMemory();
Magneto.Enable();
}
void loop() {
readSensorData();
delay(500);
}
void readSensorData() {
int32_t magnetometer[3];
Magneto.GetAxes(magnetometer);
SerialPort.print("Mag[mGauss]: ");
SerialPort.print(magnetometer[0]);
SerialPort.print(", ");
SerialPort.print(magnetometer[1]);
SerialPort.print(", ");
SerialPort.println(magnetometer[2]);
}
The library files were downloaded from the following site: https://github.com/stm32duino/IIS2MDC
3. Lastly, when a sensor becomes magnetized due to a large external magnetic field, its offset changes. We are wondering if there is a procedure to reset this phenomenon.
Thank you.
This post has been translated from Korean to comply with the ST Community guidelines.
2024-10-22 02:13 AM
Please see the posting tips for how to properly post source code - not as images:
Note that this is (principally) a user-to-user forum; If you want direct ST support, raise a case here: https://ols.st.com/s/
Or perhaps contact your local distributor: https://www.st.com/content/st_com/en/contact-us.html