Configure a PS3 controller to automatically connect to a Raspberry Pi
Want to configure manually the master address of your PS3 controller and have it automatically connect to your Raspberry Pi? It's really not that complicated and and takes only 5 minutes to configure! Here's a step-by-step guide, for macOS that is, but it will probably work for Linux as well if you take out the macOS specifics.
Prerequisites (macOS)
Have homebrew installed, if you don't have yet; follow the instructions at https://brew.sh/.
Install required libs & packages
Install libusb
and libusb-compat
using homebrew (or other package manager for other platforms).
brew install wget libusb libusb-compat
Compiling sixpair binary
Next is compiling our sixpair executable, first download sixpair.c
using following command.
wget -O sixpair.c https://gist.github.com/wouterds/4ab5715966812009d634e3d034abc7fc/raw
Now we can compile sixpair.c
to an executable using the following command.
gcc -o sixpair sixpair.c -lusb
If everything went well you should now have a sixpair
executable.
Configuring Bluetooth on the Raspberry Pi
Now ssh into you Raspberry Pi (I'm using a Raspberry Pi W V1.2). Let's start by opening the bluetooth controller by running sudo bluetoothctl
. This should have produced something like following output [NEW] Controller B8:27:EB:31:97:DA raspberrypi [default]
, my bluetooth MAC address is B8:27:EB:31:97:DA
. Copy yours as we'll need it later.
Now you're in the bluetooth controller, run the following commands;
agent on
default-agent
discoverable on
For now, just leave this window open as we'll need to connect and trust the PS3 controller in a bit.
Configuring bluetooth master address for the PS3 controller
Let's connect the PS3 controller to your Mac. Now we can pair the PS3 controller with the sixpair binary we compiled earlier and the bluetooth MAC address we retrieved in the previous step. To do this, run ./sixpair B8:27:EB:31:97:DA
(substitute the MAC address with the one your Raspberry Pi outputted). This command will procude something similar as below.
Current Bluetooth master: 3c:15:c2:e3:d8:47
Setting master bd_addr to b8:27:eb:31:97:da
Connecting the PS3 controller to the Raspberry Pi
Disconnect the PS3 controller from your Mac and head back to the Raspberry Pi terminal. Power on the PS3 controller and you will see that it tries to connect to the Raspberry Pi in the terminal.
[NEW] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
[CHG] Device 00:1B:FB:2F:59:49 Connected: no
[DEL] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
[NEW] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
[CHG] Device 00:1B:FB:2F:59:49 Connected: no
[DEL] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
[NEW] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
[CHG] Device 00:1B:FB:2F:59:49 Connected: no
[DEL] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
[NEW] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
[CHG] Device 00:1B:FB:2F:59:49 Connected: no
[DEL] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
Copy the MAC address of the PS3 controller, in this case 00:1B:FB:2F:59:49
. After the PS3 controller turned off prepare the following command in the terminal (as you will need to be quick) connect 00:1B:FB:2F:59:49
. Next power on the PS3 controller again and once you see the line [NEW] Device 00:1B:FB:2F:59:49 00-1B-FB-2F-59-49
appearing in the terminal immediately execute the command. If all went well you should see something like the following.
Attempting to connect to 00:1B:FB:2F:59:49
[CHG] Device 00:1B:FB:2F:59:49 Modalias: usb:v054Cp0268d0100
[CHG] Device 00:1B:FB:2F:59:49 UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:FB:2F:59:49 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1B:FB:2F:59:49 ServicesResolved: yes
Now we need to trust the MAC address by running trust 00:1B:FB:2F:59:49
. Normally you should see the following output, and the PS3 controller will be connected to your Raspberry Pi.
[CHG] Device 00:1B:FB:2F:59:49 Trusted: yes
Changing 00:1B:FB:2F:59:49 trust succeeded
[CHG] Device 00:1B:FB:2F:59:49 Connected: no
[CHG] Device 00:1B:FB:2F:59:49 Connected: yes
You can now exit the bluetooth controller by running quit
. To turn off the PS3 controller, hold the menu button for 10 seconds. Now when you turn on again the PS3 controller it will automatically connect to your Raspberry Pi.
And that's about it! 😎🚀