3/18/2019
Grove - 3-Axis Digitial Compass v2.0 - Seeed Wiki
http://wiki.seeedstudio.com/Grove-3-Axis_Digitial_Compass_v2.0/
14/15
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(
" y: {0:.2f}"
.format(data[
1
]), end=
' '
)
(
" z: {0:.2f}"
.format(data[
2
]), end=
' '
)
(
" uT"
)
xyHeading = math.atan2(data[
0
], data[
1
])
zxHeading = math.atan2(data[
2
], data[
0
])
heading = xyHeading
if
heading <
0
:
h=
2
*math.pi
if
heading >
2
*math.pi:
heading -=
2
*math.pi
headingDegrees = heading *
180
/(math.pi);
xyHeadingDegrees = xyHeading *
180
/ (math.pi)
zxHeadingDegrees = zxHeading *
180
/ (math.pi)
(
'heading(axis_Y point to): {0:.2f} degree'
.format(hea
time.sleep(.
250
)
if
__name__ ==
'__main__'
:
main()
Success
If everything goes well, you will be able to see the following result
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pi
@raspberrypi
:~/grove.py/grove
$
python grove_3_axis_compass_bmm15
Magnetometer x: -
34.12
y:
36.71
z: -
21.25
uT
heading(axis_Y point to):
317.10
degree
Magnetometer x: -
34.49
y:
38.20
z: -
16.32
uT
heading(axis_Y point to):
317.92
degree
Magnetometer x: -
34.12
y:
38.20
z: -
9.87
uT
heading(axis_Y point to):
318.23
degree
Magnetometer x: -
32.64
y:
38.94
z: -
5.69
uT
heading(axis_Y point to):
320.03
degree
Magnetometer x: -
31.52
y:
38.20
z: -
2.28
uT
heading(axis_Y point to):
320.47
degree
Magnetometer x: -
29.67
y:
38.20
z:
0.38
uT
heading(axis_Y point to):
322.16
degree
Magnetometer x: -
26.33
y:
38.20
z:
4.55
uT
heading(axis_Y point to):
325.42
degree
^CExiting