Simple test

Ensure your device works with this simple test.

examples/qmc5883p_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5"""QMC5333P Simple Test"""
 6
 7import time
 8
 9import board
10
11import adafruit_qmc5883p
12
13i2c = board.I2C()
14# i2c = board.STEMMA_I2C()
15
16sensor = adafruit_qmc5883p.QMC5883P(i2c)
17
18# configure sensor settings
19# defaults to MODE_NORMAL, ODR_50HZ, RANGE_8G
20
21# sensor.mode = adafruit_qmc5883p.MODE_CONTINUOUS
22# sensor.data_rate = adafruit_qmc5883p.ODR_10HZ
23# sensor.range = adafruit_qmc5883p.RANGE_2G
24
25print("QMC5883P Magnetometer Test")
26print("-" * 40)
27
28while True:
29    mag_x, mag_y, mag_z = sensor.magnetic
30
31    print(f"X:{mag_x:2.3f}, Y:{mag_y:2.3f}, Z:{mag_z:2.3f} G")
32
33    time.sleep(1)