Skip to content

Make Technic Hub stay connected to PC when connecting to Xbox Controller - #515

Merged
laurensvalk merged 2 commits into
masterfrom
xbox-connect
Oct 8, 2026
Merged

laurensvalk merged 2 commits into
masterfrom
xbox-connect

Conversation

@laurensvalk

@laurensvalk laurensvalk commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

This fixes a longstanding issue where people could not connect the Technic Hub and the Xbox Controller while connected to their PC.

I could not reproduce it on my PC, but it did happen when using my iPad as the host. I think we finally found it:

When connected to an iPad or many other hosts, pairing with an Xbox controller failed because the Bluetooth chip ran out of memory. The iPad asks to send the hub link layer packets of up to 251 bytes instead of the 27 byte default, so the chip has to keep much larger receive buffers for that connection. Some PCs does not ask for this, which is why the same pairing worked there. Fix it by limiting the data length to 27 bytes in both directions during init.

It works well with my iPad now.

Before we merge this, I'm hoping to get some feedback from people where this failed before. Please try the following script. The light is green when you press something, else red. And blue while still connecting:

from pybricks.hubs import TechnicHub
from pybricks.parameters import Button, Color
from pybricks.tools import wait
from pybricks.iodevices import XboxController

hub = TechnicHub()

xbox = XboxController()

pressed = {}

while True:

    now = xbox.buttons.pressed()
    if now == pressed:
        continue
    pressed = now

    hub.light.on(Color.GREEN if any(pressed) else Color.RED)
    print(pressed)

To confirm that your computer was affected before

We'd need to know this too, or else we don't know if the fix was intended for you. Because before, it would disconnect by default so you would not see the issue.

Run the script above on the current stable or beta firmware, and use xbox = XboxController(stay_connected=True). Then it will attempt to stay connected. On the old firmware, this should cause Xbox Controller to never finish pairing or the hub generally just freezes.


Other side effects. This may magically fix some other memory issues we saw with the CC2640 too 😄

@BertLindeman

Copy link
Copy Markdown
Contributor

Laurens, in your comment above you have xbox = XboxController(stay_connected)
I think it should be xbox = XboxController(stay_connected=True) otherwise NameError: name 'stay_connected' isn't defined

@BertLindeman

Copy link
Copy Markdown
Contributor

Test with firmware:
('technichub', '4.1.0b5', 'ci-build-5071-v4.1.0b5-4-gcf52b5388 on 2026-10-08')

All test had telemetry active, not paused at all.

Before the xbox-ctrl was paired:

Traceback (most recent call last):
  File "PR515_orig.py", line 9, in <module>
OSError: [Errno 1] EPERM: 

Second run: fine 🎉

  • xbox connects and hub stays PC connected.
  • while the hub is powered-on the controller stays hub connected.

Minor breaking:

xbox = XboxController(stay_connected=True)

now gets:

Traceback (most recent call last):
  File "PR515_orig.py", line 8, in <module>
TypeError: extra keyword arguments given

Great improvement of usability of the xbox-controller on the TechnicHub. 🥇

@laurensvalk

Copy link
Copy Markdown
Member Author

Thanks! To confirm, did that set of devices have the issue to begin with, so did it get stuck on the stable firmware with stay_connected=True?

When connected to an iPad or many other hosts, pairing with an Xbox controller failed because the Bluetooth chip ran out of memory. The iPad asks to send the hub link layer packets of up to 251 bytes instead of the 27 byte default, so the chip has to keep much larger receive buffers for that connection. Some PCs does not ask for this, which is why the same pairing worked there.

Fix it by limiting the data length to 27 bytes in both directions during init. This has to be sent before HCI_EXT_setLocalSupportedFeatures(), after which the chip refuses the command but still accepts longer packets. Longer messages are still split up and put back together as before, so the MTU is unchanged.

Large program downloads still load at about the same time.
Disconnecting is no longer needed, so we can drop it to reclaim some space.
@BertLindeman

Copy link
Copy Markdown
Contributor

Thanks! To confirm, did that set of devices have the issue to begin with, so did it get stuck on the stable firmware with stay_connected=True?

On v4.1.0b4 I could not get the xbox controller to even pair with the technichub.
I did not get the rapid blue blinking (with battery-out to power-off) in any test today.

@laurensvalk

Copy link
Copy Markdown
Member Author

Right, so those are being separately fixed. Would be best to test the old Xbox situation on the stable firmware.

Thanks for your patience. Your input it much appreciated.

All updates are being pushed right now. I think we'll put out a beta with these fixes today or tomorrow. Even if there are some issues left, it's good to have Technic and City Hub back to normal.

@laurensvalk
laurensvalk merged commit b0c3558 into master Oct 8, 2026
30 checks passed
@dlech
dlech deleted the xbox-connect branch October 8, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants