Home Circuitpython Adafruit Feather M0 and MLX90393 magnetometer circuitpython example

Adafruit Feather M0 and MLX90393 magnetometer circuitpython example

by shedboy71

In this example we connect a MLX90393 magnetometer to an Adafruit Feather M0 running Circuitpython

First lets look at some information about the sensor from the manufacturer

The MLX90393 is the newest addition to the Melexis position sensing portfolio, bringing the highest flexibility in the portfolio’s smallest assembly.

Complementing this, the magnetic field sensor IC is designed for micropower applications, with programmable duty cycles in the range of 0.1% to 100%.

The MLX90393 magnetic field sensor IC can be reprogrammed to different modes and with different settings at run-time. The sensor IC offers a 16-bit output proportional to the magnetic flux density sensed along the XYZ axes using the Melexis proprietary Triaxis® technology and also offers a temperature output signal. These digital values are available via I2C and SPI, where the MLX90393 is a slave on the bus.

By selecting which axes are to be measured, the raw data can be used as input for further post-processing, such as for joystick applications, rotary knobs, and more complex 3D position sensing applications.

Unparallelled performance is achieved with this sensor, which is primarily targeting industrial and consumer applications.

This was my sensor of choice that I used

Parts Required

 

Name Link
Adafruit Feather M0 Express Adafruit (PID 3403) Feather M0 Express – Designed for CircuitPython – ATSAMD21 Cortex M0
MLX90393 MLX90393 Digital 3D Hall Sensor Three-Displacement Angle Rotate 3D Position Sensor Module
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

Code Example

I used Mu for development

The following is based on a library , I copied the vl6180x library for this device to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries

[codesyntax lang=”python”]

import time
import busio
import board

import adafruit_mlx90393

I2C_BUS = busio.I2C(board.SCL, board.SDA)
SENSOR = adafruit_mlx90393.MLX90393(I2C_BUS, gain=adafruit_mlx90393.GAIN_1X)

while True:
    MX, MY, MZ = SENSOR.magnetic
    print("[{}]".format(time.monotonic()))
    print("X: {} uT".format(MX))
    print("Y: {} uT".format(MY))
    print("Z: {} uT".format(MZ))
    # Display the status field if an error occured, etc.
    if SENSOR.last_status > adafruit_mlx90393.STATUS_OK:
        SENSOR.display_status()
    time.sleep(1.0)

[/codesyntax]

Output

Here is what I saw in Mu REPL window

[23015.3]
X: 355.5 uT
Y: 193.8 uT
Z: -210.298 uT
[23016.3]
X: 350.1 uT
Y: 186.3 uT
Z: -230.868 uT
[23017.4]
X: 355.35 uT
Y: 186.3 uT
Z: -216.106 uT

Links

https://www.melexis.com/-/media/files/documents/datasheets/mlx90393-datasheet-melexis.pdf

You may also like

1 comment

Leave a Comment