2017-03-22 8 views
0

아래 링크와 비슷한 질문이 있습니다. 자신의 출력이 [2.00]Arduino 측에서 루프를 수행 한 후 일련 값을 저장합니다.

모양을 들어

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

[2.00,2.64]

[2.00,2.64,3.28] 등

그래서 내가 얼마나 궁금 true loop가 수행 된 후에 [2.00,2.64,3.28]을 사용할 수 있습니다. 그 목록에서 특정 색인을 추출하여 사용하기 때문에 마지막 부분을 사용하고 싶습니다.

누군가가 도움을 줄 수 있으면 좋겠습니다. 그렉

+0

가능한 [순차적으로 arduino에서 오는 목록 (파이썬)에 값을 저장하는 방법?] (http://stackoverflow.com/questions/41979340/how-to-store-value-in-list-python arduino-serial에서 오는) – abhinav

+0

정확히 동일하지는 않습니다. Adafruit NFC Shield를 사용하여 NFC 데이터를 읽습니다. arduino_data 출력을 올바르게 받았지만 while 루프, 제안 사항 밖에서이 arduino_data를 사용할 수 없습니까? – Greg

+0

이 문제를 http://stackoverflow.com/questions/42966263/pyserial-when-it-is-the-end-of-the-line-stop-the-while-loop으로 좁히십시오. – Greg

답변

0

이 질문에 관한 답에 지정된대로

: How to store value in list (python) which is coming from arduino serially?이 코드는 다음과 같습니다. 루프가 수행되는 동안 모든 데이터가 arduino_data 이름 목록에 추가 된 마지막에서

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 루프 밖에서 목록에 액세스하면 달성하고자하는 목표를 달성 할 수 있습니다. 단순히 데이터를 순차적으로 인쇄하는 것이지만 마침내 모든 것이 그 목록에 추가됩니다.

희망 하시겠습니까?

+0

인쇄물을 넣습니다. arduino_data 사실, 프로그램이 더 이상 작동하지 않는 동안, 그것은 아무 것도 읽지 않을 것입니다. 나는 지금 당황 스럽다. – Greg

+0

설명을위한 코드를 게시 할 수 있습니까? – abhinav

+0

나는 arduino에 https://www.dexterindustries.com/Arduberry/example-projects-with-arduberry-and-raspberry-pi/nfc-card-reader/와 같은 장치를 설정했습니다. 코드를 성공과 같이 설정했습니다. nfc.mifarreultralight_Readpage (6, data) nfc.PrintHexChar (data, 4) success = nfc.mifarreultralight_Readpage (7, data) nfc.PrintHexChar (data, 4) 위에 파이썬 프로그램을 실행하는 동안 6 페이지와 6 페이지와 7 페이지의 조합을 인쇄합니다. 그러나 결합 된 정보를 활용하고자 할 때 arduino_data를 루프 외부에 두는 이유는 파이썬 프로그램이 더 이상 아무것도 읽지 않을 것이기 때문입니다. – Greg