import serial import matplotlib.pyplot as plt def add_imu_data(data, accx, accy, accz): try: if len(data) == 3 and data[0] and data[1] and data[2]: accx.append(float(data[0])) accy.append(float(data[1])) accz.append(float(data[2])) except: pass return accx, accy, accz arduino = serial.Serial(port = 'COM10', baudrate = 115200, timeout = 0.1) accx = [] accy = [] accz = [] num_samples = 300 plot_num = 0 while True: try: data = arduino.readline().decode('utf-8').rstrip().split(" ") except: continue if data[0] == "DONE": row = accx row.extend(accy) row.extend(accz) plt.plot(row) plt.show() else: accx, accy, accz = add_imu_data(data, accx, accy, accz)