首页 文章

Python将数据从arduino序列分割为raspberry

提问于
浏览
0

我在树莓上有这样的串口arduino的输出

30.27|34.00\n
30.27|32.00\n
30.21|33.00\n

覆盆子上的代码:

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
while 1 :
    ser.readline()

我想吐这样的

x=30.21
y=33.00

如果数据实时发送,这是可能的,

谢谢..

1 回答

  • 1

    使用您已有的相同代码,尝试:

    import serial
    ser = serial.Serial('/dev/ttyACM0', 9600)
    while 1 :
        data=ser.readline()
        x=data.split("|")[0]
        y=data.split("|")[1]
        print "x=",x
        print "y=",y
    

    您可以更简化代码,但希望逐步完成以便于阅读 .

相关问题