I need your help for a problem that i'm dealing with it these days. I can plot a serial data which transfered from my cell phone Bluetooth and received by COM Port of my laptop. In the first glance it seems to be Ok, but at most it can plot every 260 ms (~3 fps). however the cellphone send data every 100 ms. I am pretty sure that the problem stems from "plot" and "figure" command that makes me confused. I appreciate if somebody can correct my code:
from Tkinter import *
import serial
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
ser = serial.Serial("COM4", baudrate=115200, timeout=0.1)
cnt=0
xComponent=[]
plt.ylim(0,30)
while (ser.inWaiting() == 0): # Wait here until there is data
pass
def animate(i):
BluetoothString = ser.readline()
ser.flush()
dataArray = BluetoothString.split(',')
x = float(dataArray[2]) # we only need 3rd component
xComponent.append(x)
print xComponent
ax1.clear()
ax1.plot(xComponent)
plt.ylim(0,25)
global cnt
if (cnt > 16):
xComponent.pop(0)
else:
cnt = cnt + 1
ani = animation.FuncAnimation(fig, animate, interval=0)
plt.show()