A dandelion puff

Connecting a Sony PS3 Controller to Ubuntu Linux

I’ve been emulating older games on my desktop for a while now, and I like to use a PS3 controller for games that expect the player to have a controller. I feel that I should share the procedure that I use to connect the controller via bluetooth, as I discovered the trick mostly by serendipity.

Assuming that the PS3 controller has any charge at all, if you hold down the PS button it will become visible as a bluetooth device to your computer. If you try to connect to it using the GNOME or Unity bluetooth GUIs (I haven’t ever tried from other Desktop Environment’s GUIs), it will always fail to connect for non-obvious reasons.

The answer lies, as it often does, in the shell. Specifically, the bluetoothctl command line interface. If you run bluetoothctl, you should see something similar to the following:

$ bluetoothctl
[NEW] Controller CC:AA:BB:EE:DD:FF pop-os [default]
[NEW] Device 99:88:77:66:55:44 AirPods
[NEW] Device CC:BB:AA:99:11:22 Charge 2
Agent registered
[NEW] Device 04:99:F9:FF:DD:FC PLAYSTATION(R)3 Controller
[bluetooth]#

bluetoothctl has a number of commands that you can type to operate on different devices. The info command displays the current status of a device with respect to your computer. It accepts the MAC address of the device that you’re interested in as an argument. You can and should use the tab-completion on these MAC addresses.

[CHG] Device 04:99:F9:FF:DD:FC Connected: no
[CHG] Device 04:99:F9:FF:DD:FC Connected: yes
[CHG] Device 04:99:F9:FF:DD:FC Connected: no
[CHG] Device 04:99:F9:FF:DD:FC Connected: yes
[PLAYSTATION(R)3 Controller]# info 04:99:F9:FF:DD:FC
Device 04:99:F9:FF:DD:FC
        Name: PLAYSTATION(R)3 Controller
        Alias: PLAYSTATION(R)3 Controller
        Class: 0x000508
        Icon: input-gaming
        Paired: no
        Trusted: no
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v054Cp0268d0100

As you can see, my computer connects and disconnects from the device over and over (as a result of trying to connect in the GUI, I believe).

The info results indicated that the device is not paired, trusted, connected, or blocked. What gives? Why can’t we connect? I do not pretend to understand the intricacies of the bluetooth protocol, but I found that I am able to connect if I manually “trust” the device.

[PLAYSTATION(R)3 Controller]# trust 04:99:F9:FF:DD:FC
[CHG] Device 04:99:F9:FF:DD:FC Trusted: yes
Changing 04:99:F9:FF:DD:FC trust succeeded
[CHG] Device 04:99:F9:FF:DD:FC Connected: no:1D:DD:FC
[CHG] Device 04:99:F9:FF:DD:FC Connected: yes
[PLAYSTATION(R)3 Controller]# info 04:99:F9:FF:DD:FC
Device 04:99:F9:FF:DD:FC
        Name: PLAYSTATION(R)3 Controller
        Alias: PLAYSTATION(R)3 Controller
        Class: 0x000508
        Icon: input-gaming
        Paired: no
        Trusted: yes
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v054Cp0268d0100

After this, I’m able to connect to and use the controller without difficulty. This is a one-time step too. The OS remembers which devices are trusted.

I found that I needed to “trust” the device while it was plugged in to my computer with a USB cable. After I marked it as trusted, I could unplug the USB cable and the bluetooth connection would work.

Of course, once it was connected, my screen started going crazy. The accelerometer within the controller was being used to control the orientation of my screen. It took some searching, but I found the command to enable orientation-lock in GNOME. This will vary across versions of GNOME, and will work differently in other desktop environments, but hopefully it will help someone else:

gsettings set org.gnome.settings-daemon.peripherals.touchscreen orientation-lock true

Similar tricks can be used for Xbox One S controllers and PS4 controllers, but those will have to wait for another blog post.

Image Credit: Ram Yoga
Image License: CC-BY-NC 2.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.