storing serial value after the loop is done from the Arduino side

强颜欢笑 提交于 2019-12-25 09:00:36

问题


I have similar question with the link below.

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

For his output will look like [2.00]

[2.00,2.64]

[2.00,2.64,3.28] etc

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.

Greg


回答1:


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

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.

Hope it helps!



来源:https://stackoverflow.com/questions/42942673/storing-serial-value-after-the-loop-is-done-from-the-arduino-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!