Wednesday, March 30, 2016

Setting up a Wireless USB controller for use with Retropie

I recently bought a wireless controller called an "Afterglow PS3 controller". When I got home and went to set it up, I was surprised that it wasn't working right away. I first tried the script, which has built in features for setting up a PS3 (and clones), or an xbox controller. Neither of these options worked for me.

Being a pretty Linux savvy guy, I decided to do a little research and set it up manually. Hopefully this walk-through will help others who have the same problem. This procedure might work for most controllers (unverified).

My setup:

Retropie 3.6
Raspberry PI 3
PDP Afterglow PS3 controller

Lets get started...

Note: This entire procedure can be done via SSH (optional), aside from mapping the controller.

1. Detect and identify your controller:

Unplug, and then immediately plug back in, the wireless dongle (or cable) into your USB on your Rapasberry pi.

Run the following command (hit F4 in main menu to access the terminal):
Scroll through the output from dmesg, and see if your controller is listed. (Mine shows as the following):

Awesome, it detects and registers our controller as an input device.

Now we need to blacklist the xpad driver (since it conflicts with xboxdrv, which we will setup later) so the kernel doesn't load it.

2. Verify whether or not xpad is loaded

Run the following command:

We can see that the xpad driver is indeed loaded. (If it is NOT listed here, you can skip step 3, and move directly to step 5).

Lets go ahead and unload it.

Run the following command to unload the xpad driver:
sudo rmmod xpad
3. Blacklist xpad driver via raspi-blacklist.conf file:

Run the following command:
sudo nano /etc/modprobe.d/raspi-blacklist.conf

Add the following text:
blacklist xpad

Save the file and exit the editor (hit Ctrl+o to save, press enter when prompted for filename, and then Ctrl+x to exit)

4. Reboot your pi ("sudo reboot" from the terminal, or "Quit->Reboot System" via main menu)

Once emulationstation is back up and you are in the main menu, press F4 to load the terminal again.

Note: If you run the lsmod command again after you reboot, you should not see xpad loaded at all. If you do, then repeat step 3.

5. Get your controllers "ID"

First, we need to identify the devices vendor:id string, which can be done by doing the following:

 - Unplug your USB dongle (or cable) and run the following command:

Take note of the number of devices listed, and familiarize yourself with their names.

- Now plug your dongle (or cable) back into the Raspberry PI, and run the same command:

As you can see, there is a new device being listed (Known as Logic3 for me). The vendor ID, in my case is "0e6f:1314"
Now lets load up xboxdrv and see if we can get the controller synced, and outputting events.

6. Initialize xboxdrv

xboxdrv should already be installed hopefully. If not, you should be able to install it by running "apt-get install xboxdrv".

Make sure your dongle (or controller) is plugged in, and run the following command (replacing $esp with the string we got from step 5):
sudo xboxdrv --device-by-id $esp --type xbox360

After xboxdrv loads, press some buttons on the controller (You likely need to hit the home, or the sync button first (to connect it) before it'll detect anything).

You should see the following :

As you can see, the controller is now synced, and xboxdrv is processing user input.

Now that the controller is working, we need to configure retropie to autostart xboxdrv.

7. Configure xboxdrv to load at system boot.

We will be editing a file known as rc.local, which will launch xboxdrv for us on each boot.

Edit the file with nano:
sudo nano /etc/rc.local

Add the following text just before the "exit 0" line, using your vendor ID:
xboxdrv --device-by-id 0e6f:1314 --type xbox360 --silent &

Be sure to include the & on the end, so it runs in the background. No need to add sudo on the front, since rc.local is ran as root. --silent tells it to not output anything to the console.

8. Reboot your PI

Once emulationstation loads up, hit the home (sync) button on your controller. It should now be connected and no longer flashing. Now we will map the buttons using the menu options. If it already works for you, awesome!

9. Map the controller

Bring up options, from the main menu (using a keyboard or a working controller) and press "Configure input".

Once it loads, press and hold a button on the controller. It should detect it, and run the button mapping utility.

Follow the prompt and map all of your buttons, as you normally would with any controller.

All done!

Whacky controller bug fix

Update 04/03/16:

I was encountering some issues, namely after I exit a game or when trying to hit select (to insert coins) in mame, every time I first launched a game. Basically it would be holding down the top trigger button for some reason, and spazzing out before, and after I played any game.

To fix this simply set the following, in /boot/config.txt:

I hope this example will help others in getting non official controllers working, with Retropie.

I may be writing others in the future, as I tinker with my RPI, and encounter / resolve issues.


  1. Thanks dude. This just got my after glow working with Ubuntu.

  2. This comment has been removed by the author.