Skip to content

Instantly share code, notes, and snippets.

@catharsis96
Created August 16, 2017 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catharsis96/d035513b74a5e42c43864872e2d8a2e7 to your computer and use it in GitHub Desktop.
Save catharsis96/d035513b74a5e42c43864872e2d8a2e7 to your computer and use it in GitHub Desktop.
##############
## Script listens to serial port and writes contents into a file
##############
## requires pySerial to be installed
import serial
serial_port = '/dev/cu.usbmodem1411';
baud_rate = 115200; #In arduino, Serial.begin(baud_rate)
write_to_file_path = "output.txt";
output_file = open(write_to_file_path, "w+");
ser = serial.Serial(serial_port, baud_rate)
while True:
line = ser.readline();
line = line.decode("utf-8") #ser.readline returns a binary, convert to string
print(line);
output_file.write(line);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment