This is a breakout for the Adafruit MLX90393 magnetometer sensor breakout.

  • Author(s): ktown

Implementation Notes


Software and Dependencies:

class adafruit_mlx90393.MLX90393(i2c_bus: I2C, address: int = 12, gain: int = 7, resolution: int = 0, filt: int = 7, oversampling: int = 3, debug: bool = False)

Driver for the MLX90393 magnetometer.

  • i2c_bus – The I2C bus the device is connected to

  • address (int) – The I2C device address. Defaults to 0x0C

  • gain (int) – The gain level to apply. Defaults to GAIN_1X

  • resolution (int) – The resolution level to use. Defaults to RESOLUTION_16

  • filt (int) – The filter to use. Defaults to FILTER_7

  • oversampling (int) – The oversampleing setting to use. Defaults to OSR_3

  • debug (bool) – Enable debug output. Defaults to False

Quickstart: Importing and using the device

Here is an example of using the MLX90393 class. First you will need to import the libraries to use the sensor

import board
import adafruit_mlx90393

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
SENSOR = adafruit_mlx90393.MLX90393(i2c)

Now you have access to the magnetic attribute

MX, MY, MZ = SENSOR.magnetic
display_status() None

Prints out the content of the last status byte in a human-readable format.

property filter: int

The filter level.

property gain: int

The gain setting for the device.

property last_status: int

The last status byte received from the sensor.

property magnetic: Tuple[float, float, float]

The processed magnetometer sensor values. A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.

property oversampling: int

The oversampling level.

property read_data: Tuple[int, int, int]

Reads a single X/Y/Z sample from the magnetometer.

read_reg(reg: int) int

Gets the current value of the specified register.


reg (int) – The register to read

reset() None

Performs a software reset of the sensor.

property resolution_x: int

The X axis resolution.

property resolution_y: int

The Y axis resolution.

property resolution_z: int

The Z axis resolution.

write_reg(reg: int, value: int) None

Writes the 16-bit value to the supplied register.

  • reg (int) – The register to write to

  • value (int) – The value to write to the register