안녕하세요, 저는 USB 연결을 통해 arduino와 나무 딸기 파이 사이의 통신을 설정하려고합니다. 그러나 나는 단지 짐작할 수없는 몇 가지 이상한 문제에 직면하고 있습니다. 파이썬 스크립트에서 arduino로 데이터를 보내고 arduino light를 Led로 보내고 싶습니다.왜 나무 딸기 파이와 arduino 사이의 느린 직렬 시작?
편집 *이 문제를 해결했지만 다른 사람에게 도움이되도록 질문을 남깁니다. 문제는 직렬 초기화 시간이었습니다. 아래 참조
파이썬 코드.
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=3)
ser.open()
ser.write('1')
아두 이노 코드
char serialRecieved;
/*output*/
int ledOne=8;
int ledTwo=12;
int ledThree=13;
/*input pins*/
int thermistor=1;
void setup(){
pinMode(ledOne, OUTPUT);
pinMode(ledTwo, OUTPUT);
pinMode(ledThree, OUTPUT);
Serial.begin(9600);
}
void loop(){
if (Serial.available() > 0) {
serialRecieved=Serial.read();
if(serialRecieved=='1'){lightLed(8,1000);}
if(serialRecieved=='2'){lightLed(12, 1000);}
if(serialRecieved=='3'){lightLed(13 , 1000);}
if(serialRecieved=='4'){sendTemp();}
delay(1);
}
}
void lightLed(int led, int time){
digitalWrite(led, HIGH);
delay(time);
digitalWrite(led, LOW);
}
void sendTemp(){
int temp=analogRead(thermistor);
Serial.print(temp);
}
내가 지금까지 나는이 켜져 야 핀 8에 주도하지만, 그렇지 않은 볼 수 파이썬 스크립트를 실행
. 이상한 점은 루프를 실행하면 (아래 코드 참조) 루프의 첫 번째 반복에서 직렬 데이터가 처리되지 않는다는 것 외에는 잘 작동한다는 것입니다.이 스크립트를하지 첫 번째 루프를 제외하고 작동 반복
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=3);
ser.open();
i=0
while i < 5:
ser.write('1')
ser.write('2')
ser.write('3')
ser.write('4')
time.sleep(1)
serial_data = ser.readline()
print("temperature")
print serial_data
i=i+1
사람이 시리얼 데이터의 첫 번째 부분은 손실되거나 읽을 수 없습니다되고있는 중 왜 어떤 아이디어가 있습니까? 그건 그렇고면 이미 파이썬, 리눅스 파이와 arduino, 미안 해요 말할 수 없어 미안 해요!
편집은 문제가 확인
해결 그냥 그것이 파이와 아두 이노 간의 시리얼 연결을 설정하는 데 걸리는 시간 때문, 문제를 발견했다. 누군가가 동일한 문제로 고통 받고 있다면 여기 링크가 있습니다.http://playground.arduino.cc/interfacing/python
지금 난 그냥 시리얼 연결을 전송하고 데이터를 수신 할 준비가되면 알 수있는 방법을 찾아야합니다.