Setup PS3 controller over bluetooth on Ubuntu

The PS3 Sixaxis and DualShock3 bluetooth controllers are a great for gaming on your PS3 but will work just as well under Linux. With this guide you will be able to configure them to work on your Ubuntu Linux 8.10 (Intrepid Ibex) PC in USB as well as wireless bluetooth mode.

There are a variety of solutions out there but they are either overly complex, or because of the ever changing state of Linux bluetooth support, they are somewhat outdated. The advantage of this solution is that it is simple, and requires only slight modification to the default versions of the bluez-utils packages (bluez-4.12). This minimizes possible conflicts and eliminates unneeded configuration.

This guide specifically covers Ubuntu Linux 8.10 (Intrepid Ibex) but I’m sure similar steps can be taken for other distributions.

Installation

Install the hidd daemon located in the bluez-compat package.

$ sudo apt-get bluez-compat joystick

The hidd daemon in the bluez-compat package has been deprecated but it provides the only way to connect with the PS3 controller. It will not interfere with the current bluetooth service.

From this point you can take one of two roads.

  1. If you are on 32bit (i386) or 64bit (amd64) versions of Ubuntu I have precompiled all the binaries you will need. Simply download the corresponding tarball for your architecture and follow a couple simple steps to complete the setup.
  2. The other option is to manually patch and compile the binaries yourself. This is a bit more time consuming but not anymore difficult as I have documented the exact steps for this method as well. This option is necessary if you are on some other architecture (PowerPC, etc.) or if you experience any problems with the precompiled binaries I provided.

Option 1: Download Precompiled Binaries

You can test which architecture you are using by running uname.

$ uname -a
Linux xps 2.6.27-7-generic #1 SMP Tue Nov 4 19:33:06 UTC 2008 x86_64 GNU/Linux

Download the tarball of binaries which corresponds to your architecture.
bluez-compat_ps3_amd64.tgz
bluez-compat_ps3_i386.tgz

Untar the files.

$ tar xzvf bluez-compat_ps3_<arch>.tgz
bluez-compat_4.12-0ubuntu5_amd64.deb
sixpair

Skip down to the Install the Updated Package section.

Option 2: Patch and Compile Binaries

Download the hidd daemon patch:
patch-hidd-3.19-pabr3

Install the dpkg-dev and fakeroot which will allow you to compile the blues-utils package.

$ sudo apt-get dpkg-dev fakeroot

Install the blues-utils package, apply the patch, and build the package.

$ sudo apt-get source bluez-utils
$ sudo apt-get build-dep bluez-utils
$ patch bluez-4.12/compat/hidd.c patch-hidd-3.19-pabr3
$ cd bluez-4.12
$ sudo dpkg-buildpackage -rfakeroot
$ cd ../

This will build all the bluez related packages, the only one we are interested in is bluez-compat.

Download the sixpair.c source code:
sixpair.c

Install the libusb-dev and libusb-0.1-4 which will allow you to compile the sixpair utility.

$ sudo apt-get libusb-dev libusb-0.1-4

Build the sixpair utility.

$ gcc -o sixpair sixpair.c -lusb

Install the Updated Package

At this point you should have either downloaded or compiled the bluez-compat package.

Install the patched bluez-compat package.

$ sudo dpkg -i bluez-compat_4.12-0ubuntu5_<arch>.deb

Optional: if you will dist-upgrade your system, the process will overwrite your modified package with newer versions. You can either choose to redo the above steps every time a new version of bluez-utils is packaged, or “hold” the package. This should work with both apt and aptitude.

$ sudo echo bluez-compat hold | sudo dpkg --set-selections

Bluetooth Pairing

With the updated package in place, you can now follow steps will get the PS3 controller paired with your Ubuntu system. This step only needs to be performed once as it will remain successfully paired with Ubuntu between uses. If you reconnect/re-pair the controller with the PS3 however, you will have to repeat this step.

If you want to setup multiple controllers, repeat this step for each one individually.

Run the following command to view the system log messages as they are generated.

$ watch -n 1 "tail /var/log/messages"

Plug in PS3 controller with USB cable. You should see output similar to the following system log in the terminal.

Apr  4 11:06:40 xps kernel: [ 9666.789711] input: Sony PLAYSTATION(R)3 Controller as /devices/pci0000:00/0000:00:1d.0/usb5/5-2/5-2:1.0/input/input23
Apr  4 11:06:40 xps kernel: [ 9666.834506] input,hiddev96,hidraw3: USB HID v1.11 Joystick [Sony PLAYSTATION(R)3 Controller] on usb-0000:00:1d.0-2

The lights will blink indicating that the controller is communicating with the system.

Press the PS button (clear button in the center of the gamepad). This will acknowledge the controller connection sequence and the controller will become activated.

Check that the /dev/input/js0 device exists at this point.

$ls /dev/input/js*
/dev/input/js0

You can test the controller by running either of the following commands. jscalibrator opens a GUI window and allows you you calibrate your buttons. jstest shows the raw output from the buttons themselves. Make sure you have pressed the PS button on the controller if you aren’t getting any response.

$ jscalibrator -d /dev/input/js0

or

$ jstest /dev/input/js0

The lights will continue to blink indefinitely as long as the controller is connected, this is normal. There is no way at this point to disable them but the controller will operate correctly over USB.

Execute the sixpair utility. This will tell the PS3 controller to look for your Ubuntu bluetooth master device and not the PS3 itself when it attempts to connect over bluetooth.

$ sudo ./sixpair
Current Bluetooth master: 00:1f:e1:e3:48:YY
Setting master bd_addr to 00:1f:e1:e3:48:YY

You should now disconnect the controller from the USB cable. It will remain paired with the Ubuntu system from this point forward.

Initiate Connection

By now you should have installed the updated package and successfully paired the PS3 controller with your Ubuntu system. Until you reconnect/re-pair the controller to the PS3 you can simply repeat this step each time you want to use your controller.

For the controller to successfully connect with your Ubuntu system you will have to temporarily disable the default bluetooth service and start the hidd daemon instead.

Stop the bluetooth service.

$ sudo /etc/init.d/bluetooth stop

Run the hidd daemon. The ‘-n‘ will stop it from running in the background and you can see its output in the terminal.

$ sudo hidd --server --nocheck -n
hidd[14407]: Bluetooth HID daemon

In a separate terminal run the hcidump command below. It will show you the current bluetooth traffic as it happens.

$ sudo hcidump -t -V -x

Press the PS button (clear button in the center of the gamepad). This will cause the controller to begin its connection sequence. You should see the hidd daemon accept the connection and print something similar to the output below. Pay attention to the bold text below. This is your bluetooth PS3 controller address which you will need later to ultimately disconnect the controller.

hidd[13149]: New HID device 00:16:FE:D7:8C:XX (Sony Computer Entertainment Wireless Controller)

The system log should also show the following.

Apr  4 11:09:52 xps kernel: [ 6258.750437] input: Sony Computer Entertainment Wireless Controller as /devices/pci0000:00/0000:00:1d.2/usb7/7-2/7-2.1/7-2.1:1./bluetooth/hci0/hci0:11/input22

hcidump should start reporting a large amount of bluetooth traffic from the PS3 controller. Here’s a snippet of the sample output below.

2009-04-04 11:10:04.745725 > ACL data: handle 11 flags 0x02 dlen 54
    L2CAP(d): cid 0x0041 len 50 [psm 19]
      HIDP: Data: Input report
      01 00 00 00 00 00 86 88 78 79 00 00 00 00 00 00 00 00 00 00
      00 00 00 00 00 00 00 00 00 03 05 14 FF C8 00 00 23 5E 77 01
      81 01 FE 01 E8 01 8F 00 02
2009-04-04 11:10:04.757745 > ACL data: handle 11 flags 0x02 dlen 54
    L2CAP(d): cid 0x0041 len 50 [psm 19]
      HIDP: Data: Input report
      01 00 00 00 00 00 86 88 78 79 00 00 00 00 00 00 00 00 00 00
      00 00 00 00 00 00 00 00 00 03 05 14 FF C8 00 00 23 5E 77 01
      81 01 FE 01 E7 01 8F 00 02

Check that the /dev/input/js0 device exists once again.

$ls /dev/input/js*
/dev/input/js0

You can verify the controller is correctly working over bluetooth by once again running either jscalibrator or jstest.

$ jscalibrator -d /dev/input/js0

or

$ jstest /dev/input/js0

Congratulations! You have successfully connected your PS3 controller. As before, the lights will continue to blink as long as the controller is connected. You can operate the controller and map its buttons just like any other joystick or gamepad.

If you are wanting to connect multiple controllers that were successfully paired in the previous step, press the PS button for each one. You should see that a device (/dev/input/js*) is created for each one.

Kill the hidd daemon by pressing Ctrl+C in the terminal window. You no longer need this as the the PS3 controller is now connected.

You can now restart the bluetooth service to resume the normal operation of bluetooth devices on your system. The controller will continue to operate normally.

$ sudo /etc/init.d/bluetooth start

Terminate Connection

The PS3 controller doesn’t hibernate and power off like it does when paired with the PS3. To conserve your battery, once you are done with it you need to “unplug” the controller from the system with the following command. Use the bluetooth address you saved from initiating the connection.

$ sudo hidd --unplug 00:16:FE:D7:8C:XX

The lights on the controller will go dark once it has been successfully unplugged.

If you want to reconnect/re-pair the controller to your PS3, simply reattach the controller to the PS3 with the USB cable and press the PS button.

Summary

Once you have successfully installed the package and are comfortable with the pairing and connection process you can eliminate all the debugging steps.

Here is a quick reference for the pairing and connection process.

Bluetooth Paring (only if you need to re-pair with Ubuntu)

(connect controller with USB cable)
$ sudo ./sixpair
(disconnect controller from USB cable)

Initiate Connection

$ sudo /etc/init.d/bluetooth stop
$ sudo hidd --server --nocheck -n
(press the PS button on controller to connect)
(terminate hidd Ctrl+C)
$ sudo /etc/init.d/bluetooth start

Terminate Connection

$ sudo hidd --unplug 00:16:FE:D7:8C:XX



ubuntu
, , , , , , , , , , ,
8 Comments

Related posts:

  1. Installing Ubuntu 9.10 on the Dell Zino HD
    The Dell Inspiron Zino HD is the perfect machine if you are looking to build...
  2. Install Boxee on 64-bit Ubuntu 9.10 Karmic
    Installing Boxee turns your computer into an incredable HTPC but the installation process is not...
  3. Install Linux development man pages in Ubuntu
    By default Ubuntu doesn’t install the manual pages used for Linux software development which is...


If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Comments (8)

Thanks for this very helpful post! I’ve spent the past few weeks trying to get this to work. Last night, after getting a new adapter and installing blueman and following your instructions repeatedly I got a connection! I’m not sure why but it still seems to only connect sometimes.

Thanks again!

I’m glad to hear that you were successful. Thanks for the feedback!

What would a possible problem be if $ sudo hcidump -t -V -x
does not show a new device. I know the controller is transmitting because it is found in the bluetooth pairing app that came with ubuntu. I’m running 9.04 i386 could that be an issue?

no thats not a problem, i followed the tutorial with 9.04 on and i386 system and it worked fine.

Im using 9.04 and it didnt work. Im having the same problem as above

when i put this code in the console

$ sudo ./sixpair

show me this

Current Bluetooth master: 11:11:11:11:11:11
Setting master bd_addr to 11:11:11:11:11:11

and then i put this code

$ sudo hidd –server –nocheck -n

and press the ps button and nothing happens

any help!?

Hi!

I’m running karmic and I love that your instructions are CLI only, but.. unfortunately the controller doesn’t seem to connect to hidd.

I’ve compiled my own bluez-compat and installed the deb.

The sixpair app says that the controller has gotten it’s new master (my bluetooth adapter).

However, When I press the PS-button, it flashes all 4 led’s but nothing happens in the hidd or in hcidump. Could you help me figure it out?

I’ve the same problem as stated above

Trackbacks (0)

No trackbacks yet
Leave a comment

(required)

(required)