Adafruit_CircuitPython_QMC5.../examples/qmc5883p_simpletest.py
2025-08-08 11:34:58 -04:00

32 lines
770 B
Python

# SPDX-FileCopyrightText: Copyright (c) 2025 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""QMC5333P Simple Test"""
import time
import board
import adafruit_qmc5883p
i2c = board.I2C() # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
sensor = adafruit_qmc5883p.QMC5883P(i2c)
# Optional: Configure sensor settings
# sensor.mode = adafruit_qmc5883p.MODE_CONTINUOUS
# sensor.data_rate = adafruit_qmc5883p.ODR_10HZ
# sensor.range = adafruit_qmc5883p.RANGE_2G
print("QMC5883P Magnetometer Test")
print("-" * 40)
while True:
mag_x, mag_y, mag_z = sensor.magnetic
print(f"X:{mag_x:10.2f}, Y:{mag_y:10.2f}, Z:{mag_z:10.2f} uT")
print("")
time.sleep(1)