-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleaner.py
More file actions
32 lines (28 loc) · 898 Bytes
/
cleaner.py
File metadata and controls
32 lines (28 loc) · 898 Bytes
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
import sys
import signal
import serial
"""Opening of the serial port"""
try:
# arduino = serial.Serial("/dev/tty.usbmodem14101", 115200)
arduino = serial.Serial("/dev/tty.HC-05-DevB", 115200, timeout = 2)
arduino.flushInput() #This gives the bluetooth a little kick
except:
print('Please check the port')
sys.exit(0)
def main():
print("Cleaning bluetooth data sent from the arduino")
while True:
line = arduino.readline()
if line is not b'':
print(line)
else:
print("Finished cleaning, exiting!")
arduino.close()
break
def signal_handler(sig, frame):
print('Shutting down')
arduino.close() #Otherwise the connection will remain open until a timeout which ties up the /dev/thingamabob
sys.exit(0)
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_handler)
main()