Serial communication with two devices

Hi, I’m trying to use jetson as companion computer on Drone.
I have to use all of USB ports eventhough UART pin headers.
My problem came with arduino. When I tried to communicate with Arduino by using pyserial.
These are my code.

Arduino
int LED = 3;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
while(Serial.available()>0){
int integer = Serial.parseInt();
if(integer==1){
digitalWrite(3, HIGH);
delay(1000);
}
digitalWrite(3,LOW);
}

python3 serial_test.py
import serial
ser = serial.Serial(‘/dev/ttyACM0’, 9600)
ser.write(b’1’)

As you know there is no problem, but I couldn’t see blinked LED but RX light was blinked when I wrote ‘1’.
So I tried with console like
image

then It worked well…Is there any reason about it? I wanna know specific reasons. and I have to command from script not console.
Thank you

I found the reason…
The script doesn’t have time for connecting. So I add time.sleep(2), then it works well…!
but time.sleep(1.5) can’t work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.