Using an XBOX 360 Controller on RetroPie

By default Raspbian and RetroPie come preinstalled with xpad, this is the system XBOX 360 driver and although it works it doesnt work as well as xboxdrv.  So here is a quick guide on getting xboxdrv setup with RetroPie.  This guide assumes you already have RetroPie installed on your Raspberry Pi.

First thing we need to do is disable xpad, easiest way of doing this is to add the driver to the raspi-blacklist.conf file, to do that run the following command at the terminal or SSH prompt:

sudo nano /etc/modprobe.d/raspi-blacklist.conf

This file didn’t exist for me so don’t be alarmed if a new file is created, in the file add the following text:

blacklist xpad

Now Reboot your Raspberry Pi

sudo reboot

Once the Pi has rebooted download xboxdrv by entering the following command:

sudo apt-get install xboxdrv

Once that has installed we need to configure the driver to load at start up, this page on GitHub was written by the RetroPie creator and is comprehensive enough to get you through but i will try and explain a little more of the steps to make sure it works first time with your emulators.

I used setup 3 (init script) as it apparently uses less CPU and RAM.  Create the file as described on the GitHub page by entering the following command:

sudo nano /etc/init.d/xboxdrv

Copy the code script from here and paste it into the blank script, press CTRL+X and save the file.  Make the script executable and then execute the script to ensure it starts without error by running these two commands:

sudo chmod +x /etc/init.d/xboxdrv

sudo update-rc.d xboxdrv start

Then you need to create a configuration file, here you can tell the system how many controllers to load.  Enter the following command to create the configuration file:

sudo nano /etc/default/xboxdrv

Copy and paste the configuration from the GitHub page, change the value of CONTROLLER_NUM to match how many controllers you want to load, 2 is default.  Save the file by pressing CTRL+X.

CONTROLLER_NUM=2

Ensure your controller is connected and reboot your Pi, once rebooted the controller light should be correctly lit as Player 1.  We can now test so make sure the inputs are working correctly, we do this by installing joystick and running jstest.  Run the following command to install the joystick application:

sudo apt-get install joystick

Once installed run the following command, substituting [0-3] for a single number.  Normally 0 is the first controller but if you are using a keyboard that might get detected as [0] so use [1].

jstest /dev/input/js[0-3]

You should get an output on the screen showing the button assignments, if you press a button the output will change from Off to On.  It is worth making a note of the button assignments because you will need them later when configuring emulators to use the correct buttons.  Here are the default button assignments for the XBOX 360 controller:

A – 4
B -5
X – 6
Y – 7
RB – 9
LB – 8
RT – 11
LT – 10
back – 12
start – 13
dpad-up – 0
dpad-down – 1
dpad-left – 2
dpad-right – 3
Left Thumb Down – 15
Right Thumb Down – 16
Left Thumb Axis Up/Down – Axis 1
Left Thumb Axis Left/Right – Axis 0
Right Thumb Axis Up/Down – Axis 3
Right Thumb Axis Left/Right – Axis 2
Xbox Button – 14

Now we need to configure RetroPie to use the new controller, this will be the default button configuration for emulators that use the RetroArch core.  Emulators that use other cores such as Mupen64Plus will need re-configuring separately.  Before we start we need to ensure that we have read and write permissions on Retroarch config folder, run the following command to change the permissions:

sudo chmod +rw /opt/retropie/configs/all/

Then navigate to the Retroarch emulator core folder

cd /opt/retropie/emulators/retroarch/

Run the configuration script for each controller you want to use, if you are only using 1 controller run the first line, if you are using 2 controllers run both the first and second lines and so on…

./retroarch-joyconfig -o /opt/retropie/configs/all/p1.cfg -p 1 -j 0

./retroarch-joyconfig -o /opt/retropie/configs/all/p2.cfg -p 2 -j 1

./retroarch-joyconfig -o /opt/retropie/configs/all/p3.cfg -p 3 -j 2

./retroarch-joyconfig -o /opt/retropie/configs/all/p4.cfg -p 4 -j 3

Follow the on screen prompts, you will be asked to press each button in sequence.  Doing so will create a map file for each controller, we then need to combine the map file with the Retroarch configuration file so the core knows what buttons to use on your controller.  To do this run the following command to combine the text in the files:

sudo cat /opt/retropie/configs/all/p*.cfg >> /opt/retropie/configs/all/retroarch.cfg

Perform one last reboot and run a game, the buttons should now work however they might be wrong for the emulator you are playing.  To change this you need to take the mapping from the Retroarch.cfg file in the “ALL” folder (global config) and add it to the Retroarch.cfg file of the emulator you are using i.e SNES.   This will allow you to map the original SNES buttons to the XBOX 360 controller buttons giving you the best setup possible.

I will show you have to do that in another guide, i will also show you have to setup the hotkey buttons and how to exit the games and return to the EmulationStation User Interface.

3 Replies to “Using an XBOX 360 Controller on RetroPie”

  1. Just a heads up (from what I’ve found)…. cd /opt/retropie/emulators/retroarch/ gives an error of no such file or directory. You have the capitalize the “r” and “a” so it’d be cd /opt/retropie/emulators/RetroArch/ . From there, I can’t find “./retroarch-joyconfig -o /opt/retropie/configs/all/p1.cfg -p 1 -j 0”. This appears to have been moved to /opt/retropie/emulators/RetroArch/installdir/bin . This is the only place I can find “retroarch-joyconfig”. I’m still struggling with getting the button mappings right, but thought I’d let you know what I’ve run into as your guide has been the most helpful so far, but hasn’t gotten me from A-Z just quite yet. Looking foward to your post on shaders!

    1. Thanks Craig, that directory on my install is in lowercase. Did you install your RetroPie using the RetroPie-Setup.sh script or did you use the Disk Image method? I used the script setup, i wonder if the locations are different depending on the install method?

Leave a Reply

Your email address will not be published. Required fields are marked *