From d1fcc8aabd8c99f7d30fc1ac79585e840f7c6ebf Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 8 Aug 2025 13:39:37 -0400 Subject: [PATCH] tested with hardware --- adafruit_qmc5883p.py | 16 ++++++++-------- examples/qmc5883p_simpletest.py | 3 +-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/adafruit_qmc5883p.py b/adafruit_qmc5883p.py index ba3807a..d44f473 100644 --- a/adafruit_qmc5883p.py +++ b/adafruit_qmc5883p.py @@ -131,11 +131,11 @@ class QMC5883P: raise RuntimeError("Failed to find QMC5883P chip") # Initialize with default settings - self.mode = MODE_CONTINUOUS - self.data_rate = ODR_10HZ - self.oversample_ratio = OSR_8 - self.downsample_ratio = DSR_1 - self.range = RANGE_2G + self.mode = MODE_NORMAL + self.data_rate = ODR_50HZ + self.oversample_ratio = OSR_4 + self.downsample_ratio = DSR_2 + self.range = RANGE_8G self.setreset_mode = SETRESET_ON @property @@ -160,9 +160,9 @@ class QMC5883P: lsb_per_gauss = _LSB_PER_GAUSS[self._range] # Convert to Gauss then to microteslas (1 Gauss = 100 uT) - x = (raw_x / lsb_per_gauss) * 100.0 - y = (raw_y / lsb_per_gauss) * 100.0 - z = (raw_z / lsb_per_gauss) * 100.0 + x = raw_x / lsb_per_gauss + y = raw_y / lsb_per_gauss + z = raw_z / lsb_per_gauss return (x, y, z) diff --git a/examples/qmc5883p_simpletest.py b/examples/qmc5883p_simpletest.py index 57c37c4..26559f2 100644 --- a/examples/qmc5883p_simpletest.py +++ b/examples/qmc5883p_simpletest.py @@ -26,7 +26,6 @@ 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("") + print(f"X:{mag_x:2.3f}, Y:{mag_y:2.3f}, Z:{mag_z:2.3f} G") time.sleep(1)