Xbox Controller

../_images/xboxcontroller.png

../_images/pybricks_variables_set_xbox_controller.svg

class XboxController

Use the Microsoft® Xbox® controller as a sensor in your projects to control them remotely.

The hub will scan for the controller and connect to it. It will disconnect when the program ends.

For tips on connectivity and pairing, see below.

../_images/pybricks_blockButtonIsPressed_XboxController.svg

buttons.pressed() Set[Button]

Checks which buttons are currently pressed.

Returns:

Set of pressed buttons.

Buttons include:

  • Button.A, Button.B, Button.X, Button.Y.

  • Button.LB and Button.RB (bumpers).

  • Button.LJ and Button.RJ (pressing the joysticks).

  • Button.VIEW, Button.MENU, Button.GUIDE (the Xbox logo), and Button.UPLOAD.

  • Button.P1, Button.P2, Button.P3, and Button.P4 (Elite Series 2 only). Pressing the paddles may also be detected as other button presses, depending on the currently active profile.

../_images/pybricks_blockJoystickValue_lj_x.svg

../_images/pybricks_blockJoystickValue_lj_y.svg

joystick_left() Tuple

Gets the left joystick position as percentages between -100% and 100%. The center position is (0, 0).

Returns:

Tuple of X (horizontal) and Y (vertical) position.

../_images/pybricks_blockJoystickValue_rj_x.svg

../_images/pybricks_blockJoystickValue_rj_y.svg

joystick_right() Tuple

Gets the right joystick position as percentages between -100% and 100%. The center position is (0, 0).

Returns:

Tuple of X (horizontal) and Y (vertical) position.

../_images/pybricks_blockJoystickValue_lt.svg

../_images/pybricks_blockJoystickValue_rt.svg

triggers() Tuple

Gets the left and right trigger positions as percentages between 0% and 100%.

Returns:

Tuple of left and right trigger positions.

../_images/pybricks_blockJoystickValue_dpad.svg

dpad() int

Gets the direction-pad position. 1 is up, 2 is up-right, 3 is right, 4 is down-right, 5 is down, 6 is down-left, 7 is left, 8 is up-left, and 0 is not pressed.

Returns:

Direction-pad position.

../_images/pybricks_blockJoystickValue_profile.svg

profile() int

Gets the current profile of the controller. Only available on the Xbox Elite Controller Series 2.

Returns:

Profile number.

Xbox Controller Pairing Instructions

The first time you use a controller with a hub, you will need to pair them: Turn the controller on and then press and hold the pairing button on the back of the controller for a few seconds. When you release it, the Xbox button starts flashing more rapidly. Then start your program.

When pairing and the connection is succesful, the Xbox button will stop flashing and stay on for as long as the program is running.

Repeat Connections

If you keep using the same controller with the same hub, you can simply turn the controller on the next time and the hub will connect to it automatically when your program with this class runs.

The Xbox controller only accepts this simpler connection with the most recently connected device. So if you connect to your Xbox console again, or connect to another hub, you will need to pair them again as described above.

Compatible Controllers

All Xbox controllers released since 2016 are compatible. This includes the controller from the One S (1708 from 2016), the Elite Series 2 (1797 from 2019), and the Series X/S (1914 from 2020), which is the latest model as of this writing.

See also this overview of model numbers including pictures of each controller.

Updating the Xbox Controller

If you frequently use the Xbox Controller with your console, your controller is probably already up to date. If you have not used it for a while or if you bought one recently, you may need to update it.

To update the controller without a console, you can use the Xbox Accessories app on a Windows computer. You can download it from the Microsoft Store. Connect the controller via USB to the computer and follow the instructions in the app to click on “Update now”.

Technic Hub Limitations

Due to limitations of the Technic Hub, the hub will disconnect from the computer when searching for the Xbox controller. This means you will not be able to see output from the print command. Also, you’ll have to connect to the computer again if you want to change your program.