3378 |
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 |
|
|
|
14 |
if len(sys.argv) != 2: |
|
|
15 |
sys.stderr.write("Invalid number of arguments.\n") |
|
|
16 |
sys.stderr.write("Usage: %s #I2CPORT\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 |
port = port, |
|
|
26 |
bus = [ |
|
|
27 |
{ |
|
|
28 |
"type": "i2chub", |
|
|
29 |
"address": 0x72, |
|
|
30 |
"children": [ |
|
|
31 |
{ |
|
|
32 |
"type": "i2chub", |
|
|
33 |
"address": 0x70, |
|
|
34 |
"channel": 0, |
|
|
35 |
"children": [ |
|
|
36 |
{"name": "barometer", "type": "altimet01" , "channel": 0, }, |
|
|
37 |
{"name": "hum_temp", "type": "sht25" , "channel": 1, }, |
|
|
38 |
# {"name": "wind_direction", "type": "mag01" , "channel": 1, }, |
3452 |
kaklik |
39 |
# {"name": "thermometer", "type": "lts01" , "channel": 2, }, |
3378 |
kaklik |
40 |
], |
|
|
41 |
}, |
|
|
42 |
# {"name": "barometer2", "type": "altimet01" , "channel": 6, }, |
|
|
43 |
], |
|
|
44 |
}, |
|
|
45 |
], |
|
|
46 |
) |
|
|
47 |
|
|
|
48 |
cfg.initialize() |
|
|
49 |
|
|
|
50 |
barometer = cfg.get_device("barometer") |
|
|
51 |
hum_temp = cfg.get_device("hum_temp") |
|
|
52 |
#wind_direction = cfg.get_device("wind_direction") |
3452 |
kaklik |
53 |
#thermometer = cfg.get_device("thermometer") |
3378 |
kaklik |
54 |
time.sleep(0.5) |
|
|
55 |
|
|
|
56 |
#### Data Logging ################################################### |
|
|
57 |
|
|
|
58 |
filename = datetime.datetime.now().isoformat() |
|
|
59 |
|
|
|
60 |
|
|
|
61 |
try: |
|
|
62 |
with open(filename+".log", "a") as f: |
|
|
63 |
while True: |
|
|
64 |
barometer.route() |
|
|
65 |
(t1, p1) = barometer.get_tp() |
|
|
66 |
hum_temp.route() |
|
|
67 |
t2 = hum_temp.get_temp() |
3452 |
kaklik |
68 |
# t3 = thermometer.get_temp() |
|
|
69 |
t3 = -200 |
3378 |
kaklik |
70 |
h1 = hum_temp.get_hum() |
3379 |
kaklik |
71 |
|
3378 |
kaklik |
72 |
|
3379 |
kaklik |
73 |
sys.stdout.write(" Temperature: %.2f Pressure: %d TempSHT: %.2f HumSHT: %.1f TempLTS: %.2f" % (t1, p1, t2, h1, t3)) |
|
|
74 |
f.write("%d\t%.2f\t%d\t%.2f\t%.1f\t%.2f\n" % (time.time(),t1, p1, t2, h1, t3)) |
3378 |
kaklik |
75 |
sys.stdout.flush() |
|
|
76 |
time.sleep(10) |
|
|
77 |
except KeyboardInterrupt: |
|
|
78 |
sys.exit(0) |
|
|
79 |
|