Created
August 16, 2017 19:34
-
-
Save catharsis96/d035513b74a5e42c43864872e2d8a2e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############## | |
## 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