3/18/2019
Grove - 3-Axis Digitial Compass v2.0 - Seeed Wiki
http://wiki.seeedstudio.com/Grove-3-Axis_Digitial_Compass_v2.0/
13/15
Step 3. Excute below commands to run the code.
Following is the grove_3_axis_compass_bmm150.py code.
1
2
cd grove.py/grove
python grove_3_axis_compass_bmm150.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from
__future__
import
print_function
import
time
,
sys
,
signal
,
atexit
,
math
try
:
from
upm
import
pyupm_bmm150
as
sensorObj
except
ImportError
:
(
'Error: Please install python-mraa python-upm module.
\r\n
'See instruction here https://github.com/Seeed-Studio/pi_
def
main
():
# Instantiate a BMP250E instance using default i2c bus and addr
sensor = sensorObj.BMM150(
0
,
0x13
)
# For SPI, bus 0, you would pass -1 as the address, and a valid
# BMM150(0, -1, 10);
## Exit handlers ##
# This function stops python from printing a stacktrace when yo
def
SIGINTHandler
(signum, frame):
raise
SystemExit
# This function lets you run code on exit
def
exitHandler
():
(
"Exiting"
)
sys.exit(
0
)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# now output data every 250 milliseconds
while
(
1
):
sensor.update()
data = sensor.getMagnetometer()
(
"Magnetometer x: {0:.2f}"
.format(data[
0
]), end=
' '
)