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