Mar-28-2018, 07:07 AM
I am trying to read the output of MPU6050 connected to Arduino using Python so that I could do vibration measurement of the motor. I am able to split and also convert the string to float and get all 6 values (Ax,Ay,Az,Gx,Gy,Gz) but I'm not able to plot it using matplotlib and also the code also stops executing with some errors like:
ValueError: could not convert string to float: '1.01.05\r\n'
or
IndexError: list index out of range
ValueError: could not convert string to float: '1.01.05\r\n'
or
IndexError: list index out of range
import serial import matplotlib.pyplot as ply import numpy import pylab as py from drawnow import * ACCX=[] ACCY=[] ACCZ=[] GYRX=[] GYRY=[] GYRZ=[] arduinodata=serial.Serial('COM3',9600) #port name and baud rate ply.ion() def makeplotting(): ply.ylabel('ACCX (°/sec)') ply.xlabel('Time') ply.plot(ACCX) while True: while(arduinodata.inWaiting()==0): pass arduinostring=arduinodata.readline() arduinostring=str(arduinostring,encoding="utf-8") dataArray=arduinostring.split(',') accxtemp=float(dataArray[0]) ACCX.append(accxtemp) drawnow(makeplotting)