import matplotlib.pyplot as plt import numpy as np import serial import sys # x = np.linspace(0, 6*np.pi, 100) # y = np.sin(x) x = range(100) y = [200, 300]*50 plt.ion() fig = plt.figure() ax = fig.add_subplot(111) line1, = ax.plot(x, y, 'r-') # Returns a tuple of line objects, thus the comma # for phase in np.linspace(0, 10*np.pi, 500): # global path, baseline NX = 500 NY = 500 nloop = 100 path = [] baseline = 0 baseline_filt = 0.01 gain = 5 port = sys.argv[1] ser = serial.Serial(port,9600) while 1: # # idle routine # # look for framing # byte2 = 0 byte3 = 0 byte4 = 0 while 1: byte1 = byte2 byte2 = byte3 byte3 = byte4 byte4 = ord(ser.read()) # print byte1, byte2, byte3, byte4 if ((byte1 == 1) & (byte2 == 2) & (byte3 == 3) & (byte4 == 4)): # print 'ready' break path = [] for i in range(nloop): lo = ord(ser.read()) hi = ord(ser.read()) # print lo, hi reading = 256*hi + lo baseline = baseline_filt*reading + (1-baseline_filt)*baseline value = NY/2 + gain*(reading - baseline) # print value # path.append(i*NY/float(nloop)) #this is just the x coordinate times 5 coz window is 500 and nloop is 100 # path.append(i) path.append(value) print path # line1.set_ydata(np.sin(x + phase)) line1.set_ydata(path) fig.canvas.draw()