我想構建一個心電圖。過濾器是建立在udoo中,然後我想在python中繪製信號。但它一直得到這個當我跑我的代碼:Python:ValueError:無法將字符串轉換爲實時浮動數據
ValueError: could not convert string to float.
import serial
import sys
import time
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
# constants
BAUDE_RATE = 9600
ARDUINO_MAX_INT = 2 ** 10
ARDUINO_MAX_VOLTAGE = 3.3
WINDOW_SIZE = 30
MAX_DATA_SIZE = 1024
# declare the Window
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="Arduino Analog Plotter")
win.resize(1000, 600)
# initialize plots
raw_plot = win.addPlot(title="Raw Pin Data")
raw_curve = raw_plot.plot(pen='y')
raw_plot.addLegend()
raw_plot.showGrid(True, True)
raw_plot.setYRange(0, 1200)
raw_plot.setXRange(0, 1024)
# disable auto size of the x-y axis
raw_plot.enableAutoRange('xy', False)
raw_data = np.zeros(1024)
# open serial
ser = serial.Serial('COM10', 115200, timeout=1)
line = pg.InfiniteLine(pos=1024, angle=0, pen=(24, 215, 248))
raw_plot.addItem(line)
ser.flushInput()
def gettemp(ser):
ser.write('t')
ser.flush()
return ser.readline().strip('\r').strip('\n').split(' ').pop(7)
def update():
global raw_data
# open serial port
raw_capture = []
for x in range(WINDOW_SIZE):
sensoroutput=gettemp()
r=sensoroutput
ser.readline().strip('\r').strip('\n').split(' ').pop(7)
raw_capture.append(float(r).pop(7))
raw_data = np.concatenate([raw_data, raw_capture])
# remove first bin to make room for new bin
if len(raw_data) > MAX_DATA_SIZE:
raw_data = raw_data[WINDOW_SIZE:]
# plot data
raw_curve.setData(raw_data)
def savecounter():
ser.close()
import atexit
atexit.register(savecounter)
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
是否有人知道如何解決這一問題?
你在哪一行得到錯誤? –
請發佈確切的堆棧跟蹤/錯誤。該堆棧跟蹤會告訴你遇到問題的代碼行。 – bedwyr