Sunday, July 13, 2014

How to use an Xbox 360 wired controller with a Raspberry PI (and/or how to compile a kernel module)


So I asked the question, "How can I get my Raspberry PI to recognize an Xbox 360 wired controller?"

The answer is:
sudo rpi-update

The xpad Linux kernel module is part of 3.12 and above from what I can tell (I haven't really done any research on this).

What really annoyed me was the LED on the controller kept blinking. Apparently there is a compiler flag that xpad.c recognizes that isn't part of the Raspbian xpad (or normal xpad driver).

How to compile the xpad kernel module for a Rapsberry PI

Make sure you are up to date with the kernel:

sudo rpi-update

Download Source Code

This guide was developed off of 3.12.x. Once this is complete and you have rebooted, login, and we can just start from the home directory by downloading the kernel source:

mkdir xpad
tar xvf rpi-3.12.y
cd raspberrypi-linux*
zcat /proc/config.gz >.config
make oldconfig
make modules_prepare

Now, lets download the newest version of xpad:

cd drivers/input/joystick
wget -N

At this point, open the xpad.c in nano or vi and after the lines that start with '#include', add the line:


Save, then quit.

cd ../../..


Let's now compile the makefile for the joystick folder only (you can just run 'make' if you want to compile everything).

make SUBDIRS=scripts/mod
make SUBDIRS=drivers/input/joystick modules

Now if this is complete, we can install the module. There's a couple ways of doing this safely but I'm just going to overwrite the old driver and reboot.

sudo cp drivers/input/joystick/xpad.ko /lib/modules/`uname -r`/kernel/drivers/input/joystick/xpad.ko
sudo reboot

That's it. Plug in your controller and you are good to go.


If you want, there is a joystick test application you can get by running:

sudo apt-get install joystick
jstest /dev/input/js0

Also remember you can remove the ~/xpad directory now that we are done using it.

No comments:

Post a Comment


Ryan Kuhn