mcopy/notes/mcopy_projector_debug.py

26 lines
556 B
Python
Raw Permalink Normal View History

2023-07-02 17:56:03 +00:00
import serial
import time
import serial.tools.list_ports
ports = serial.tools.list_ports.comports()
port = ''
for p in ports:
2023-07-04 00:33:32 +00:00
print(p)
if "Arduino" in p.description or 'ACM0' in p.description:
print("This is an Arduino!")
2023-07-02 17:56:03 +00:00
port = p.device
break
2023-07-04 00:33:32 +00:00
if port == '':
2023-07-02 17:56:03 +00:00
print("Arduino is not connected")
exit(1)
arduino = serial.Serial(port=port, baudrate=57600, timeout=.05)
time.sleep(1)
2023-07-04 00:33:32 +00:00
with open('debug.csv', 'w') as file:
while True: # Or: while ser.inWaiting():
file.write(arduino.readline().decode())
2023-07-02 17:56:03 +00:00