python - AttributeError: 'str' object has no attribute 'inWaiting' -
from of community able install al new backend matplotlib , run code arduino serial output of python window.
i able make pretty graph , displays, crashes when following error:
attributeerror: 'str' object has no attribute 'inwaiting'
this remedied of @elethan
however, have error:
pulse = float(dataarray[0]) valueerror: not convert string float:
this error not happen everytime
as if wasn't enough, output on plotted graph shows value of 10 of plot, not value output arduino serial.
i unsure why: 1) error intermittend (maybe grabbing ',' , not value) 2) why steady value of 10 when graph plot
the code follows:
import time import serial import matplotlib.pyplot plt import numpy drawnow import * import os,sys pulsearray = [] plt.ion() clippingcounter = 0 # configure serial connections (the parameters differs on device connecting to) ser = serial.serial( port='/dev/ttyacm0', baudrate=115200, parity=serial.parity_odd, stopbits=serial.stopbits_two, bytesize=serial.sevenbits ) ser.isopen() input=1 def plotpulsedata(): plt.ylim(0,120) plt.title('plots data of pulse sensor') plt.grid(true) plt.ylabel('pulse') #plt.subplot(2, 2, 1) plt.plot(pulsearray, 'ro-', label='bpm', linewidth=2) plt.legend(loc='upper left') while true: #first things first, lets wait data prior reading time.sleep(1) if (ser.inwaiting()>4): s = ser.read(4) #print ser dataarray = s.split(',') pulse = float(dataarray[0]) pulsearray.append(pulse) plt.figure(1) drawnow(plotpulsedata) plt.pause(.000001) clippingcounter = clippingcounter + 1 if(clippingcounter>50): pulsearray.pop(0)
any appreciated, thank in advance.
you reassign ser
first time through while loop serial
object string:
ser = ser.read(4)
the next time through loop when call inwaiting()
method on object, error, because calling on string, instead of original serial
object:
ser.inwaiting() > 4
change variable name output of ser.read(4)
name not taken, , error should go away:
s = ser.read(4) ... dataarray = s.split(',')
Comments
Post a Comment