Skip to content

Commit d1fcc8a

Browse files
committed
tested with hardware
1 parent 07266ab commit d1fcc8a

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

adafruit_qmc5883p.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def __init__(self, i2c_bus: busio.I2C, address: int = _DEFAULT_ADDR) -> None:
131131
raise RuntimeError("Failed to find QMC5883P chip")
132132

133133
# Initialize with default settings
134-
self.mode = MODE_CONTINUOUS
135-
self.data_rate = ODR_10HZ
136-
self.oversample_ratio = OSR_8
137-
self.downsample_ratio = DSR_1
138-
self.range = RANGE_2G
134+
self.mode = MODE_NORMAL
135+
self.data_rate = ODR_50HZ
136+
self.oversample_ratio = OSR_4
137+
self.downsample_ratio = DSR_2
138+
self.range = RANGE_8G
139139
self.setreset_mode = SETRESET_ON
140140

141141
@property
@@ -160,9 +160,9 @@ def magnetic(self) -> Tuple[float, float, float]:
160160
lsb_per_gauss = _LSB_PER_GAUSS[self._range]
161161

162162
# Convert to Gauss then to microteslas (1 Gauss = 100 uT)
163-
x = (raw_x / lsb_per_gauss) * 100.0
164-
y = (raw_y / lsb_per_gauss) * 100.0
165-
z = (raw_z / lsb_per_gauss) * 100.0
163+
x = raw_x / lsb_per_gauss
164+
y = raw_y / lsb_per_gauss
165+
z = raw_z / lsb_per_gauss
166166

167167
return (x, y, z)
168168

examples/qmc5883p_simpletest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
while True:
2727
mag_x, mag_y, mag_z = sensor.magnetic
2828

29-
print(f"X:{mag_x:10.2f}, Y:{mag_y:10.2f}, Z:{mag_z:10.2f} uT")
30-
print("")
29+
print(f"X:{mag_x:2.3f}, Y:{mag_y:2.3f}, Z:{mag_z:2.3f} G")
3130

3231
time.sleep(1)

0 commit comments

Comments
 (0)