kbalage

Native Xbox controller support for LEGO hubs by Pybricks

Recommended Posts

The @Pybricks team have been working hard to deliver a fantastic update that I've personally been wanting since LEGO introduced the Powered Up system - you can now use an Xbox controller to directly control any creation with a Technic / Mindstorms / Spike Prime / Spike Essential Hub! No need to have an app running all the time, and no need for a smart device to act as a bridge between the controller and the hub. Here is a video showing you the details:

 

Share this post


Link to post
Share on other sites

Oh my God, so it happened! Best news of the year so far :) I was only hoping this to become reality, but they did it, and it seems they did it with style. Seems really well implemented at the first sight, will need to dive into this asap..

Share this post


Link to post
Share on other sites

Very cool! I really appreciated PyBricks support for the Lego Train remote, but an Xbox controller would be far superior! The main catch for me is that PU motors still aren't powerful enough to make the most of this fine control, but it's a very neat option!

Two clarifications, though:

1. The controller support is fully compatible with the Python interface, not just the block one, right?

2. Only Xbox controllers can be used, not generic Bluetooth ones, right?

[Heads over to Ebay looking for cheap previous-generation Xbox controller auctions...]

Edited by 2GodBDGlory

Share this post


Link to post
Share on other sites
38 minutes ago, 2GodBDGlory said:

1. The controller support is fully compatible with the Python interface, not just the block one, right?

That's how I understood it, even saw the Python code for the controller!

38 minutes ago, 2GodBDGlory said:

2. Only Xbox controllers can be used, not generic Bluetooth ones, right?

I just saw in the GitHub discussion (for the development) that it's kind of prepared for supporting more kinds of controllers, but for now the Xbox ones are done and tested, but they will probably add more in the future. They said they'd mainly target mainstream widely accessible ones though, maybe not all kinds of generic ones (the hard part seems to get it to connect smoothly). I'd expect PS controllers next maybe.

Share this post


Link to post
Share on other sites

Cool indeed. What about potential redistribution of the setup for instruction makers? It would make sense to allow some kind of commercial licensing that would require end user to buy the license himself just for a single model that requires the control setup, is best used with it.

Share this post


Link to post
Share on other sites
10 minutes ago, SaperPL said:

Cool indeed. What about potential redistribution of the setup for instruction makers? It would make sense to allow some kind of commercial licensing that would require end user to buy the license himself just for a single model that requires the control setup, is best used with it.

Access to the Python coding interface is free. More samples for LEGO sets will be added to the website, actually anyone can write and share code that can be used with Pybricks and the Xbox controller. MOC makers can also share the code tailored for their creation, and it can be used by anyone going forward. 

57 minutes ago, 2GodBDGlory said:

1. The controller support is fully compatible with the Python interface, not just the block one, right?

2. Only Xbox controllers can be used, not generic Bluetooth ones, right?

Yes, every function is accessible both on the Python interface and the block interface. At the moment only Xbox controllers are supported. Playstation controllers don't support Bluetooth Low Energy, therefore they cannot communicate directly with the hubs. 

Share this post


Link to post
Share on other sites

Yesss. Great news! This should make controlling many motors much easier than with the Powered Up remote. Also the proportional control looks really nice.

Share this post


Link to post
Share on other sites
On 2/16/2024 at 3:17 PM, 2GodBDGlory said:

[Heads over to Ebay looking for cheap previous-generation Xbox controller auctions...]

Compatible:

XBOX One (Revision 2,  ….)

XBOX Series Generation

XBOX Elite 2 Controller

Not compatible:

- First XBOX One (Revision 1)

- First XBOX Elite Controller

 

Edited by Al Ex

Share this post


Link to post
Share on other sites
1 hour ago, Al Ex said:

Compatible:

XBOX One (Revision 2,  ….)

XBOX Series Generation

XBOX Elite 2 Controller

Not compatible:

- First XBOX One (Revision 1)

- First XBOX Elite Controller

 

Good to know, especially for a non-gamer! Thanks!

Share this post


Link to post
Share on other sites

Enjoy, everyone! Many of you have asked for this. This has been a huge addition to the code base, and we're thrilled that we got it working on the Technic Hub eventually. 

And thanks to @kbalage for announcing it to the world!

For details on compatible models and connection procedures, please see this documentation page. See also this Wikipedia controller overview.

Share this post


Link to post
Share on other sites

can i get programs to 42100 and 42131 to controll them with xbox controller?

Share this post


Link to post
Share on other sites

@Pybricks is it possible to connect the XboxController to two hubs at the same time? Or how is it possible to write control programs for sets like 42100? In the video of @kbalage above, you show the Leibherr Crane (42146) in action, which has two hubs, so I am guessing it is possible to make it work somehow. But I tried connecting to two hubs by pressing the pairing button while connected to the first one, and although it does connect to the second one, but then it drops the connection to the first one.. Is there some trick for making this work?

Share this post


Link to post
Share on other sites
Posted (edited)
2 hours ago, gyenesvi said:

@Pybricks is it possible to connect the XboxController to two hubs at the same time? Or how is it possible to write control programs for sets like 42100? In the video of @kbalage above, you show the Leibherr Crane (42146) in action, which has two hubs, so I am guessing it is possible to make it work somehow. But I tried connecting to two hubs by pressing the pairing button while connected to the first one, and although it does connect to the second one, but then it drops the connection to the first one.. Is there some trick for making this work?

pybricks: „As you could see it hinted in the video, it does work with multiple hubs, you can e.g. control the Liebherr crane as well that has 2 hubs.There'll be more publications about the functionality and how it can be used, make sure to follow the Pybricks social channels. There is no limit, so 10 hubs will also work!“

How it works see older code for Liebherr + Lego 88010 remote:

„Put the program on both hubs.
Upon starting the program the hub will search for a remote for 5 seconds, after that it will assume the other hub has the remote, so it will go into bluetooth receiving state.So turn on both hubs, turn on the remote, one hub will connect to the remote, the other will receive commands over bluetooth, it doesnt matter which hub has the remote.“

https://github.com/orgs/pybricks/discussions/1447

 

Edited by Al Ex

Share this post


Link to post
Share on other sites

 

7 hours ago, Al Ex said:

If you read a bit more about that example you will notice that it requires two remotes, one connected to each hub. So not an example of a remote talking to many hubs.

I think you should consider the general rules:

  1. One remote can connect to a single hub at the time
  2. One hub can talk with other or several other hubs

So you can, for instance, connect the remote to one hub and forward some of the commands to other hub(s).

So I think the answer is yes, one remote, either Lego or XBox, can send commands to several hubs, but you have to have it connected to one of the hubs and handle the command forwarding to the other hubs.

Allowing the connection of a remote to several hubs at the same time would arise several confusing issues, like which button is for which hub, etc. Also, most probably, remotes can't be connected to two devices at the same time

Share this post


Link to post
Share on other sites

Indeed, I can see it hinted for the Xbox controller.

7 hours ago, Al Ex said:

How it works see older code for Liebherr + Lego 88010 remote:

Thanks for that older discussion link, interesting, but unfortunately, that does not answer the question, as the latest version of the program in there uses two Lego remotes instead of one Xbox controller (so avoids the problem).

But in general, I know that connecting a controller to one of the hubs and forwarding control commands from there to the other hub is a possibility. I guess this is what @Pybricks was referring to when hinting that it could work with 10 hubs as well. Even for that, there are two technical possibilities: using Pybricks on all hubs and sending commands via broadcasting, or using Pybricks on one of the hubs and controlling the rest via the Lego Wireless Protocol of the original lego firmware. I wonder which solution could work better though when an Xbox controller connection is also present.

But anyway, I first wanted to know if an Xbox controller connection to two hubs is possible at all, as that could be the most direct/simplest solution. If not, we will have to fall back to one of the above two.

14 minutes ago, vascolp said:

So you can, for instance, connect the remote to one hub and forward some of the commands to other hub(s).

I just wrote the same in the meantime you posted :)

14 minutes ago, vascolp said:

Allowing the connection of a remote to several hubs at the same time would arise several confusing issues, like which button is for which hub, etc.

Well I don't think that would be an issue, each hub would have its own program, which could know which controls (buttons/joysticks) to look for, and the two would use a disjoint set.

14 minutes ago, vascolp said:

Also, most probably, remotes can't be connected to two devices at the same time

Might be true for Xbox controller, but I guess in general BT devices can connect to multiple others, just like the phone app can connect to two hubs in the original C+ profiles. Might depend on which one is central / peripheral device, as it may be that one central can connect to multiple peripherals but not the other way round (not sure though). I guess in the case of the phone app, the phone is the central and the hubs are the peripherals. But in case of Pybricks, it may be that the hub is the central and the Xbox controller is the peripheral. Though wonder how the computer connection is solved then, it that also acting as a peripheral?..

Share this post


Link to post
Share on other sites

 

20 minutes ago, gyenesvi said:

Well I don't think that would be an issue, each hub would have its own program, which could know which controls (buttons/joysticks) to look for, and the two would use a disjoint set.

Well, maybe you are right… I probably would not go that way… can be solved with current situation and there are other interesting things to do, like support for other remotes. :classic:  

Share this post


Link to post
Share on other sites
48 minutes ago, vascolp said:

I probably would not go that way… can be solved with current situation

What do you mean? Even if it was possible with the current situation, you would not do it that way? That's exactly what I'm trying to understand; what's possible with the current situation (and how), not proposing a new feature. So that the Pybricks team can work on the remaining FW features while the community can work on control programs for official sets :)

Share this post


Link to post
Share on other sites
3 hours ago, gyenesvi said:

What do you mean? Even if it was possible with the current situation, you would not do it that way? That's exactly what I'm trying to understand; what's possible with the current situation (and how), not proposing a new feature. So that the Pybricks team can work on the remaining FW features while the community can work on control programs for official sets :)

I think that feature is not available in the current version (but I might be wrong). Assuming that, what I am saying is that if I were to decide, I would not prioritize that feature.

I am all for the other features!!! :-)

Share this post


Link to post
Share on other sites
Posted (edited)

Xbox Controller attached Codes:

- Liebherr LR 13000 (42146) + Xbox Controller: 
https://github.com/orgs/pybricks/discussions/1505
(Top hub connects to Xbox controller. Bottom hub receives the control data from the top)

- Audi RS Q e-tron (42160) + Xbox Controller, v.1: https://pybricks.com/projects/sets/tech ... ontroller/

- Transformation Vehicle (42140) + Xbox Controller: https://www.tcm0.tk/2024/02/xbox-blueto ... n-nun.html

- Volvo-Dumper (6x6) (42114) + Xbox Controller: https://github.com/orgs/pybricks/discussions/1466

- Cat® D11 Bulldozer (432131) + Xbox Controller: https://github.com/orgs/pybricks/discussions/1546

Edited by Al Ex

Share this post


Link to post
Share on other sites

Yep, multiple hubs will work via broadcasting. It's already available. Examples coming soon.

Somebody built a scaled up version of the Liebherr crane with at least 7 hubs, which totally works!

This week we are working on stabilizing the current release (no more beta!).

Share this post


Link to post
Share on other sites

To test Pybricks' recent feature of Xbox controller connectivity, I made this small program. After connecting to the controller, it lights up the LED in white when you press one of the buttons, orange when you press a direction on the D-pad, and gradually other colours as you move the sticks or triggers.

You can see the code here: https://github.com/AVCampos/lego-pybricks-xbox-test

The program assumes you're using a Technic hub, but can easily run on other compatible hubs just by changing two lines of code. I hope it's of help for your projects!

Share this post


Link to post
Share on other sites
Posted (edited)

This looks both interesting and as an answer to those who have modified their Liebherr 42146 crane and thus exceed some of the factory settings. However, I am dumber than a post when it comes to the Pybricks system. Nor do I wish to learn programming - in fact at mu age, it probably isn't possible. Thankfully, I see others have already done the programming and all that needs to be done is down load it to the hubs. I have questions though!

Question 1) Downloading to the hubs will overwrite the factory settings. If, in the future one wishes to restore them, can it be done? Would it involve saving the settings externally?
Question 2) As I understand it, I down load the Pybricks' program and the program for the crane to a bluetooth device, such as my phone, then connecting with the crane hubs and load the new program to the hubs. Is this correct?

I am sure I will have more questions, I'm too ignorant on this topic to know to ask them.

EDIT: I have an Xbox controller though I am clueless as to which one it is. :pir_laugh2:

EDIT #2: The program linked to above also has the ability to turn lights on and off. Where does one find the plug needed to plug into the hub, along with wiring information?

Edited by Lego Tom

Share this post


Link to post
Share on other sites
5 minutes ago, Lego Tom said:

If, in the future one wishes to restore them, can it be done

Yes, you can always start the "Bootloader" mode on any hub an reinstall any FW,

7 minutes ago, Lego Tom said:

Would it involve saving the settings externally?

Which settings?

8 minutes ago, Lego Tom said:

Is this correct?

First you load the FW into the hub, and then your application (crane), there is no smartdevice needed

The browser where you do his connects via BT with the hub.

 

Share this post


Link to post
Share on other sites
7 hours ago, Lego Tom said:

Question 1) Downloading to the hubs will overwrite the factory settings. If, in the future one wishes to restore them, can it be done? Would it involve saving the settings externally?

On the Pybricks website, the sample place where you can install Pybricks, you can reinstall the original lego firmware. No need to save anything externally.

7 hours ago, Lego Tom said:


Question 2) As I understand it, I down load the Pybricks' program and the program for the crane to a bluetooth device, such as my phone, then connecting with the crane hubs and load the new program to the hubs. Is this correct?

All you need to to is open the Pybricks website in a BT compatible browser, and you can install firmware and load the programs to the hubs from there.

7 hours ago, Lego Tom said:

The program linked to above also has the ability to turn lights on and off. Where does one find the plug needed to plug into the hub, along with wiring information?

Not sure what plug you mean here? Are you talking about external lights or the one inside the hub? For external lights, you need to buy they PU lights from lego.com, and then just plug it into one of the ports.

As for the programming, it is easier than you would think. You don't need to learn programming in general. It really is just a few lines of code that you need to gather from the examples. It is all about configuring which ports you use for motors / lights, and then telling what action should happen on which input. And Python is really meant to be an easily readable/understandable high level language for people who don't necessarily have deep programming knowledge, that's why it's ideal for this task. So give it a try :)

Share this post


Link to post
Share on other sites
48 minutes ago, gyenesvi said:

On the Pybricks website, the sample place where you can install Pybricks, you can reinstall the original lego firmware. No need to save anything externally.

All you need to to is open the Pybricks website in a BT compatible browser, and you can install firmware and load the programs to the hubs from there.

Not sure what plug you mean here? Are you talking about external lights or the one inside the hub? For external lights, you need to buy they PU lights from lego.com, and then just plug it into one of the ports.

As for the programming, it is easier than you would think. You don't need to learn programming in general. It really is just a few lines of code that you need to gather from the examples. It is all about configuring which ports you use for motors / lights, and then telling what action should happen on which input. And Python is really meant to be an easily readable/understandable high level language for people who don't necessarily have deep programming knowledge, that's why it's ideal for this task. So give it a try :)

Thanks for the reply!  I would like to power the LED lights I have added from one of the hubs, so I need one of the plugs LEGO uses. I also need to know which pins on the plug will give me positive and negative.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.