-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHub.py
140 lines (109 loc) · 3.21 KB
/
Hub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python3
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
from serial import Serial
import time
import json
ser17 = Serial('/dev/ttyACM0', 9600, timeout=1)
ser2 = Serial('/dev/ttyACM1', 9600, timeout=1)
ser3 = Serial('/dev/ttyACM2', 9600, timeout=1)
interrupt17 = 17
GPIO.setup(interrupt17, GPIO.OUT)
interrupt2 = 2
GPIO.setup(interrupt2, GPIO.OUT)
ser17.flush()
ser2.flush()
while True:
for interrupt, ser in [(interrupt2, ser2), (interrupt17, ser17)]:
for x in [0, 1, 2]:
GPIO.output(interrupt, GPIO.HIGH)
command = 'data' + str(x) + "\n"
ser.write(bytes(command.encode('utf-8')))
pico_data = ser.readline()
pico_data1 = pico_data.decode("utf-8", "ignore")
sensor_response = pico_data1[:-2]
print(sensor_response)
GPIO.output(interrupt, GPIO.LOW)
time.sleep(10)
ser17.flush()
ser2.flush()
data = json.loads(sensor_response)
print("Index: " + str(data["index"]))
print("Average Output: " + str(data["averaged"]))
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
from serial import Serial
import time
import json
ser17 = Serial('/dev/ttyACM0', 9600, timeout=1)
ser2 = Serial('/dev/ttyACM1', 9600, timeout=1)
ser3 = Serial('/dev/ttyACM2', 9600, timeout=1)
interrupt17 = 17
GPIO.setup(interrupt17, GPIO.OUT)
interrupt2 = 2
GPIO.setup(interrupt2, GPIO.OUT)
ser17.flush()
ser2.flush()
GPIO.output(interrupt2, GPIO.HIGH)
command = 'init' + "\n"
ser2.write(bytes(command.encode('utf-8')))
pico_data = ser2.readline()
pico_data1 = pico_data.decode("utf-8", "ignore")
sensor_response = pico_data1[:-2]
print(sensor_response)
GPIO.output(interrupt2, GPIO.LOW)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
from serial import Serial
import time
ser3 = Serial('/dev/ttyACM2', 9600, timeout=1)
interrupt3 = 3
GPIO.setup(interrupt3, GPIO.OUT)
GPIO.output(interrupt3, GPIO.HIGH)
command = "0on" + "\n"
ser3.write(command.encode('utf-8'))
pico_data = ser3.readline()
pico_data1 = pico_data.decode("utf-8", "ignore")
sensor_response = pico_data1[:-2]
print(sensor_response)
GPIO.output(interrupt3, GPIO.LOW)
time.sleep(1)
GPIO.output(interrupt3, GPIO.HIGH)
command = "0off " + "\n"
ser3.write(command.encode('utf-8'))
pico_data = ser3.readline()
pico_data1 = pico_data.decode("utf-8", "ignore")
sensor_response = pico_data1[:-2]
print(sensor_response)
GPIO.output(interrupt3, GPIO.LOW)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
from serial import Serial
import time
ser3 = Serial('/dev/ttyACM0', 9600, timeout=1)
interrupt3 = 3
GPIO.setup(interrupt3, GPIO.OUT)
GPIO.output(interrupt3, GPIO.HIGH)
command = "stat1off" + "\n"
# command = "init"
ser3.write(command.encode('utf-8'))
pico_data = ser3.readline()
pico_data1 = pico_data
sensor_response = pico_data1[:-2]
print(sensor_response)
GPIO.output(interrupt3, GPIO.LOW)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
from serial import Serial
import time
ser3 = Serial('/dev/ttyACM1', 9600, timeout=1)
interrupt3 = 17
GPIO.setup(interrupt3, GPIO.OUT)
GPIO.output(interrupt3, GPIO.HIGH)
command = 'init'+'\n'
ser3.write(command.encode('utf-8'))
pico_data = ser3.readline()
pico_data1 = pico_data
sensor_response = pico_data1[:-2]
print(sensor_response)
GPIO.output(interrupt3, GPIO.LOW)