So with some more work, I've got it writing to a text file (and also print to Arduino serial monitor for troubleshooting purposes) at the rate I'd like. I'm running the attached python script through Command Prompt while running data through Arduino serial.
My current issue is that it is writing b'' on repeat instead of a number for each line. I originally had
data = float(ser_bytes) but that would end the program, so I changed it to data = str(ser_bytes), which now writes but writes the wrong thing.
Has anyone seen this b'' thing before? Any ideas for how to remedy this problem and have it write my data to the text file?
import serial
ser = serial.Serial('COM5', 9600, timeout=0)
ser.flushInput()
output_file = None
START = True
write_counter = 0
close_counter = 0
while True:
try:
ser_bytes = ser.readline()
data = str(ser_bytes)
if START == True:
output_file = open("output.txt", "a+")
if write_counter % 40000 == 0:
output_file.write(str(data) + "\n")
print(data)
START = False
if close_counter % 100 == 0:
output_file.close()
START = True
write_counter += 1
close_counter += 1
except:
print("Keyboard Interrupt")
break