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  
14 if len(sys.argv) != 3:
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 address = eval(sys.argv[2])
21  
22  
23 #### Sensor Configuration ###########################################
24  
25 cfg = config.Config(
26 port = 1,
27  
28 bus = [
29 {
30 "type": "i2chub",
31 "address": 0x70,
32  
33 "children": [
34 {
35 "type": "i2chub",
36 "address": 0x70,
37 "channel": 1,
38  
39 },
40 ],
41 },
42 ],
43 )
44 cfg.initialize()
45  
46 gauge = cfg.get_device("altimet")
47  
48  
49 #### Data Logging ###################################################
50  
51 try:
52 with open("temperature.log", "a") as f:
53 while True:
54 (t, p) = gauge.get_tp()
55 #sys.stdout.write(" Temperature: " + str(t) + " Preassure: " + str(p) + "\r\n")
56 sys.stdout.write(" Temperature: %.2f Pressure: %d\n" % (t, p, ))
57 f.write("%d\t%s\t%.2f\t%d\n" % (time.time(), datetime.datetime.now().isoformat(), t, p, ))
58 sys.stdout.flush()
59 time.sleep(0.5)
60 except KeyboardInterrupt:
61 sys.exit(0)
62