Line 24... |
Line 24... |
24 |
}, |
24 |
}, |
25 |
], |
25 |
], |
26 |
) |
26 |
) |
27 |
cfg.initialize() |
27 |
cfg.initialize() |
28 |
|
28 |
|
29 |
print "LTS01 temperature sensor module example \r\n" |
29 |
print "Frequency counter readout example \r\n" |
30 |
print "Temperature Humidity[%%] \r\n" |
- |
|
31 |
fcount = cfg.get_device("counter") |
30 |
fcount = cfg.get_device("counter") |
32 |
time.sleep(0.5) |
31 |
time.sleep(0.5) |
- |
|
32 |
frequency = fcount.get_freq() |
33 |
|
33 |
|
34 |
#### Data Logging ################################################### |
34 |
#### Data Logging ################################################### |
35 |
|
35 |
|
36 |
tune = 143050000 |
- |
|
37 |
set_freq = 10000000 |
- |
|
38 |
|
- |
|
39 |
try: |
36 |
try: |
- |
|
37 |
with open("temperature.log", "a") as f: |
40 |
while True: |
38 |
while True: |
41 |
now = datetime.datetime.now() |
39 |
now = datetime.datetime.now() |
42 |
if (now.second == 15) or (now.second == 35) or (now.second == 55): |
40 |
if (now.second == 15) or (now.second == 35) or (now.second == 55): |
43 |
frequency = fcount.get_freq() |
41 |
frequency = fcount.get_freq() |
44 |
f = open('/sys/bus/i2c/devices/7-0055/frequency', 'a', buffering = 0) |
- |
|
45 |
# set_freq = set_freq + (tune - frequency) |
42 |
now = datetime.datetime.now() |
46 |
|
43 |
|
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") |
44 |
sys.stdout.write("frequency: " + str(frequency) + " Hz Time: " + str(now.second) + "\r") |
52 |
f.close() |
45 |
f.write("%d\t%s\t%.3f\n" % (time.time(), datetime.datetime.now().isoformat(), frequency)) |
53 |
|
46 |
|
54 |
sys.stdout.write("Time:" + str(now.second) + "\r\n") |
- |
|
55 |
sys.stdout.flush() |
47 |
sys.stdout.flush() |
56 |
time.sleep(1) |
48 |
time.sleep(1) |
57 |
except KeyboardInterrupt: |
49 |
except KeyboardInterrupt: |
- |
|
50 |
sys.stdout.write("\r\n") |
58 |
sys.exit(0) |
51 |
sys.exit(0) |
- |
|
52 |
f.close() |