The Linux Journey

Getting Started

- What is Linux?
- Installing Ubuntu

Site Navigation

- Home
- About
- Recent News
- Downloads

Account

- Login
- Register
- Logout

Search



Other Links

free search engine website submission top optimization
Latest News


Use Xbox360 Controller as Joystick
April 3rd, 2008

I've found using an Xbox 360 controller as a joystick to be an awesome convenience. Even if you don't own an Xbox it may be worth going out and buying one of these controllers soley as a computer joystick. It sure is fun being able to start up my favorite emulators, like Mupen64, and being able to play it with my wireless controller. Anyway, enough of my rambling. Lets get to it.

First of all if you plan on using a wireless Xbox 360 controller you are going to need the Xbox 360 Wireless Gaming Receiver for Windows. Don't let the "for Windows" part scare you. I actually use this myself and it works like a charm. Its only around $20, so it won't put too much of a dent on your wallet.

Ok to begin we need to make sure you have the right packages to be able to install the new drivers. Type or copy and paste this command in the terminal:

sudo apt-get install linux-headers-`uname -r` build-essential automake1.9

Basically this command is just checking you have what you need, and if you dont it will install it. It will probably prompt you to enter your password also. Type it in and press Enter. Before we can go get those drivers to make the controller work we're going to need to make a folder to put them in to make things a little easier on us. Go to you home folder and create a new folder called xpad, or simply copy this into the terminal which does the same thing:

cd
mkdir xpad

The 'cd' command takes your home directory and the 'mkdir xpad' command creates a directory called xpad.
Now we need to go to that directory we just made and download the drivers into it. The easiest way to do this is to enter these commands into the terminal:

cd xpad
wget "http://xbox-linux.cvs.sourceforge.net/*checkout*/xbox-linux/kernel-2.6/drivers/usb/input/xpad.c"
wget "http://xbox-linux.cvs.sourceforge.net/*checkout*/xbox-linux/kernel-2.6/drivers/usb/input/xpad.h"


The 'cd xpad' command takes you to the xpad directory we created and the 'wget ...' commands download those files into that directory. The same thing could be accomplished by going to those 2 websites, clicking File->save as, and saving them into your xpad folder.

We still need one more file before we can get our xbox controllers going. This is a Makefile which basically will set things up for us. You are going to have to create this file yourself, so go to your xpad folder, right click, and click Create Document -> empty document. Name this document "Makefile". You can find your xpad folder by clicking on the main menu of the Gnome panel. Its under Places->Home folder, and then double click on the xpad folder. in the Makefile we created you will need to copy this into it:

KERNEL_PATH?=/usr/src/linux-headers-$(shell uname -r)

EXTRA_CFLAGS=-I$(shell pwd)

obj-m:=xpad.o

all:
        $(MAKE) modules -C $(KERNEL_PATH) SUBDIRS=$(shell pwd)

install:
        cp -f xpad.ko /lib/modules/$(shell uname -r)/kernel/drivers/input/joystick



MAKE SURE THE TABS ARE SILL THERE WHEN YOU COPY THIS. The Makefile needs to be formatted exactly as shown here.

Alright hopefully everything has gone to plan so far. Go back to your terminal and make sure you are still in the xpad directory. Just to be sure you can copy this into it:

cd
cd xpad

Almost done! To finish up copy this to the terminal:

make
sudo make install
sudo modprobe -r xpad
sudo depmod -a
sudo modprobe xpad


That will compile the module, intall it, take out the old one if any, and load up the new one. You should now have a working Xbox 360 controller joystick in Linux. If you got an error during any of the steps you probably missed a step. If at any point you restart your computer and it no longer works just run the last 3 commands in the terminal again (the modprobes and depmod).





Comments




Type Your Comment Here. You must be logged in to comment.