【问题标题】:storing serial value after the loop is done from the Arduino side从Arduino端完成循环后存储序列值
【发布时间】:2017-03-22 04:18:37
【问题描述】:

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

How to store value in list (python) which is coming from arduino serially?

因为他的输出看起来像 [2.00]

[2.00,2.64]

[2.00,2.64,3.28] 等

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

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

格雷格

【问题讨论】:

标签: python arduino-uno pyserial


【解决方案1】:

正如在与您的问题相关的答案中指定的那样:How to store value in list (python) which is coming from arduino serially?,代码如下所示。

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 循环之外的列表,您可以实现您想要完成的任何事情。它只是串行打印数据,但最后所有内容都被附加到该列表中。

希望对你有帮助!

【讨论】:

  • 我把 print arduino_data 设置为 while True 的同一级别,然后程序不再工作,它不会读取任何内容!我现在有点困惑。
  • 我在 arduino 上设置了类似 dexterindustries.com/Arduberry/… 的设备 我设置了类似 success = nfc.mifarreultralight_Readpage(6, data) nfc.PrintHexChar(data,4) success = nfc.mifarreultralight_Readpage( 7, data) nfc.PrintHexChar(data,4) 当我运行上面的python程序时,它将打印第6页上的任何内容,然后打印第6页和第7页的组合,但是当我想利用组合信息时,这就是为什么我将 arduino_data 放在循环之外,python 程序将不再读取任何内容。
  • 一个问题是 while true 总是在运行,所以现在的问题是一旦读完如何停止 while true 循环/
猜你喜欢
  • 2016-11-05
  • 1970-01-01
  • 1970-01-01
  • 2020-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多