How to speed up data transmission from RP to arduino using usb

Hi people,

my boud rate is 115200 and i want to keep it that way.
i did a test and i found that since i write something to the serial port via Raspberry Pi it tooks 1 sec to get some data back, for example:

start_time = time.time()
ser.write(str(input_from_user).encode())

///arduino just recive a number and send it back//

ser.readline().decode('utf=8').rstrip()
finish_time = time.time()

finish_time - start_time = 1
what can i do to speed this up?

Possibly something to do with the Arduino code.

This Simple Python - Arduino demo may give you some ideas.

The Python code should work on Windows if you edit it to use the Windows style of COM ports.

I am not aware of any unwanted delay in my Python-Arduino communications.

…R

Hey all,
i dont think i have a problem with my codes.. check them out:

Raspberry Pi's code:

if name== 'main':

ser = serial.Serial('/dev/ttyACM0', 1000000. timeout = 3)
ser.flush()
time.sleep(0.5)

while 1:
time_1 = time.time()

ser.write(str(input_from_user).encode())
ser.readline().decode('utf=8').rstrip()

time_2 = time.time()
print(time_2 - time_1)

Arduino code:

void setup() {
Serial.begin(1000000);
}
void loop() {
if (Serial.available() > 0) {
String data_1= Serial.readStringUntil('\n');

int data = data_1.toInt();
Serial.println(data);

}
}

it tooks 1 sec to get some data back, for example:

 String data_1= Serial.readStringUntil('\n');

The default timeout for the readStringUntil() function is 1 second.

Are you aware of the potential memory problems that use of the String class can cause? See the evils of Strings.

The serial input basics tutorial shows how to avoid the use of the String class.

guyelm:
i dont think i have a problem with my codes.. check them out:

Do you have a problem with the code in the link in Reply #2 - I know it works.

...R

guyelm:
Hi people,

my boud rate is 115200 and i want to keep it that way.
i did a test and i found that since i write something to the serial port via Raspberry Pi it tooks 1 sec to get some data back, for example:

what can i do to speed this up?

you could dramatically speed up the transmission upon transmitting integers instead of text.
A bit tweaking on the python side to force data into integers, but WAYS more efficient...

RIN67630:
you could dramatically speed up the transmission upon transmitting integers instead of text.
A bit tweaking on the python side to force data into integers, but WAYS more efficient…

i will check it out, thanks!

groundFungus:

 String data_1= Serial.readStringUntil('\n');

The default timeout for the readStringUntil() function is 1 second.

Thank you, thats fix it!