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
 5
 6import board
 7
 8import adafruit_mlx90393
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12try:
13    SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X)
14except ValueError:
15    SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X, address=0x18)
16
17while True:
18    MX, MY, MZ = SENSOR.magnetic
19    print(f"[{time.monotonic()}]")
20    print(f"X: {MX} uT")
21    print(f"Y: {MY} uT")
22    print(f"Z: {MZ} uT")
23    # Display the status field if an error occured, etc.
24    if SENSOR.last_status > adafruit_mlx90393.STATUS_OK:
25        SENSOR.display_status()
26    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
 5
 6import board
 7
 8import adafruit_mlx90393
 9
10i2c = board.I2C()  # uses board.SCL and board.SDA
11# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
12try:
13    SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X)
14except ValueError:
15    SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X, address=0x18)
16
17
18while True:
19    temp = SENSOR.temperature
20
21    print(f"Temperature: {temp} °C")
22
23    # Display the status field if an error occurred, etc.
24    if SENSOR.last_status > adafruit_mlx90393.STATUS_OK:
25        SENSOR.display_status()
26    time.sleep(1.0)