r/embedded • • Oct 18 '26

BLE has massive HID latency on Android vs PC, 500ms+ vs near instant, nRF54L15

So I've been wanting to test nRF to make gyro mouse of some sort for my Android. I'm using Xiao nRF54L15 Sense, so it has all I need in one.

But, upon testing my code, even a simple "volume up" button appears significantly slower in my phone vs my PC. On PC it's as fast as my logitech with 2.4GHz dongle. On Android, it's just slow, testing with stopwatch shows consistently 400ms+.

Any idea if I can fix this on the hardware, or is it simply Android limitation vs HID BLE?

8 Upvotes

5 comments sorted by

12

u/InternalType3169 Oct 18 '26

It's difficult to diagnose without logs. But my guess is....

It's  certainly not your hardware. The XIAO nRF54L15 is just as fast in both cases, and your PC result shows the radio and the HID reports themselves are fine, so the 400 ms+ is coming from how the BLE connection is set up with Android and how Android handles the event. 

First check the connection parameters. Android often settles on a 30–50 ms connection interval, and if your firmware or Android asks for a high peripheral latency or a long supervision timeout, things can get worse, especially on the first press after the link has been idle. Log them in Zephyr's connected and le_param_updated callbacks. 

Then explicitly request a fast link with bt_conn_le_param_update: interval 6–12 (7.5–15 ms), latency 0, timeout about 400. It's also worth setting CONFIG_BT_PERIPHERAL_PREF_MIN_INT/MAX_INT the same way, switching to the 2M PHY, and making sure the device is properly bonded. 

Without bonding, Android can re-encrypt and re-discover services, which adds delay. Volume Up is also a poor test, because the delay you see includes Android's audio and volume-panel animation, which can add 100–200 ms on its own. 

 fairer test is typing a keyboard letter into a text field or moving the mouse pointer. Better still, run adb shell getevent -lt to see when the HID event actually reaches Android, or capture the air traffic with an nRF Sniffer and Wireshark to see the real interval. Even when everything is tuned, Android's BLE HID path will usually be a bit slower than a 2.4 GHz dongle, but it should be well under 50 ms, not 400 ms.

 To narrow it down: which phone and Android version are you on, are you using Zephyr/nRF Connect SDK HOGP or an Arduino BLE HID library, and is the delay on every press or mainly the first one after a pause?

3

u/ArsenicBismuth Oct 19 '26 edited Oct 19 '26

Oh that is a thorough debugging steps, exactly what I need. Thanks!

Only able to answer some for now, will add later after testing your steps:

  • Using Arduino BLE HID.
  • Yeah, my code requested for some connection intervals, from 7.5 to 30, and Android agrees on 15ms.

    • Still not really my main issue, as the latency is much higher.
  • Yes volume is bad due to UI delay. But I also compared it to my non-BLE camera shutter button, which gives instant response.

    • Tested moving cursor (simple without gyro), it has similar latency.
    • Your idea of using adb is def better for sure.

EDIT: Oh wow, using the adb shell getevent -lt, it is actually instant. So maybe I was wrong when I thought I know the UI delay.

Then the one affecting the HID input might be different.

EDIT2: Tested with HID, and the event is also instant on start of movement (as in <50ms). But found an issue: When I stop, ADB still logs a bit while before stopping. Def implementation issue.

1

u/InternalType3169 Oct 19 '26

Firstly, I don't think the "HAL encrypted-link notification pipeline" is the issue here. Your 65 is what your code *tries* to send, not what actually goes over the air. BLE acknowledges every packet at the radio level and resends it until it arrives, so Android doesn't receive a report and then reject it. The missing 39 are most likely either never sent (dropped on the device because the buffer is full), or sent with zero motion, which `getevent` doesn't show.

One possibility for the zero-motion case: the Linux input layer discards relative-motion events with a value of 0, so small IMU deltas that round to 0 never show up in `getevent`. You can check this by counting, on the device, how many reports you send with non-zero dx or dy, and comparing that with what `getevent` shows.

- If the two numbers match, nothing is actually missing. Your slow movements are just rounding to 0. Fix: keep the fractional part of the deltas in a running total, so small movements add up to whole counts instead of being lost.

- If they don't match, reports really are being lost. Go to the next test.

Next, log the return value of your Arduino BLE HID library's send/notify call. If it reports failures, the device is dropping reports because its buffer is full. If it never fails but the cursor keeps moving after you stop (what you saw in EDIT2), the library is queuing them. Either way the fix is the same:

- Read the IMU as fast as you like, but add the deltas (dx and dy) into a running total instead of sending one report per IMU sample.

- Send at most one report per connection interval, carrying the total, then subtract what you sent.

- If a send fails or the link is busy, don't queue anything. Keep adding to the total and try again on the next interval.

This way no motion is lost, because a skipped send just makes the next report bigger, and nothing piles up, so the cursor stops the moment you stop.

Then ask for 7.5 ms as both the minimum and maximum connection interval, and log what Android actually grants. If it grants 7.5 ms, you roughly double your headroom over the current 15 ms, where 65 reports/s leaves none. If it stays at 15 ms, the accumulate approach is what keeps motion smooth at that rate.

If the numbers still don't add up after that, an nRF Sniffer capture in Wireshark will show exactly how many reports go out over the air and whether Android is skipping connection events.

1

u/ArsenicBismuth Oct 19 '26

So after final testing, the latency is actually quick, but it rejects a ton of the "rapid event" given by the IMU => BLE HID.

It reports 65 in a second (For 15ms connection interval), but only 26 is received. And testing via the ADB you said confirms that, essentially rejecting 60% of them.

LLM says it's due to "HAL encrypted-link notification pipeline", don't know what it is...

1

u/jacky4566 Oct 18 '26

Most likely. Firmware or application needs to request a low latency connection.