简体   繁体   English

解释传入数据

[英]Interpreting Incoming Data

So I've got two different analog reads from an arduino sending values over to my raspberry pi via serial connection. 因此,我从arduino获得了两个不同的模拟读取,通过串行连接将值发送到我的树莓派。 On my raspberry pi I'm reading the values using python. 在我的树莓派上,我正在使用python读取值。 I"m wanting to store X in an address and Y in another address. How do I pull every other incoming value and store them in separate addresses. X in one and Y in another. The incoming data looks like this: XYXYXY with x and y being some arbitrary values. I'm just looking for some code to grab every other incoming data. This is what im using to read data coming from my arduino. 我想将X存储在一个地址中,将Y存储在另一个地址中。如何提取其他所有传入值并将它们存储在单独的地址中。X分别存储在一个地址中,Y存储在另一个地址中。输入数据如下所示:XYXYXY与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
#...

Thanks so much 非常感谢

Maybe I am missing the point here, but if you want to assign incoming values to alternating variables, then 也许我在这里没有重点,但是如果您想将传入值分配给交替变量,则

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM