Rev Author Line No. Line
3489 kaklik 1 #!/usr/bin/python
2  
3 import time
4 import datetime
5 import sys
6 from pymlab import config
7  
8 #### Script Arguments ###############################################
9  
10 if len(sys.argv) != 2:
11 sys.stderr.write("Invalid number of arguments.\n")
12 sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], ))
13 sys.exit(1)
14  
15 port = eval(sys.argv[1])
16 #### Sensor Configuration ###########################################
17  
18 cfg = config.Config(
19 port = port,
20 bus = [
21 {
22 "name": "counter",
23 "type": "acount02",
24 },
25 ],
26 )
27 cfg.initialize()
28  
29 print "LTS01 temperature sensor module example \r\n"
30 print "Temperature Humidity[%%] \r\n"
31 fcount = cfg.get_device("counter")
32 time.sleep(0.5)
33  
34 #### Data Logging ###################################################
35  
36 tune = 143050000
37 set_freq = 10000000
38  
39 try:
40 while True:
41 now = datetime.datetime.now()
42 if (now.second == 15) or (now.second == 35) or (now.second == 55):
43 frequency = fcount.get_freq()
44 f = open('/sys/bus/i2c/devices/7-0055/frequency', 'a', buffering = 0)
45 # set_freq = set_freq + (tune - frequency)
46  
47 if (tune > frequency):
48 set_freq = set_freq + 1
49 else: set_freq = set_freq - 1
50 f.write(str(int(set_freq)))
51 sys.stdout.write("frequency:" + str(frequency) + "\r\n")
52 f.close()
53  
54 sys.stdout.write("Time:" + str(now.second) + "\r\n")
55 sys.stdout.flush()
56 time.sleep(1)
57 except KeyboardInterrupt:
58 sys.exit(0)