解释传入的D

2024-04-27 00:53:06 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有两个不同的模拟读取从一个arduino发送值到我的raspberry pi通过串行连接。在我的raspberry pi上,我正在使用python读取值。我想把X存储在一个地址,把Y存储在另一个地址。如何提取其他传入值并将它们存储在不同的地址中。一个是X,另一个是Y。传入的数据如下所示:X和Y是任意值。我只是在找一些代码来获取所有其他传入的数据。这就是我用来读取来自arduino的数据。你知道吗

import time
import serial


ser = serial.Serial(
    port='/dev/ttyACM0',
    baudrate = 9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
    )


while 1:
    x = ((ser.readline().strip()).decode('utf-8'))
    #y = float(x)*100
    #z = int(y)
    #print (hex(z))
    print(x)


#This is what the incoming data looks like.
#0.01
#0.20
#0.01
#0.20
#...

非常感谢


Tags: 数据代码devimporttimeport地址serial
1条回答
网友
1楼 · 发布于 2024-04-27 00:53:06

也许我没有抓住重点,但是如果你想给交替变量赋值,那么

while True:
    x = (ser.readline().strip()).decode('utf-8')
    y = (ser.readline().strip()).decode('utf-8')
    print(x,y)

相关问题 更多 >