Line 25... |
Line 25... |
25 |
i2c = { |
25 |
i2c = { |
26 |
"port": port, |
26 |
"port": port, |
27 |
}, |
27 |
}, |
28 |
bus = [ |
28 |
bus = [ |
29 |
{ |
29 |
{ |
30 |
"name": "current_sensor", |
30 |
"name": "current_sensor1", |
31 |
"type": "vcai2c01", |
31 |
"type": "vcai2c01", |
- |
|
32 |
"address": 0x68, |
- |
|
33 |
}, |
- |
|
34 |
{ |
- |
|
35 |
"name": "current_sensor2", |
- |
|
36 |
"type": "vcai2c01", |
- |
|
37 |
"address": 0x6a, |
32 |
}, |
38 |
}, |
33 |
], |
39 |
], |
34 |
) |
40 |
) |
35 |
cfg.initialize() |
41 |
cfg.initialize() |
36 |
|
42 |
|
37 |
print "Current loop sensor example \r\n" |
43 |
print "Current loop sensor example \r\n" |
38 |
print "Time, channel #1, channel #2, channel #3 , channel #4 \r\n" |
44 |
print "Time, channel #1, channel #2, channel #3 , channel #4 \r\n" |
39 |
sensor = cfg.get_device("current_sensor") |
45 |
sensor1 = cfg.get_device("current_sensor1") |
40 |
time.sleep(0.5) |
46 |
time.sleep(0.5) |
41 |
|
47 |
|
42 |
#### Data Logging ################################################### |
48 |
#### Data Logging ################################################### |
43 |
|
49 |
|
44 |
try: |
50 |
try: |
45 |
with open(log_file, "a") as f: |
51 |
with open(log_file, "a") as f: |
46 |
while True: |
52 |
while True: |
47 |
|
53 |
|
48 |
sensor.setADC(channel = 1, gain = 2, sample_rate = 3.75); |
54 |
sensor1.setADC(channel = 1, gain = 2, sample_rate = 3.75); |
49 |
time.sleep(0.5) |
55 |
time.sleep(0.5) |
50 |
channel1 = sensor.readCurrent(); |
56 |
channel1 = sensor1.readCurrent(); |
51 |
|
57 |
|
52 |
sensor.setADC(channel = 2, gain = 1, sample_rate = 15); |
58 |
sensor1.setADC(channel = 2, gain = 1, sample_rate = 15); |
53 |
time.sleep(0.5) |
59 |
time.sleep(0.5) |
54 |
channel2 = sensor.readADC(); |
60 |
channel2 = sensor1.readCurrent(); |
55 |
|
61 |
|
56 |
sensor.setADC(channel = 3, gain = 1, sample_rate = 15); |
62 |
sensor1.setADC(channel = 3, gain = 1, sample_rate = 15); |
57 |
time.sleep(0.5) |
63 |
time.sleep(0.5) |
58 |
channel3 = sensor.readADC(); |
64 |
channel3 = sensor1.readCurrent(); |
59 |
|
65 |
|
60 |
sensor.setADC(channel = 4, gain = 1, sample_rate = 15); |
66 |
sensor1.setADC(channel = 4, gain = 1, sample_rate = 15); |
61 |
time.sleep(0.5) |
67 |
time.sleep(0.5) |
62 |
channel4 = sensor.readADC(); |
68 |
channel4 = sensor1.readCurrent(); |
63 |
|
69 |
|
64 |
sys.stdout.write("%s \t %0.3f \t %0.3f \t %0.3f \t %0.3f \n" % (datetime.datetime.now().isoformat(), channel1, channel2, channel3, channel4)) |
70 |
sys.stdout.write("%s \t %0.3f \t %0.3f \t %0.3f \t %0.3f \n" % (datetime.datetime.now().isoformat(), channel1, channel2, channel3, channel4)) |
65 |
|
71 |
|
66 |
f.write("%d\t%d\t%d\t%d\t%d\n" % (time.time(), channel1, channel2, channel3, channel4)) |
72 |
f.write("%d\t%d\t%d\t%d\t%d\n" % (time.time(), channel1, channel2, channel3, channel4)) |
67 |
f.flush() |
73 |
f.flush() |