cancel
Showing results for 
Search instead for 
Did you mean: 

Addressing Offset and Calibration Issues with IIS2MDC Sensors

Jinlee
Associate

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.

Jinlee_0-1729586995606.png

 

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, &currentRegB);  
  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.

1 REPLY 1
Andrew Neil
Evangelist III

Please see the posting tips for how to properly post source code - not as images:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

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