3374 |
kaklik |
1 |
#!/usr/bin/python |
|
|
2 |
|
|
|
3 |
# Python driver for MLAB MAG01A module with HMC5888L Magnetometer sensor wrapper class |
|
|
4 |
|
|
|
5 |
import time |
|
|
6 |
import datetime |
|
|
7 |
import sys |
|
|
8 |
|
|
|
9 |
from pymlab import config |
|
|
10 |
|
|
|
11 |
|
|
|
12 |
#### Script Arguments ############################################### |
|
|
13 |
|
3375 |
kaklik |
14 |
if len(sys.argv) != 2: |
3374 |
kaklik |
15 |
sys.stderr.write("Invalid number of arguments.\n") |
|
|
16 |
sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], )) |
|
|
17 |
sys.exit(1) |
|
|
18 |
|
|
|
19 |
port = eval(sys.argv[1]) |
|
|
20 |
|
|
|
21 |
|
|
|
22 |
#### Sensor Configuration ########################################### |
|
|
23 |
|
|
|
24 |
cfg = config.Config( |
|
|
25 |
bus = [ |
3375 |
kaklik |
26 |
# { |
|
|
27 |
# "type": "i2chub", |
|
|
28 |
# "address": 0x70, |
|
|
29 |
# |
|
|
30 |
# "children": [ |
|
|
31 |
# { |
|
|
32 |
# "type": "i2chub", |
|
|
33 |
# "address": 0x70, |
|
|
34 |
# "channel": 1, |
|
|
35 |
# |
|
|
36 |
# }, |
|
|
37 |
# ], |
|
|
38 |
# }, |
|
|
39 |
|
|
|
40 |
{ |
|
|
41 |
"name": "altimet", |
|
|
42 |
"type": "altimet01", |
|
|
43 |
}, |
|
|
44 |
|
|
|
45 |
|
3374 |
kaklik |
46 |
], |
|
|
47 |
) |
|
|
48 |
cfg.initialize() |
|
|
49 |
|
|
|
50 |
gauge = cfg.get_device("altimet") |
|
|
51 |
|
|
|
52 |
|
|
|
53 |
#### Data Logging ################################################### |
|
|
54 |
|
|
|
55 |
try: |
|
|
56 |
with open("temperature.log", "a") as f: |
|
|
57 |
while True: |
3375 |
kaklik |
58 |
sys.stdout.write("Start measurement now? [ENTER]") |
|
|
59 |
sys.stdin.readline() |
3374 |
kaklik |
60 |
(t, p) = gauge.get_tp() |
3375 |
kaklik |
61 |
sys.stdout.write(" Temperature: %.2f Pressure: %d Note: " % (t, p, )) |
|
|
62 |
note = sys.stdin.readline() |
|
|
63 |
f.write("%d\t%s\t%.2f\t%d\t%s\n" % (time.time(), datetime.datetime.now().isoformat(), t, p, note, )) |
3374 |
kaklik |
64 |
sys.stdout.flush() |
|
|
65 |
time.sleep(0.5) |
|
|
66 |
except KeyboardInterrupt: |
|
|
67 |
sys.exit(0) |
|
|
68 |
|