问题
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