arduino python超声波电脑鼠标_在arduino和matplotlib pyqt上使用超声波传感器实时显示图形...

我坚持我的密码。我想在PyQt5上有GUI来显示我的图形。我在matplot中有工作代码,但不能将其转换为PyQT。我是个初学者。我试图找到类似的代码,但我只做了这个。这在matplotlib上有效,但我希望在我的GUI上有它。在import serial

import numpy

import matplotlib.pyplot as plt

from drawnow import *

distance =[]

arduinoData=serial.Serial('COM4',115200)

plt.ion()

cnt=0

def makeFig():

plt.ylim(2,20)

plt.title('Plot ')

plt.grid(True)

plt.ylabel('Distance cm')

plt.plot(distance, 'ro-', label='Distance ')

plt.legend(loc='upper left')

while True: # While loop that loops forever

while (arduinoData.inWaiting()==0): #Wait here until there is data

pass #do nothing

arduinoString = arduinoData.readline() #read the line of text from the serial port

measurement = int(arduinoString) #Convert first element to floating number and put in measurement

distance.append(measurement) #Build our distance array by appending temp readings

drawnow(makeFig) #Call drawnow to update our live graph

plt.pause(.000001) #Pause Briefly. Important to keep drawnow from crashing

cnt=cnt+1

if(cnt>50): #If you have 50 or more points, delete the first one from the array

distance.pop(0) #This allows us to just see the last 50 data points

#This allows us to just see the last 50 data points

我的PyQt和Matplot。我想点击按钮显示这个图表。

我在第51行,在图中有一个错误

测量值=int(arduinoString)

ValueError:以10为基数的int()的文本无效:b'\n'“和

“后端TkAgg是交互式后端。打开交互模式。“

我从我的传感器发送简单距离的数据,比如5,10等等。在

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值