tested with hardware
This commit is contained in:
parent
07266ab1ca
commit
d1fcc8aabd
2 changed files with 9 additions and 10 deletions
|
|
@ -131,11 +131,11 @@ class QMC5883P:
|
||||||
raise RuntimeError("Failed to find QMC5883P chip")
|
raise RuntimeError("Failed to find QMC5883P chip")
|
||||||
|
|
||||||
# Initialize with default settings
|
# Initialize with default settings
|
||||||
self.mode = MODE_CONTINUOUS
|
self.mode = MODE_NORMAL
|
||||||
self.data_rate = ODR_10HZ
|
self.data_rate = ODR_50HZ
|
||||||
self.oversample_ratio = OSR_8
|
self.oversample_ratio = OSR_4
|
||||||
self.downsample_ratio = DSR_1
|
self.downsample_ratio = DSR_2
|
||||||
self.range = RANGE_2G
|
self.range = RANGE_8G
|
||||||
self.setreset_mode = SETRESET_ON
|
self.setreset_mode = SETRESET_ON
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -160,9 +160,9 @@ class QMC5883P:
|
||||||
lsb_per_gauss = _LSB_PER_GAUSS[self._range]
|
lsb_per_gauss = _LSB_PER_GAUSS[self._range]
|
||||||
|
|
||||||
# Convert to Gauss then to microteslas (1 Gauss = 100 uT)
|
# Convert to Gauss then to microteslas (1 Gauss = 100 uT)
|
||||||
x = (raw_x / lsb_per_gauss) * 100.0
|
x = raw_x / lsb_per_gauss
|
||||||
y = (raw_y / lsb_per_gauss) * 100.0
|
y = raw_y / lsb_per_gauss
|
||||||
z = (raw_z / lsb_per_gauss) * 100.0
|
z = raw_z / lsb_per_gauss
|
||||||
|
|
||||||
return (x, y, z)
|
return (x, y, z)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ print("-" * 40)
|
||||||
while True:
|
while True:
|
||||||
mag_x, mag_y, mag_z = sensor.magnetic
|
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(f"X:{mag_x:2.3f}, Y:{mag_y:2.3f}, Z:{mag_z:2.3f} G")
|
||||||
print("")
|
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue