adafruit_mlx90393

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

  • Author(s): ktown

Implementation Notes

Hardware:

Software and Dependencies:

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

Driver for the MLX90393 magnetometer.

Parameters:
  • 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
  • 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()

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

filter

The filter level.

gain

The gain setting for the device.

last_status

The last status byte received from the sensor.

magnetic

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

oversampling

The oversampling level.

read_data

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

read_reg(reg)

Gets the current value of the specified register.

reset()

Performs a software reset of the sensor.

resolution_x

The X axis resolution.

resolution_y

The Y axis resolution.

resolution_z

The Z axis resolution.

write_reg(reg, value)

Writes the 16-bit value to the supplied register.