MLX90393 Triple-axis Magnetometer

The mlx90393 sensor platform allows you to use your MLX90393 (datasheetExternal link, Adafruit_) three axis magnetometer with ESPHome. The I²C is required to be set up in your configuration for this sensor to work.

AdafruitExternal link

# Example configuration entry
sensor:
  - platform: mlx90393
    id: mlx
    x_axis:
      name: "x"
    y_axis:
      name: "y"
    z_axis:
      name: "z"

Configuration variables: Copy link to header

  • x_axis (Optional): The information for the x-axis.

    • resolution (Optional, int): Specify which part of the full 19-bit value to read. Defaults to DIV_4. Must be one of:

      • DIV_8
      • DIV_4
      • DIV_2
      • DIV_1
    • All other options from Sensor.

  • y_axis (Optional): The information for the y-axis.

    • resolution (Optional, int): Specify which part of the full 19-bit value to read. Defaults to DIV_4. Must be one of:

      • DIV_8
      • DIV_4
      • DIV_2
      • DIV_1
    • All other options from Sensor.

  • z_axis (Optional): The information for the z-axis.

    • resolution (Optional, int): Specify which part of the full 19-bit value to read. Defaults to DIV_4. Must be one of:

      • DIV_8
      • DIV_4
      • DIV_2
      • DIV_1
    • All other options from Sensor.

  • temperature (Optional): Built-in temperature sensor.

    • oversampling (Optional, int): On-chip oversampling for the temperature sensor. Defaults to 0. Must be between 0 and 3.
    • All other options from Sensor.
  • drdy_pin (Optional, Pin Schema): Data-ready pin. Often labelled INT. Using this pin might lead to slightly quicker read times.

  • gain (Optional, int): Sets the analog gain. Defaults to 1X. Must be one of

    • 1X
    • 1_25X
    • 1_67X
    • 2X
    • 2_5X
    • 3X
    • 3_75X
    • 5X
  • oversampling (Optional, int): On-chip oversampling. Defaults to 2. Must be between 0 and 3.

  • filter (Optional, int): On-chip digital filter. Defaults to 6. Must be between 0 and 7.

  • temperature_compensation (Optional, bool): On-chip temperature compensation. Defaults to false. When enabled, the resolution options DIV_8 and DIV_4 cannot be used.

  • hallconf (Optional, int): Modifies the hall plate spinning (2-phase vs 4-phase). Defaults to 0xC. Must be 0xC or 0x0.

  • update_interval (Optional, Time): The interval to check the sensor. Defaults to 60s.

  • address (Optional, int): Manually specify the I²C address of the sensor. Defaults to 0x0C.

  • i2c_id (Optional, ID): Manually specify the ID of the I²C Component if you want to use multiple I²C buses.

Gain, resolution and full scale readings Copy link to header

By default, the sensor is configured for the lowest sensitivity. This enables reading magnetic fields of 50,000 µT. However, sensitivity is limited to 3 µT. This can be improved significantly using the gain and resolution options, at the cost of reducing the maximum magnetic field that can be measured.

The sensor internally generates an analog signal which is sent to an amplifier. The gain option controls this amplifier. Too much amplification will cause saturation of the values, but no integer overflow.

After amplification, the analog signal is digitized using a 19-bit ADC. Only 16 bits are sent to ESPHome. The resolution option chooses which bits are sent.

Note that the ADC doesn’t actually fill all its 19 bits. This causes DIV_4 to have the same maximum field as DIV_8, while giving better sensitivity. Only DIV_2 and DIV_1 actually use all values, giving them the best dynamic range. However, both will cause integer overflows when the maximum field strength is exceeded.

After receiving the 16-bit value, ESPHome converts it to floating point values in µT. Therefore, neither gain nor resolution affects the magnitude of the values in ESPHome directly.

The following table shows the sensitivity and maximum field strength for every combination. Note that the Z axis has worse sensitivity due to hardware constraints.

gainresolutionsensitivity XY (µT/LSB)max field XY (µT)sensitivity Z (µT/LSB)max field Z (µT)
1XDIV_86.00966,0989.680106,480
1XDIV_43.00466,0984.840106,480
1XDIV_21.50249,2252.42079,299
1XDIV_10.75124,6121.21039,649
1_25XDIV_84.80752,8787.74485,184
1_25XDIV_42.40452,8783.87285,184
1_25XDIV_21.20239,3801.93663,439
1_25XDIV_10.60119,6900.96831,719
1_67XDIV_83.60539,6595.80863,888
1_67XDIV_41.80339,6592.90463,888
1_67XDIV_20.90129,5351.45247,579
1_67XDIV_10.45114,7670.72623,790
2XDIV_83.00433,0494.84053,240
2XDIV_41.50233,0492.42053,240
2XDIV_20.75124,6121.21039,649
2XDIV_10.37612,3060.60519,825
2_5XDIV_82.40426,4393.87242,592
2_5XDIV_41.20226,4391.93642,592
2_5XDIV_20.60119,6900.96831,719
2_5XDIV_10.3009,8450.48415,860
3XDIV_82.00322,0333.22735,493
3XDIV_41.00122,0331.61335,493
3XDIV_20.50116,4080.80726,433
3XDIV_10.2508,2040.40313,216
3_75XDIV_81.60217,6262.58128,395
3_75XDIV_40.80117,6261.29128,395
3_75XDIV_20.40113,1270.64521,146
3_75XDIV_10.2006,5630.32310,573
5XDIV_81.20213,2201.93621,296
5XDIV_40.60113,2200.96821,296
5XDIV_20.3009,8450.48415,860
5XDIV_10.1504,9220.2427,930

For hallconf = 0x0, the sensitivity scales with a factor 98/75. For example 0.150μT/LSB with HALLCONF 0xC becomes 0.196μT/LSB with HALLCONF 0x0. The maximum field strength changes accordingly.

See Also Copy link to header

CURRENT