Rev Author Line No. Line
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, },
39 ],
40 },
41 # {"name": "barometer2", "type": "altimet01" , "channel": 6, },
42 ],
43 },
44 ],
45 )
46  
47 cfg.initialize()
48  
49 barometer = cfg.get_device("barometer")
50 hum_temp = cfg.get_device("hum_temp")
51 #wind_direction = cfg.get_device("wind_direction")
52 time.sleep(0.5)
53  
54 #### Data Logging ###################################################
55  
56 filename = datetime.datetime.now().isoformat()
57  
58  
59 try:
60 with open(filename+".log", "a") as f:
61 while True:
62 barometer.route()
63 (t1, p1) = barometer.get_tp()
64 hum_temp.route()
65 t2 = hum_temp.get_temp()
66 h1 = hum_temp.get_hum()
67  
68 sys.stdout.write(" Temperature: %.2f Pressure: %d TempSHT: %.2f HumSHT: %.1f " % (t1, p1, t2, h1,))
69 f.write("%d\t%.2f\t%d\t%.2f\t%.1f\n" % (time.time(),t1, p1, t2, h1,))
70 sys.stdout.flush()
71 time.sleep(10)
72 except KeyboardInterrupt:
73 sys.exit(0)
74