XBOX Controller on RaspberryPi
This post starts where my previous post about creating a Xbox USB controller ended. It’s been a while since I worked on this project so I may have forgotten a few small things but this should be everything that you need. I’m assuming a bit of experience on your behalf for this project so hopefully nothing is overly complicated.
First we need to have our Raspberry Pi hooked up to the internet and accessible. If you are using ssh for the first time with your devi the username should be pi and the password should be raspberry. If you are on windows and don’t have a ssh client I reccomend you download putty. If you are trying to ssh into the raspberry pi but don’t know it’s IP address the easiest way I’ve found is log on to your router and check the ip addresses of the connected machines.
Now on to the fun stuff. First off you will want to install the Xbox controller drivers onto your raspberry pi. If you have your raspberry pi connected to the internet the easiest way to get the drives is to run:
sudo apt-get install xboxdrv
Excellent the first step is complete, were making progress. Now we need to get the ID of of our xbox controller. Make sure your usb controller is plugged in to your Pi and run the following command:
lsusb
Now were looking for an entry that says Microsoft. When I originally ran this I had two entries so I had just tried both of them. The ID of mine was “045e:0283”. Now we have all the information we need to test out the controller and driver functionality. Try running the following command with the ID of your controller replacing mine.
xboxdrv --device-by-id "045e:0283" --type xbox
If everything went well you will get massive outputs on your terminal screen. This is the output of the driver polling your xbox controller for changes. Notice the –type is “xbox” but if you read into the driver documentation you’ll see that this driver supports few other controllers such as a wireless Xbox 360 controlelr and a wired one. I didn’t test those out so it’s up to you to figure out those setups. When you confirm that your setup works you’ll want to put this command in a script and add –silent at the end of the command so the polling outputs don’t show up anymore, they slow the Pi down and are unnecessary. Now you’ll want this script to start up the driver every time you boot your raspberry pi so we will make our script and add it to rc.local. I create a directory called xbox in my home directory and put the script in there but you can put it wherever you want. The script looked like this:
#!/bin/bash
xboxdrv --device-by-id "045e:0283" --type xbox --silent
Dont forget the /bin/bash line as well as the –silent option. If you set your script up like mine you can confirm that your script is functioning with:
sudo sh ~/xbox/script/
There won’t be any output because of the –silent part. Now place the above sudo command into /etc/rc.local to have it run every time your start your raspberry pi up. This is all the steps involved in getting the xbox controller to boot up with your raspberry pi but you will still have to set the controller to work with emulation station. To do this you have to run the retroarch-joyconfig script. By default you should be able to run the following command to change to the directory containing the script:
cd ~/RetroPie/emulators/RetroArch/installdir/bin/
Run the following command to invoke the script and follow the instructions on the screen to map the buttons
./retroarch-joyconfig -o p1.cfg -p 1
This will create a file called p1.cfg for player 1 with the button mapping settings that your entered. You can technically have multiple players if you use wireless controllers but this setup is only 1 player. We want to add the settings in the p1.cfg file to emulationstation’s config file so we can actually use the controller in emulation station so run the following command
sudo cat p1.cfg >> ~/RetroPie/configs/all/retroarch.cfg
This is everything you should need to get the whole project rocking. It seems like a very daunting but it’s not really that bad there’s just a lot of little places that you can go wrong. If you want to add one more level of awesomeness to the project you can buy a wireless USB dongle so that you can access your pi remotely while it’s on. I won’t cover that part here but I will leave you with the links I used to figure the process out.