How to use an Xbox or PS4 controller with a Raspberry Pi

How to use an Xbox or PS4 controller with a Raspberry Pi

Videogames in the 1980s were quite different from the latest crop of frag -'em- till- you're- dead point-and-shoot games. They were tastefully crafted 8- bit graphical masterpieces, with an intense storylines and gameplay that kept you engrossed for hours.

If reading this makes you feel nostalgic, you can emulate the golden era of gaming consoles on your modern hardware and escape back to that golden era.

The quad-core Raspberry Pi 3 has enough numbercrunching power to recreate the video game consoles of yesteryear virtually. Most of the software that creates the defunct platforms is available as open source software, which you can install on top of a Raspbian distribution (distro).

However, the easiest way to start playing vintage games on the Raspberry Pi is to install the purpose-made RetroPie distro, which packs a bundle of emulators.

We have an indepth guide to turning your Raspberry Pi into a retro games console, which will go through all the steps, but we will also quickly show you how to get RetroPie working here, before attaching a games console controller to your Raspberry Pi.

How to use an Xbox or PS4 controller with a Raspberry Pi

Just to be on the safe side, try playing games with the default clock speeds, before you try to overclock the Raspberry Pi

You can manually install RetroPie on top of an existing Raspbian distro but it's more convenient to use the pre-baked image. In addition to Raspberry Pi 3, the distro works with the older models as well, so make sure you grab the correct image.

You need to transfer this image to at least a 4GB card, either using the dd command in Linux, such as

$ dd if=retropie-rpi2.img of=/dev/sdd

You also need a USB keyboard and mouse for some initial setup that you can't do remotely via SSH. We'll also hook up a compatible Wi-Fi adaptor to the Raspberry Pi, which won't work straight out of the box, but we'll get to that later.

Most important of all, make sure you grab some gaming controllers to enjoy the games to the hilt, and RetroPie can work with various controllers, from cheap no-names ones to PS4 controllers and Xbox One controllers.

Once you've prepared the memory card with the RetroPie image, insert it into the Raspberry Pi, connect the controller, the Wi-Fi adaptor, the speakers and the USB input devices, hook it up to your HDMI monitor, and power it up.

How to use an Xbox or PS4 controller with a Raspberry Pi

If you want to, you can make changes to the splash screen using the RetroPie-Setup script

The Raspberry Pi boots directly into Emulation Station, which is the graphical interface it uses to enable you to switch between emulators. The interface asks you to configure the controller. However, before we do that, we have to tweak a couple of settings.

Press the F4 key on the keyboard to exit the Emulation Station, then head to XTerminal.

Basic setup

The first order of business is to expand the image to take over the entire card. In order to do this, bring up Raspbian's configuration utility with

$ sudo raspi-config

and select the first option to expand the filesystem. Once that's done, head to the second option to change the default password for the pi user.

Next up, head to the Advanced Options and select the SSH option to enable remote access. To ensure you use the maximum memory for gaming, head to the Memory Split option. If you're using a Raspberry Pi 3 or Raspberry Pi 2, allocate 512 to the GPU.

Users of the older B+ model should earmark 256. Finally, scroll down to the Overclock option, where users of the Raspberry Pi 2 should select the Pi2 option. Once you've made all the changes, head back to the main menu and select 'Finish' to restart the Raspberry Pi and save changes.

When you're back up again, press F4 once more to exit out of Emulation Station. We'll now get the Wi-Fi adaptor to work. Open the configuration file with:

$ sudo nano /etc/network/interfaces

and then change its contents to resemble the following:

Make sure you replace the text in the wpa-ssid line with the SSID and password for your Wi-Fi network. Press Ctrl+X to save the file and exit the text editor. Now reboot the Raspberry Pi with sudo reboot . Once it comes back up, your Wi-Fi adaptor connects you to your router.

From this point on, you can do the configuration remotely from another computer. Exit Emulation Station yet again and make a note of the IP address RetroPie has been assigned by your router.

Assuming it's 192.168.3.111, you can now log in to it from another computer with sudo ssh pi@192.168.3.111 .

Irrespective of how you're accessing the Raspberry Pi, the next order of business is to tweak some RetroPie-related settings. Change into the RetroPie-Setup directory with

$ cd /RetroPie-Setup

and execute the configuration script with

$ sudo ./retropie_setup.sh

The script fetches any required packages that are missing from your installation. When it's ready, the script displays an Ncurses-based menu. First up, scroll down to the second-to-last option, which updates the RetroPie-Setup script itself.

Once it's done, re-launch the script and scroll down to the third option, labelled Setup/Configuration. In here, scroll down and select '323', which makes the necessary changes to display the RetroPie configuration menu in Emulation Station.

This helps you make changes to the distro without heading back to the command line. Now, depending on your audio gear and how it's connected to the Raspberry Pi, you might need to handhold RetroPie before it can send audio output correctly.

Select option '301' to configure the audio settings. If the default auto option isn't playing any sound, scroll down and select the output to which your speakers are connected. The menu also gives you the option to bring up the mixer to adjust the volume.

Mayank Sharma

With almost two decades of writing and reporting on Linux, Mayank Sharma would like everyone to think he’s TechRadar Pro’s expert on the topic. Of course, he’s just as interested in other computing topics, particularly cybersecurity, cloud, containers, and coding.