Getting the Xbox controller to work with linux, including rumble effect.
This information is current as of Thu Jul 17 08:02:37 CDT 2008.
Edit: Correction: I believe I bought an xbox 360 controller.
Related post: programming joysticks with linux
Here is what I had to do to get my xbox 360 gamepad working with linux.
To start out with, I’m running Fedora core 8, with running kernel 2.6.25.10-47.fc8.
First, here’s what didn’t work:
I plugged the thing in, and saw the xpad driver load (saw it in output of dmesg.) Then, I ran the “jstest” program, and it printed out about 20 lines, then stopped, and no amount of fiddling with the buttons or joysticks on the game pad would make it produce any more output. Hmm.
I have the following kernel development packages installed, which means there are some headers and what not in /usr/src/kernels that allow modules to be compiled.
rpm -qa | grep kernel.devel produces: kernel-devel-2.6.25.9-40.fc8 kernel-devel-2.6.25.10-47.fc8
So, I thought to build a new xpad.ko module from newer source:
After a bit of searching around on the internet, I tried the following:
mkdir xpad_driver cd xpad_driver 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
Create a Makefile with this in it:
obj-m := xpad.o
then:
make -C /usr/src/kernels/2.6.25.10-47.fc8-i686 M=`pwd` modules
Well, it didn’t build.
So then, I downloaded the 2.6.26 kernel from kernel.org, and unpacked it and copied xpad.c and xpad.h from drivers/input/joystick, and tried the make command again:
make -C /usr/src/kernels/2.6.25.10-47.fc8-i686 M=`pwd` modules
this makes xpad.ko
then, as root:
rmmod xpad.ko
(at this point, unplug the joystick)
insmod ./xpad.ko
(at this point plug in the joystick.)
This worked. Yay!
But, now to try force feedback. I got the fftest program. (google for fftest.c, and compile it with “gcc -o fftest fftest.c”)
Then run it as “fftest /dev/input/event0”
No dice. “i/o error.”
Great. Ok, try copying evdev.h and evdev.c from kernel.org’s 2.6.26 tree (from drivers/input/joystick again) and add “evdev”a into the makefile, like:
cat Makefile obj-m := xpad.o evdev.o
Then run the make again:
make -C /usr/src/kernels/2.6.25.10-47.fc8-i686 M=`pwd` modules
Now that produces evdev.ko.
Try to insmod it, but it won’t. Turns out Fedora has the “input” driver statically linked in, so you can’t rmmod it. (Found out by looking at /dev/input/event0, and noticing it had character device major number 13, and then looking in /proc/devices, see that this corresponds to “input”. Try rmmod input, but no luck, it’s statically linked.
Bummer. I guess Fedora core 8 (with their very most recent kernel as of this writing) just really doesn’t have xbox 360 support then. (Edit: this may not be true, see below.)
(Here begins the part where things began working.)
That means time to compile that 2.6.26 kernel.org kernel and see if that works. Copied the .config file from /usr/src/kernels/2.6.25.10-47.fc8-i686/.config and then ran
“make oldconfig”, hitting enter a whole bunch for defaults to new config options, then ran “make menuconfig” and turned off a bunch of hardware I don’t have, then ran “make.” Went shopping (not kidding). The compile takes awhile with redhat’s config file, even considering that I turned off a bunch of stuff.
then (as root) “make modules_install”, and “make install”, then reboot into the new kernel.
Hmm, it still doesn’t seem to work.
At this point, I was stuck for awhile, but then I began running fftest against the various event device nodes…
[root@zuul xpad_driver]# ./fftest /dev/input/event0 Force feedback test program. HOLD FIRMLY YOUR WHEEL OR JOYSTICK TO PREVENT DAMAGES Device /dev/input/event0 opened Axes query: Effects: Number of simultaneous effects: 0 Upload effects[0]: Function not implemented Upload effects[1]: Function not implemented Upload effects[2]: Function not implemented Upload effects[3]: Function not implemented Upload effects[4]: Function not implemented Upload effects[5]: Function not implemented Enter effect number, -1 to exit
No dice. Same thing with event1, event2, event3, event4 but then… hello, what’s this?
root@zuul xpad_driver]# ./fftest /dev/input/event5 Force feedback test program. HOLD FIRMLY YOUR WHEEL OR JOYSTICK TO PREVENT DAMAGES Device /dev/input/event5 opened Axes query: Effects: Periodic Rumble Number of simultaneous effects: 16 Upload effects[1]: Invalid argument Upload effects[2]: Invalid argument Upload effects[3]: Invalid argument Enter effect number, -1 to exit
That’s different… hmm, it didn’t complain about 0, or, 4, or 5…
Enter effect number, -1 to exit 0 Now Playing: Sine vibration Enter effect number, -1 to exit 4 Now Playing: Strong Rumble Enter effect number, -1 to exit 5 Now Playing: Weak Rumble Enter effect number, -1 to exit -1 No such effect [root@zuul xpad_driver]#
Hey hey! It works!
Well, option 0, “Sine vibration” didn’t ever stop, just kept going indefinitely (even exiting the program doesn’t stop it.) But, playing 4, or 5 it rumbles for awhile then stop. 4 seems to be the same as 0, except it stops, and 5 seems to be a higher frequency, lower amplitude version of 4.
On inspecting the fftest code, it seems that it plays effects 4 and 5 for 5 seconds, but the others for 20 seconds for some reason. 20 seconds is a long time. Knowing this, and waiting 20 secs, effect 0 does indeed eventually stop. So… it looks like it’s working. And, knowing that it’s (for some reason) showing up at /dev/input/event5, rather than /dev/input/event0. Hmm, it suddenly occurs to me that maybe event0-4 are the mouse. Maybe that’s mousex, mousey, plus 3 buttons mapped to 0,1,2,3,4… that’d make sense.)
That it showed up on /dev/input/event5 means it’s quite possible that this might actually work with Fedora’s kernel, (well, apart from the xpad driver itself.)
I’ll have to try that… but for now, heck I’ll just stick with this 2.6.26 kernel. There’s nothing like the bleeding edge.





[…] Getting the Xbox controller to work with linux, including rumble effect. « Scary Reasoner – March 11th ( tags: controller linux xbox360 xbox usb driver guide tutorial ) […]
Delicious Bookmarks for March 11th from 16:57 to 18:58 « Lâmôlabs said this on March 12, 2011 at 12:02 am |
Thanks for the article, buddy. I made the darn thing rumble. Know any games that use the rumble though? supertux and tuxracer don’t…
Two games I made, http://wordwarvi.sf.net and http://bethewumpus.sf.net both use the rumble feature.
Greetz,
I tried this, couldn’t make it work:
See, cat /proc/bus/input/devices:
I: Bus=0003 Vendor=046d Product=c29a Version=0111
N: Name=”Driving Force GT”
P: Phys=usb-0000:00:1d.3-1/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0/input/input7
U: Uniq=
H: Handlers=event4 js0
B: EV=1b
B: KEY=1f0000 0 0 0 0 0 0 ffff00000000 0 0 0 0
B: ABS=30007
B: MSC=10
So, I did: linux-dopx:/home/anisha # fftest /dev/input/event4
Force feedback test program.
HOLD FIRMLY YOUR WHEEL OR JOYSTICK TO PREVENT DAMAGES
Device /dev/input/event4 opened
Axes query:
Effects:
Number of simultaneous effects: 0
Upload effects[0]: Function not implemented
Upload effects[1]: Function not implemented
Upload effects[2]: Function not implemented
Upload effects[3]: Function not implemented
Upload effects[4]: Function not implemented
Upload effects[5]: Function not implemented
Enter effect number, -1 to exit
Kernel is: 2.6.34 (64 bit)
Any ideas?
Hmm, you have a “Driving Force GT””, whatever that is, but it’s not an xbox 360 controller.
The driver is reporting back that it supports zero force feedback effects:
“Number of simultaneous effects: 0”
That’s not a good sign.
Hey, I’ve been reading your website for a while.
I already can control my mouse with my PS2 controller which is nice :).
However, fftest doesn’t seem to work with this specific controller, do you know if I can bruteforce it somehow to know how to make it work?
Thanks 🙂
Eh, sorry, don’t know anything about the PS2 controller.
Hi,
nice article great job.
I want to brag that I got USB “PS2-sixAxis”-likish cheap controller and it worked on my Ubuntu 11.10 box.
Just had to use:
$ sudo fftest /dev/input/event6
Now let me figure out how to use that in a program…