-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Micropython BLE has higher latency than Arduino. Is there any way to reduce it? #15418
Comments
Hi and thank you for reporting. Is this the code that you are using? https://github.com/ospanic/MIDI_Boy/blob/master/Kalinmba/main.py - if not, please provide the exact code being used. How much delay do you experience? |
Yes,it is. BLE seems to be able to reduce latency by setting parameters, but the cost is that it will increase the power consumption of the device. Obviously, in the use scenario of BLE MIDI instruments, latency is more important for the device. |
@jd3096-mpy your code has a |
We have a BLE test in Testing this with two PYBD-SFx boards (running either NimBLE or BTstack) the latency of a notification can get down to the minimum of 7.5ms (15ms round trip for two). Testing with an ESP32, it seems the best you can get is 11.5ms, which is still very good. By default the latency is about 50ms. This is all dependent on the connection interval that is negotiated when the two BLE devices connect. And it's the central (the one initiating the connection) that can set the connection interval parameters. @jd3096-mpy your MIDI program is the peripheral. What central are you using to connect to the MIDI peripheral? The central is the one you need to set the connection interval on.
Yes, that's the correct function to use to set the connection interval parameters. But it's for the central, the device initiating the connection (not the MIDI peripheral). In MicroPython it's possible to set the connection interval using ble.gap_connect(addr_type, addr, 5000, 11500, 11500) That will give a connection interval of 11.5ms, which will be the latency of a notify. |
I tested it with just one key program, and I felt that the delay still existed. I am sure that there is no delay in the key reading, because when I used UART wired MIDI, the same program, the delay obviously did not exist. |
First of all, thank you very much for your hard and meticulous testing. |
Thank you for the feedback. I think we can close this issue then. When you have something more to share about your project, then create a post in our Show & Tell on the discussion board: https://github.com/orgs/micropython/discussions/categories/show-and-tell - does not have to be polished - can be work in progress :) Probably there are others interested in BLE MIDI things! |
It would be good to have a working BLE MIDI example in I'll close this then. If it turns out that MicroPython does have latency issues with working BLE MIDI code, please reopen with more details how to reproduce the problem (ie both central and peripheral). |
Description
I tried to use MicroPython's BLE to make a BLE MIDI instrument.
like this
But I found that there was a delay when testing. There was no such feeling when using Arduino or espidf. I want to know where the problem lies. Is there any solution, such as modifying the source code and recompiling the firmware? Will using a function like
esp_ble_gap_set_prefer_conn_params
be effective?Code Size
No response
Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree
The text was updated successfully, but these errors were encountered: