Commit f75d8f02 authored by Cristiano Krug's avatar Cristiano Krug
Browse files

Upload New File

parent 19a4ab25
import warnings
import serial
import serial.tools.list_ports
import time
import csv
import matplotlib
matplotlib.use("tkAgg")
import matplotlib.pyplot as plt
import numpy as np
arduino_ports = [
p.device
for p in serial.tools.list_ports.comports()
if 'CH340' in p.description # may need tweaking
]
if not arduino_ports:
raise IOError("No CH340 found")
if len(arduino_ports) > 1:
warnings.warn('Multiple CH340s found - using the first')
ser = serial.Serial(arduino_ports[0])
plot_window = 60
y_var = np.array(np.zeros([plot_window]))
plt.ion()
fig, ax = plt.subplots()
line, = ax.plot(y_var)
filename = time.strftime("%Y%m%d-%H%M%S")
timezero = time.time()
while True:
try:
ser_bytes = ser.readline()
try:
decoded_bytes = int(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
## decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
## print(decoded_bytes)
print(time.strftime("%Y-%m-%d_%H:%M:%S"), decoded_bytes)
except:
continue
with open(filename + '.csv',"a",newline='') as f:
writer = csv.writer(f,dialect='excel',delimiter=";")
writer.writerow([round((time.time()-timezero)/60, ndigits=2),decoded_bytes])
## writer.writerow([round(time.time()),decoded_bytes])
y_var = np.append(y_var,decoded_bytes)
y_var = y_var[1:plot_window+1]
line.set_ydata(y_var)
ax.relim()
ax.autoscale_view()
fig.canvas.draw()
fig.canvas.flush_events()
except:
print("Keyboard Interrupt")
break
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment