How To Use Playstation and Xbox Controllers With Raspberry Pi

Raspberry Pi Xbox PlayStation
(Image credit: Tom's Hardware)

Playing games on your Raspberry Pi is far easier with a good game controller. Many different game controllers can be connected to your Raspberry Pi using USB. Furthermore, some well-known console controllers can also be linked up using Bluetooth.

In theory, all controllers should work with any Raspberry Pi projects. This covers everything from generic USB joypads to the latest Bluetooth devices. So, you can expect to be able to connect an Xbox One controller and a PS4 controller to your Raspberry Pi. Controllers designed for the PlayStation 3 and Xbox 360 will also work, as will Nintendo gamepads. 

Own a PlayStation 5? The new Sony console features a major revision of the much-loved game controller. But despite being fresh out of the box in 2020, the PS5 controller will easily connect to a Raspberry Pi over Bluetooth, just like its predecessor. Meanwhile, Xbox Series S and X controllers are backward compatible, and can be used on an Xbox One console. The new controller design should also work with the Raspberry Pi.

In this tutorial, we’ll look at what you need to do to connect the most widely used game controllers to a Raspberry Pi: those intended for the Xbox One, PS4, Xbox 360 and PS3 consoles.

Connecting the Xbox One Controller Via USB to Raspberry Pi

The Xbox One boasts one of the most popular game controllers available. Also compatible with PC games, this is a well-designed, multi-purpose controller that can be easily connected to a Raspberry Pi, either using USB or Bluetooth.

1. Update and upgrade the software on your Raspberry Pi.

sudo apt update
sudo apt upgrade

2. Connect the controller and launch a game such as Minecraft Pi Edition, which comes preloaded when you install Raspberry Pi OS with all the recommended software. If you can move your character with the controller then everything is ready to go. If not, go to the next step.

3. Install the Xbox One driver and then reboot your Raspberry Pi.

sudo apt install xboxdrv

4. Open your game and test that you can move around.

Connecting the Xbox One / Playstation 4 and 5 Controller Via Bluetooth

Using a wireless Xbox One controller with the Raspberry Pi is a little more complicated. Two types of wireless Xbox One controller have been released. One uses wireless, while the second requires Bluetooth. How can you tell which is which?

If you have the 1697 wireless model, you’ll need to connect the official Microsoft Xbox Wireless Adapter to your Raspberry Pi. This is a standard USB dongle that should work out of the box. Simply hold the pairing buttons on the adapter and the Xbox One controller to sync, then start playing.

To Connect the Xbox One Bluetooth Controller

1. Update and upgrade the software on your Raspberry Pi.

sudo apt update
sudo apt upgrade

2. Install the Xbox One driver.

sudo apt install xboxdrv

3. Disable ERTM (Enhanced Re-Transmission Mode). While enabled, this Bluetooth feature blocks syncing between the Xbox One controller and your Raspberry Pi.

echo ‘options bluetooth disable_ertm=Y’ | sudo tee -a /etc/modprobe.d/bluetooth.conf

4. Reboot your Raspberry Pi.

5. Open a terminal and start the bluetooth control tool.

sudo bluetoothctl

6. At the [Bluetooth]# prompt, enable the agent and set it as default.

agent on
default-agent

7. Power up the Xbox One controller and hold the sync button. At the [Bluetooth]# prompt, scan for devices.

scan on

(Image credit: Tom's Hardware)

The MAC address should appear, comprising six pairs of letters and numbers followed by “Xbox Wireless Controller.”

8. Use the MAC address to connect the Xbox controller.

connect [YOUR MAC ADDRESS]

9. To save time for future connections, use the trust command to automatically connect.

trust [YOUR MAC ADDRESS]

Connecting an Xbox 360 Controller to Raspberry Pi 

(Image credit: Tom's Hardware)

If you don’t have more recent controllers (or the budget to buy them), it might be easier for you to grab a controller from an older generation of consoles, such as the Xbox 360, or PS3. 

1. Update and upgrade the software on your Raspberry Pi. 

sudo apt update
sudo apt upgrade

2. Install the Xbox One driver

sudo apt install xboxdrv

3. Connect your controller via USB and it should just work. Wireless controllers will require a dedicated wireless receiver (the type that is developed for PC use). 

Connecting a Playstation 3 Controller to Raspberry Pi 

Connecting a Playstation 3 controller via USB is straightforward, but Bluetooth access requires some compiling.

1. Update and upgrade the software on your Raspberry Pi. 

sudo apt update
sudo apt upgrade

2. Install the libusb-dev software. This ensures the PS3 can communicate with the Raspberry Pi over Bluetooth. 

sudo apt install libusb-dev

3. Create a folder for the sixpair software, switch to that folder, and download the sixpair.c software

mkdir ~/sixpair
cd ~/sixpair
wget http://www.pabr.org/sixlinux/sixpair.c

4. Compile the code with gcc.

gcc -o sixpair sixpair.c -lusb

5. Connect the controller to the Pi using its USB cable and run sixpair to configure the Bluetooth connection.

sudo ~/sixpair/sixpair

6. Take note of the MAC code, then disconnect the PS3 controller.

7. Open a terminal and start the bluetooth control tool.

sudo bluetoothctl

8. At the [Bluetooth]# prompt, enable the agent and set it as default.

agent on
default-agent

9. Power up the Playstation 3 controller and hold the sync button. In the [Bluetooth]# prompt scan for devices.

scan on

10. The MAC address should appear, comprising six pairs of letters and numbers. Look for your Playstation 3 controller’s MAC address. Use the MAC address to connect the controller.

connect [YOUR MAC ADDRESS]

11. To save time for future connections, use the trust command to automatically connect.

trust [YOUR MAC ADDRESS]

For other Bluetooth controllers, meanwhile, generic connections should work. This means that anything – smartphone game controllers, for example – can conceivably be connected using bluetoothctl , but some calibration may be required.

Whatever device you’re using, you may need to test it. To do this, simply use the testing tool in the Linux joystick utility.

sudo apt install joystick

To test your gamepad, ensure that it is connected and run the jstest command to check that each button is registered.

sudo jstest /dev/input/js0

This article originally appeared in an issue of Linux Format magazine.