-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_receive.py
28 lines (23 loc) · 886 Bytes
/
serial_receive.py
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
"""
Created on Wed 16 Nov 2022
@author: Zefy Pissaki | [email protected]
"""
import time
import serial # import serial library
from string import digits
results_file = open("data.txt","a")
# get the start time
start_time = time.time()
arduinoSerialData = serial.Serial('com5', 115200)
while (1==1):
if (arduinoSerialData.inWaiting()>0):
# get the runtime
current_time = time.time()
elapsed_time= current_time - start_time # get runtime in seconds
elapsed_time = f"{elapsed_time:.2f}" # limit float precision to 2 decimals
results_file.write( str(elapsed_time) + ',')
myData = arduinoSerialData.readline() # reads everything as a string
myData = myData.decode('utf-8').strip() # decode received data. clean digit string
results_file.write(str(myData)+ '\n')
print (myData)
results_file.close()