【发布时间】:2018-12-08 20:25:09
【问题描述】:
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)
我在这里尝试从 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'"的结果?
【问题讨论】:
-
而
ardstr = data.readline().decode('utf8').rstrip()不会给您想要的结果? (或者根据您的其他计划在打印时执行此操作)。
标签: python python-3.x matplotlib arduino-uno