import serial
import numpy
import matplotlib.pyplot as plt
from drawnow import *
data = serial.Serial('com3',115200)
while True:
while (data.inWaiting() == 0):
pass
ardstr = data.readline()
print (ardstr)
Run Code Online (Sandbox Code Playgroud)
在这里,我试图从arduino获取数据,但它是以格式输入的b'29.20\r\n'。我想要以格式显示数据,"29.20"以便对其进行绘制。
我尝试过ardstr = str(ardstr).strip('\r\n'),ardstr.decode('UTF-8')
但没有一个在工作。我的python版本是3.4.3。
我该怎么做才能得到结果"29.40"而不是"b'29.20\r\n'"?