0

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

Community
  • 1
  • 1
Greg
  • 1
  • 5
  • Possible duplicate of [How to store value in list (python) which is coming from arduino serially?](http://stackoverflow.com/questions/41979340/how-to-store-value-in-list-python-which-is-coming-from-arduino-serially) – abhinav Mar 22 '17 at 04:20
  • Not exactly the same. I am using Adafruit NFC Shield to read NFC data. I got the arduino_data output correctly, but I can not utilize this arduino_data outside the while loop, any suggestions? – Greg Mar 22 '17 at 14:49
  • I narrow this problem down to http://stackoverflow.com/questions/42966263/pyserial-when-it-is-the-end-of-the-line-stop-the-while-loop – Greg Mar 23 '17 at 03:03

1 Answers1

0

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!

Community
  • 1
  • 1
abhinav
  • 1,108
  • 11
  • 23
  • I put the print arduino_data to the same level of while True, then the program no longer working, it won't read anything! I am kind of confused right now. – Greg Mar 22 '17 at 14:45
  • I have a device set up like https://www.dexterindustries.com/Arduberry/example-projects-with-arduberry-and-raspberry-pi/nfc-card-reader/ on arduino I have code set up like success = nfc.mifarreultralight_Readpage(6, data) nfc.PrintHexChar(data,4) success = nfc.mifarreultralight_Readpage(7, data) nfc.PrintHexChar(data,4) while i am running the python program above it will print whatever on page 6 and then print a combination of page 6 and 7, but when I want to utilize the combined information which is why I put arduino_data outside the loop the python program won't read anything anymore. – Greg Mar 22 '17 at 15:49
  • One concern is while true is always running, so the question right now will be once it finish reading how to stop the while true loop/ – Greg Mar 22 '17 at 16:18