Rev Author Line No. Line
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")
3376 kaklik 16 sys.stderr.write("Usage: %s #I2CPORT\n" % (sys.argv[0], ))
3374 kaklik 17 sys.exit(1)
18  
19 port = eval(sys.argv[1])
20  
21  
22 #### Sensor Configuration ###########################################
23  
24 cfg = config.Config(
3376 kaklik 25 port = port,
26 bus = [
3375 kaklik 27 {
3376 kaklik 28 "type": "i2chub",
29 "address": 0x72,
30  
31 "children": [
32 {
33 "type": "i2chub",
34 "address": 0x70,
35 "channel": 3,
36 "children": [
37 {"name": "altimet1", "type": "altimet01" , "channel": 0, },
38 {"name": "altimet2", "type": "altimet01" , "channel": 3, },
39 {"name": "altimet3", "type": "altimet01" , "channel": 4, },
40 {"name": "altimet4", "type": "altimet01" , "channel": 5, },
41 {"name": "altimet5", "type": "altimet01" , "channel": 6, },
42 {"name": "altimet6", "type": "altimet01" , "channel": 7, },
43 ],
44 },
45 {"name": "altimet8", "type": "altimet01" , "channel": 6, },
46 ],
3375 kaklik 47 },
48  
3376 kaklik 49 # {
50 # "type": "i2chub",
51 # "address": 0x72,
52 # "children": [
53 # {"name": "altimet", "type": "altimet01" , "channel": 6, },
54 # ],
55 # },
3375 kaklik 56  
3376 kaklik 57  
58 ],
3374 kaklik 59 )
60 cfg.initialize()
61  
3376 kaklik 62 gauge1 = cfg.get_device("altimet1")
63 gauge2 = cfg.get_device("altimet2")
64 gauge3 = cfg.get_device("altimet3")
65 gauge4 = cfg.get_device("altimet4")
66 gauge5 = cfg.get_device("altimet5")
67 gauge6 = cfg.get_device("altimet6")
3374 kaklik 68  
3376 kaklik 69 gauge8 = cfg.get_device("altimet8")
70 time.sleep(0.5)
3374 kaklik 71  
72 #### Data Logging ###################################################
73  
3376 kaklik 74  
3374 kaklik 75 try:
76 with open("temperature.log", "a") as f:
77 while True:
3376 kaklik 78 sys.stdout.write("Start measurement now? [ENTER]")
3375 kaklik 79 sys.stdin.readline()
3376 kaklik 80 gauge1.route()
81 (t1, p1) = gauge1.get_tp()
82 gauge2.route()
83 (t2, p2) = gauge2.get_tp()
84 gauge3.route()
85 (t3, p3) = gauge3.get_tp()
86 gauge4.route()
87 (t4, p4) = gauge4.get_tp()
88 gauge5.route()
89 (t5, p5) = gauge5.get_tp()
90 gauge6.route()
91 (t6, p6) = gauge6.get_tp()
92 # gauge7.route()
93 # (t7, p7) = gauge7.get_tp()
94 gauge8.route()
95 (t8, p8) = gauge8.get_tp()
96  
97 sys.stdout.write(" Temperature: %.2f %.2f %.2f %.2f %.2f %.2f %.2f Pressure: %d %d %d %d %d %d %d Note: " % (t1, t2, t3, t4, t5, t6, t8, p1, p2, p3, p4, p5, p6, p8, ))
3375 kaklik 98 note = sys.stdin.readline()
3376 kaklik 99 f.write("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%s\n" % (time.time(), datetime.datetime.now().isoformat(),t1, t2, t3, t4, t5, t6, t8, p1, p2, p3, p4, p5, p6, p8, note, ))
3374 kaklik 100 sys.stdout.flush()
101 time.sleep(0.5)
102 except KeyboardInterrupt:
103 sys.exit(0)
104