Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial latency? #6

Open
Armandpl opened this issue Dec 12, 2022 · 6 comments
Open

Serial latency? #6

Armandpl opened this issue Dec 12, 2022 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@Armandpl
Copy link

Hello,

I'm curious to know what kind of latency you were getting and with which arduino?

I'm using a similar technique to try and communicate with my rotary inverted pendulum but I'm running into latency issues. It's taking a long time to send the command and get back an answer from the arduino. To be clear I'm not using this specific library but my code is really close.

Using an arduino nano it takes me 15.5 ms to send and then receive 8 bytes from pyserial. Using a nano every it is much faster and takes only 1.5 ms. I'm trying to investigate what's affecting the speed and to figure out if I've made a mistake somewhere.

Cheers

@araffin araffin self-assigned this Dec 14, 2022
@araffin araffin added the question Further information is requested label Dec 14, 2022
@araffin
Copy link
Owner

araffin commented Dec 14, 2022

Hello,
will try to answer a bit longer by this weekend.
In the past I used arduino mega mostly and I remember having ~1-10ms latency (but I'm not sure we checked it closely back then, that was more than 5 years ago ^^").

Using an arduino nano it takes me 15.5 ms to send and then receive 8 bytes from pyserial

so the problem is python?
if so, you might consider going to c++/rust or try to find faster implementation of Serial.read().
(the latency is from the python side, right?)

@Armandpl
Copy link
Author

so the problem is python?

Looks like it's not as the latency varies depending on the arduino. e.g using the arduino nano every and the same code I get 1.5 ms instead of 15.5 ms.

try to find faster implementation of Serial.read()
On the arduino side? How would I go about finding this? any keyword I should search for?

@araffin
Copy link
Owner

araffin commented Dec 20, 2022

You could also debug by mocking the arduino (maybe take a look at python serial tests: https://github.com/pyserial/pyserial/blob/master/test/handlers/protocol_test.py): https://github.com/balp/arduino-mock

Did you had a look at the low_latency_mode option?

See pyserial/pyserial#290

@Armandpl
Copy link
Author

thanks very much I'm going to try that :)

@NaiveInvestigator
Copy link

@Armandpl what was the fix you later on came to settle into? Did 'low_latency_mode' fix the issue for you or something else?

@Armandpl
Copy link
Author

Armandpl commented Oct 7, 2024

@NaiveInvestigator old arduinos e.g the nano have a separate usb serial modem while newer versions such as the nano every have the modem included in the main chip. I don't know why but those are faster. The fix was switching to one of the newer chips, I choose a xiao samd21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants