Simple test

Ensure your device works with this simple test.

examples/mlx90393_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import adafruit_mlx90393
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
10SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X)
11
12while True:
13    MX, MY, MZ = SENSOR.magnetic
14    print("[{}]".format(time.monotonic()))
15    print("X: {} uT".format(MX))
16    print("Y: {} uT".format(MY))
17    print("Z: {} uT".format(MZ))
18    # Display the status field if an error occured, etc.
19    if SENSOR.last_status > adafruit_mlx90393.STATUS_OK:
20        SENSOR.display_status()
21    time.sleep(1.0)

Temperature test

Example showing how to measure temperature with the sensor

examples/mlx90393_temperature.py
 1# SPDX-FileCopyrightText: 2023 Jose D. Montoya
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import adafruit_mlx90393
 7
 8i2c = board.I2C()  # uses board.SCL and board.SDA
 9# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
10SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X)
11
12
13while True:
14    temp = SENSOR.temperature
15
16    print("Temperature: {} °C".format(temp))
17
18    # Display the status field if an error occurred, etc.
19    if SENSOR.last_status > adafruit_mlx90393.STATUS_OK:
20        SENSOR.display_status()
21    time.sleep(1.0)