Use a PS3 Controller on Linux (USB)

With Steam recently coming to Linux, and all the great humble bundles, it’s becoming more and more important to have a good gamepad to use on your Linux PC. If you’re a console gamer, you probably already have an XBox 360 or a PS3 controller. In fact, plug in your controller via USB and it probably already works. Unfortunately, many games (Hotline Miami, Super Meat Boy, etc.) assume you have a 360 controller and the button mappings of a PS3 dualshock controller will be horribly skewed (the PS3 select button is 360’s A button). In some games, like Cave Story+, this is not a problem because they allow custom key mappings within the program. A few, like Steam Big Picture, correctly detect the PS3 controller. However, many games just assume a 360 controller, so it simplifies things if you make the dualshock pretend to be a 360 controller. Luckily, there’s a program that does just this: xboxdrv.

Setup

  1. Install the xboxdrv package. Or get it from the source.
    sudo apt-get install xboxdrv
  2. Plug in your PS3 DualShock controller via USB. The LEDs will flash. You should see relevant lines in your /var/log/syslog file (or equivalent, depending on your distribution – I’m using Ubuntu 13.04).
    usb 4-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    usb 4-2: Product: PLAYSTATION(R)3 Controller
    usb 4-2: Manufacturer: Sony
    sony 0003:054C:0268.0008: Fixing up Sony Sixaxis report descriptor
    input: Sony PLAYSTATION(R)3 Controller as /devices/pci0000:00/0000:00:13.2/usb4/4-2/4-2:1.0/input/input18
    sony 0003:054C:0268.0008: input,hiddev0,hidraw0: USB HID v1.11 Joystick [Sony PLAYSTATION(R)3 Controller] on usb-0000:00:13.2-2/input0

    UPDATE 2014-06-23 Start —
    Run ‘dmesg | grep sony‘ in a console and read the latest messages. If you see messages like the following, there’s likely an issue with your kernel:
    sony 0003:054C:0268.0003: can't set operational mode
    sony: probe of 0003:054C:0268.0003 failed with error -38

    The rest of the steps won’t work and they’ll be somewhat silent in their failure. I was using 3.13.0-30-generic on Ubuntu 14.04 (Trusty) when Andrew pointed out this problem in the comments. It is a known problem and I imagine it will get addressed in the next kernel update soon-ish. If you’re impatient, you may be able to roll back to an earlier version (but I’m not sure how far you’d have to go). You may even be able to choose a working earlier version from your boot menu. You could also upgrade to a newer version before it’s officially supported and distributed, if you’re comfortable doing that. I can confirm that 3.13.11-03131104-generic works, as mentioned in the Launchpad bug report.
    UPDATE 2014-06-23 End —

  3. Press the PlayStation button to enable it. The LEDs will continue to flash, but input will now register.
  4. Run xboxdrv.
    sudo xboxdrv --detach-kernel-driver

    You may require one or both of “sudo” and “–detach-kernel-driver” above. If you get a LIBUSB_ERROR_ACCESS error, you’ll have to use sudo. If you get a LIBUSB_ERROR_ACCESS error, you can try the –detach-kernel-driver option.

  5. Play a game!

Other References

26 thoughts on “Use a PS3 Controller on Linux (USB)

  1. I’ve been unsuccessfully messing around with jscal to try to get this working, but your method works perfectly – thanks!!

    For Fedora 18 or 19, just replace step 1 with:
    yum install kernel-modules-extra (this gets you the required joydev kernel module)
    yum –enablerepo=updates-testing install xboxdrv (currently in the Fedora 18 and 19 testing repos, but should be in main soon)
    Reboot to use the new kernel module

    Link the the Fedora package listing: https://admin.fedoraproject.org/updates/xboxdrv

    • Glad it was useful! I went down a similar path as you and wondered why I didn’t encounter this solution before… hence this article. :)

      Thanks for the extra info!

  2. Pingback: LinuxGameCast Weekly EP66 — Right Is Left | Linux Game Cast

    • Hi Damian,
      Just type the following in the terminal: sudo xboxdrv --detach-kernel-driver, and press Enter. Modified the step a little to make that more clear. :)

      • ok i have a rather bizzare problem

        I’ve followed all the steps with no problem and now the computer sees the controller normally (i use xubuntu 14.04). However even when the jstest sees both the axis and buttons, when i press them it nothing happens, it dosen’t repond. In other words I can see the controller but i can’t use it.

        • Hi brb521, I think you’ll have to provide more details on each of the commands and the output for anyone to be able to help you.

          • Here is more of the same issue on Stackoverflow. I have the same thing as brb521. Do you know anything about this?

          • Solidworks,

            Check the comment below, and see if you get similar messages in your syslog. It could be a kernel issue, that can be resolved if you upgrade it or roll it back. I haven’t added any description of this in the main post yet. Will do later.

  3. I can’t seem to get this running in steamOS…

    I get “xboxdrv has no instalation candidate”

    Then when i try to install the PPA i get “add-apt-repository: command not found”

    Then when i try to install “python-software-propertoes” i get “E: Invalid operation python-software-properties. please help

    • Hi Michael,

      If it said invalid operation, maybe you forgot the “install” before the package name?

      I’m not running SteamOS, but it looks like it’s based on Debian Wheezy (stable 7.1), so that might help when looking for information. It looks like you first have to add Debian’s repository to your apt sources. Take a look here for more information, and let me know how it goes.

  4. thanks!!
    I just bought a ps3 controller the other day, and, well, it won’t hurt to also have it working under linux….

  5. Hey man, love the emulator but my problem is, when I upgraded to 14.04 I keep getting this message when I start the emulator and the controller is pretty much useless then. The message goes xboxdrv 0.8.5 – http://pingus.seul.org/~grumbel/xboxdrv/
    Copyright © 2008-2011 Ingo Ruhnke
    Licensed under GNU GPL version 3 or later
    This program comes with ABSOLUTELY NO WARRANTY.
    This is free software, and you are welcome to redistribute it under certain
    conditions; see the file COPYING for details.

    Controller: PLAYSTATION(R)3 Controller
    Vendor/Product: 054c:0268
    USB Path: 003:006
    Controller Type: Playstation 3 USB

    Your Xbox/Xbox360 controller should now be available as:
    /dev/input/js1
    /dev/input/event10

    Press Ctrl-c to quit, use ‘–silent’ to suppress the event output
    I have tried restarting my computer to see if this works and nothing works. Help would be nice, thank you in advance

    • Hi Andrew,

      In fact, I have the same problem, but haven’t used a controller since upgrading to 14.04. The output from syslog that indicates a problem:

      [ 9422.173493] sony 0003:054C:0268.0003: can't set operational mode
      [ 9422.188797] sony: probe of 0003:054C:0268.0003 failed with error -38

      Looks like it’s a problem with the present version of the linux kernel (3.13.0-30-generic) included in 14.04. You can either wait for the next automatically distributed version, try an older version from you boot menu, or upgrade.

  6. Hi there.

    First off, thanks for posting this. When I had a Xubuntu operating system, this worked nearly flawlessly for me (the controller would for some reason occasionally turn off though).

    My question now, however, concerns using this on Bodhi. I installed jstest and followed the instructions on here to install xboxdrv. The issue I’m having doesn’t revolve around either of them recognizing the PS3 or 360 controller. Both programs actually did recognize them.

    The issue I’m having is that xboxdrv is treating it as if I’m holding down one of the buttons the entire time. For ZSNES this didn’t seem to be an issue, and it registered just fine. For Visualboy Advance, however, every time I pressed a button to assign to a spot, it’d appear in another, and then the next I’d press would be assigned to another, and so on. At first I thought it was an issue with just the 360 controller…but then I switched controllers and had an identical problem with the PS3 controller.

    Looking at the teminal, I noticed this particular bit kept going on endlessly for both controllers:
    X1:129 Y1:127 X2:130 Y2:129 du: 0 dd: 0 dl: 0 dr: 0 select:0 ps:0 start:0 L3:0 R3:0 /\:0 O:0 X: 0 [ ]: 0 L1: 0 R1: 0 L2: 0 R2: 0

    Obviously I’m guessing those are the axises going nonstop or something of the like. Any tips on how I can fix this and get both controllers to function normally?

    • Hi Maxwell,

      This is actually the expected behaviour, so it doesn’t appear as anything is wrong. The analog sticks have possible values of 0-255 for both X and Y axes, the center is a dead zone around 128. And in fact, on the Dual Shock 3 controller, almost all of the buttons are analog; try applying different pressures to a button and watch the values change. (Very few games ever used this.)

  7. Pingback: Humble Indie Bundle 12 | Game Imps

  8. Hey there,

    I was wondering if you could help me, I’ve been struggling to get any controller to work properly (due to either drivers or controllers continually drifting to the left).

    When I run ‘sudo xboxdrv –detach-kernel-driver’ it comes up with;

    — [ ERROR ] ——————————————————
    Error couldn’t claim the USB interface: LIBUSB_ERROR_NOT_FOUND
    Try to run ‘rmmod xpad’ and then xboxdrv again or start xboxdrv with the option –detach-kernel-driver.

    I have already unloaded and disabled xpad and I am running it with the –detach-kernel-driver option.

    If I run with out the –detach-kernel-driver option I get;

    — [ ERROR ] ——————————————————
    Error couldn’t claim the USB interface: LIBUSB_ERROR_BUSY
    Try to run ‘rmmod xpad’ and then xboxdrv again or start xboxdrv with the option –detach-kernel-driver.

    Would steam be putting its own driver in the way maybe?

    Thank you for your help so far!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>