Skip to main content
Bumped by Community user
Bumped by Community user
added 38 characters in body
Source Link
Lightsout
  • 177
  • 5
  • 13

I have 2 programs to test serial communication, an simple arduino program that echoes whatever is on the serial port and a python program that writes to the serial port and prints the reply.

I'm having an issue where whenever I upload the arduino program and try to run the python itcode the arduino code wouldn't workdetect serial available on the first run. I would have to either

  • open and close serial monitor before I run python program
  • run the python program, quit, and run it again

and it would continue to work until I re-upload the arduino then the same thing happens. Does anyone know what is the issue? This is on Ubuntu.

arduino

String str;

void setup() {                
// Turn the Serial Protocol ON
  Serial.begin(115200);
}

void loop() {
  if (Serial.available()) {
      str = Serial.readStringUntil('\n');     // Read the serial input
      Serial.println(str);             // sends ascii code
    
  }
}

Python

import serial


ser = serial.Serial('/dev/ttyACM1', 115200)

for i in range(0,4):
    str = "test string\n"
    ser.write(str)
    print ser.readline()

I have 2 programs to test serial communication, an simple arduino program that echoes whatever is on the serial port and a python program that writes to the serial port and prints the reply.

I'm having an issue where whenever I upload the arduino program and try to run the python it wouldn't work on the first run. I would have to either

  • open and close serial monitor before I run python program
  • run the python program, quit, and run it again

and it would continue to work until I re-upload the arduino then the same thing happens. Does anyone know what is the issue? This is on Ubuntu.

arduino

String str;

void setup() {                
// Turn the Serial Protocol ON
  Serial.begin(115200);
}

void loop() {
  if (Serial.available()) {
      str = Serial.readStringUntil('\n');     // Read the serial input
      Serial.println(str);             // sends ascii code
    
  }
}

Python

import serial


ser = serial.Serial('/dev/ttyACM1', 115200)

for i in range(0,4):
    str = "test string\n"
    ser.write(str)
    print ser.readline()

I have 2 programs to test serial communication, an simple arduino program that echoes whatever is on the serial port and a python program that writes to the serial port and prints the reply.

I'm having an issue where whenever I upload the arduino program and try to run the python code the arduino code wouldn't detect serial available on the first run. I would have to either

  • open and close serial monitor before I run python program
  • run the python program, quit, and run it again

and it would continue to work until I re-upload the arduino then the same thing happens. Does anyone know what is the issue? This is on Ubuntu.

arduino

String str;

void setup() {                
// Turn the Serial Protocol ON
  Serial.begin(115200);
}

void loop() {
  if (Serial.available()) {
      str = Serial.readStringUntil('\n');     // Read the serial input
      Serial.println(str);             // sends ascii code
    
  }
}

Python

import serial


ser = serial.Serial('/dev/ttyACM1', 115200)

for i in range(0,4):
    str = "test string\n"
    ser.write(str)
    print ser.readline()
Source Link
Lightsout
  • 177
  • 5
  • 13

Serial available doesn't work right after upload

I have 2 programs to test serial communication, an simple arduino program that echoes whatever is on the serial port and a python program that writes to the serial port and prints the reply.

I'm having an issue where whenever I upload the arduino program and try to run the python it wouldn't work on the first run. I would have to either

  • open and close serial monitor before I run python program
  • run the python program, quit, and run it again

and it would continue to work until I re-upload the arduino then the same thing happens. Does anyone know what is the issue? This is on Ubuntu.

arduino

String str;

void setup() {                
// Turn the Serial Protocol ON
  Serial.begin(115200);
}

void loop() {
  if (Serial.available()) {
      str = Serial.readStringUntil('\n');     // Read the serial input
      Serial.println(str);             // sends ascii code
    
  }
}

Python

import serial


ser = serial.Serial('/dev/ttyACM1', 115200)

for i in range(0,4):
    str = "test string\n"
    ser.write(str)
    print ser.readline()