从 Arduino 端完成循环后存储串行值 [英] storing serial value after the loop is done from the Arduino side

查看:34
本文介绍了从 Arduino 端完成循环后存储串行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对下面的链接有类似的问题.

I have similar question with the link below.

如何存储列表(python)中的值是从 arduino 串行来的吗?

他的输出看起来像[2.00]

For his output will look like [2.00]

[2.00,2.64]

[2.00,2.64]

[2.00,2.64,3.28] 等

[2.00,2.64,3.28] etc

所以我想知道在 while true 循环完成后如何使用 [2.00,2.64,3.28].我想使用最后一部分,因为我想从该列表中提取特定索引并使用它.

So I wonder how will be able to use [2.00,2.64,3.28] after the while true loop is done. I want to use that last piece because I want to extract specific index from that list and make use of it.

我希望有人知道答案会有所帮助.

I wish somebody know the answer could help.

格雷格

推荐答案

正如在与您的问题相关的答案中指定的那样:如何将值存储在串行来自arduino的列表(python)中?,代码如下所示.

As it is specified in the answer related to your question: How to store value in list (python) which is coming from arduino serially?, code looks like the following.

import serial
arduino = serial.Serial('COM12', 9600, timeout = .1)
arduino_data = [] # declare a list
while True:
    data = arduino.readline()
    if data:
        arduino_data.append(data) # Append a data to your declared list
        print arduino_data

最后,当while循环完成时,所有数据都被添加到名为arduino_data的列表中.因此,访问 while 循环之外的列表,您就可以实现您想要完成的任何事情.它只是串行打印数据,但最后所有内容都附加到该列表中.

At last, when while loop is done, all data has been appended to the list named arduino_data. Thus, access the list outside the while loop and you may achieve whatever you are trying to accomplish. It is simply printing the data serially, but at last everything is getting appended to that list.

希望能帮到你!

这篇关于从 Arduino 端完成循环后存储串行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆