Setting up PlayStation Controllers on the Raspberry Pi

If you’ve ever tried to use a PlayStation controller with the Raspberry Pi, you may have found that it’s not very easy to do. Hopefully this tutorial will help simplify the process.

Our Raspberry Pi PlayStation Controller guide will walk you through the process of setting up and connecting the PlayStation 3 and PlayStation 4 controllers.

For PS3 controllers, we show you how to install the six-pair software and use it to configure your PS3 controller so it can connect to whatever Bluetooth device you’re using on your Raspberry Pi.

In this PS4 controller tutorial, we’ll walk you through the process of pairing with the Raspberry Pi’s Bluetooth, and also offer workarounds if your controller doesn’t work with the standard Bluetooth stack.

You can also configure Xbox controllers on the Raspberry Pi, as well as various other types of game controllers.

Controller setup is the perfect way to get your Pi ready to play some games. You might also be interested in using the controllers in other Raspberry Pi projects that use a gamepad.

Gear List

Below are all the gear I used for this set up controllers from PlayStation in the Pi tutorial.

Recommended

  • Raspberry Pi 2 or later
  • Micro SD card
  • Power supply
  • PlayStation controller (PS3 controller or PS4 controller)
  • Bluetooth adapter (only if not using a Pi 3 or Zero W)

Optional

  • Raspberry Pi Case

Setting up a PS3 controller on the Raspberry Pi

Setting up a PlayStation controller 3 on the Raspberry Pi is not an entirely straightforward process. Especially if you intend to use it wirelessly, we’ll walk you through all the steps to get you up and running in no time.

If you want to use your PS3 controller wired, you should be able to use it works as a plug and play device.

However, we recommend that you go to our section on compiling and installing sixad. Sixad is a piece of software that ensures that all features of PS3 controllers are supported.

Before beginning this section of the Raspberry Pi PlayStation tutorial, make sure you have a mini USB cable handy, as that you will need it. this to pair the controller with the Raspberry Pi. The reason for this is due to the way the PS3 controller is configured to communicate with Bluetooth controllers.

Preparing the PS3 controller to connect to the Raspberry Pi

1 . Before we start installing anything on our Raspberry Pi, we must first run the following two commands.

These commands will ensure that your Raspberry Pi is up to date.

sudo apt update sudo apt upgrade

2. To get started, we first need to install a package, this is so we can compile the sixpair software. This package is libusb-dev, this is for programs to interact with USB devices.

sudo apt install libusb-dev

3. With our required package now installed, we can go ahead and download the sixpair code and create a folder for it.

mkdir ~/sixpair cd ~/sixpair wget http://www.pabr.org/sixlinux/sixpair.c

4. Now, with the six-pair code downloaded to our Raspberry Pi, we need to compile it, to do this we can just run the following command.

This command will tell the GCC compiler to compile the code .

gcc -o sixpair sixpair.c -lusb

5. With Sixpair now compiled on our Raspberry Pi, we need to connect our PS3 controller to the Raspberry Pi using the USB mini cable.

6. Once the controller has connected, we can run sixpair by running the following command.

Sixpair will reconfigure the controller to talk to our device Bluetooth.

sudo ~/sixpair/sixpair

7. If the sixpair software has successfully reconfigured the PS3 controller to talk to your Raspberry Pi’s Bluetooth dongle, then you should see something like the following on your command line.

Current Bluetooth Master: b8:27:eb:a4:59:08 Setting bd_addr master to b8:27:eb:a4: 59:08

8. Now at this point red is required to disconnect the PS3 controller from the Raspberry Pi, now that the changes have been made we should no longer need to connect the controller via USB unless you change the Bluetooth adapter.

You now have two options, these are compiling and installing sixad to handle the connection between the PS3 controller or simply using the bluetoothctl utility to make a connection to the controller of PS3.

Personally, we recommend that you try using Bluetooth as it is the most compatible with other Bluetooth Devices.

Continue to the next section to learn how to pair your PS3 controller using Bluetooth . Otherwise, skip to the next section on how to use SIXAD to pair your controller.

Using bluetoothctl to connect your PS3 controller

1. Now that the PS3 controller is ready to connect with our Raspberry Pi, we can move on to pairing it with the Raspberry Pi.

To do this, we must first start the Bluetooth Configuration Tool by running the following command on the Raspberry Pi.

See Also:  How to Create a WordPress Users Email List

sudo bluetoothctl

2. Now that we have started the Bluetooth configuration tool, we need to turn on the agent and set it to use the default agent. Simply type the following two commands to do this.

agent on default-agent

3. Once we have enabled the agent, we now want to scan for new Bluetooth devices, by running the following command will tell the tool to start scanning.

scan on

You’ll immediately notice that any Bluetooth devices in the area will start showing up on your command line.

Ignore these for now as just we want to pay attention to the PS3 controller itself.

4. Now it’s time to press the PlayStation button on the controller, so it starts talking to the raspberry pi. You should soon start to see entries appear on the command line.

5. Once you see something like the following appear, be sure to copy the MAC address that is displayed. It is the text string that is separated by the symbols ‘:’.

[NEW] Device B8:27:EB:A4:59:08 B8-27-EB-A4-59-08 [CHG] Device B8 :27:EB:A4:59:08 Connected: no [DEL] Device B8:27:EB:A4:59:08 B8-27-EB-A4-59-08

6. Now that you have a MAC address available, copy it down, in our example this is “B8:27:EB:A4:59:08”.

With the MAC address in hand, you want to use that in the next command. With this following command, we are trying to get a successful connection and a UUID returned by the device.

Note that you may need to run this command several times before it is successful.

Make sure to replace “YOUR_MAC_ADDRESS” with the one you found in step 7.

connect YOUR_MAC_ADDRESS

Watch your PlayStation 3 controller, if it stops trying to connect then make sure to press the PS button again.

7. You will know a successful connection has been made when you see the text below appear on the command line. With the UUIDs available, we can proceed to the next step.

Attempting to connect to B8:27:EB:A4:59:08 [CHG] Device B8:27:EB:A4: 59 :08 Modalities: usb:v054Cp0268d0100 [CHG] Device B8:27:EB:A4:59:08 UUID: 00001124-0000-1000-8000-00805f9b34fb 00001200-0000-1000-8000-00805f f . Now that you have the MAC address, we need to add it to our Bluetooth trusted list. What this does is allow the controller to connect to the Raspberry Pi on its own.

To do this, we just need to type the following command on our Raspberry Pi. Be sure to replace “YOUR_MAC_ADDRESS” with the one you found in Step 7.

trust YOUR_MAC_ADDRESS

9. Once your PS3 controller has been successfully added to the trusted list, you should see something like the following on the command line.

[CHG] Device B8:27:EB:A4:59:08 Trusted: yes Changing B8:27:EB :A4:59: 08 trust successful

10. With your PS3 controller now successfully connected to your Raspberry Pi, we can now exit the Bluetooth configuration tool.

To exit you can use the following command or simply press CTRL + D.

exit

11. Now you can restart the Raspberry Pi. We do this so we can test and make sure everything works as expected. Run the following command to reboot the Raspberry Pi.

sudo reboot

12. With the Raspberry Pi now rebooted, press the PS button on your controller to test the connection between it and the Raspberry Pi.

The controller’s LEDs should blink briefly while connecting; however, afterward, if everything has worked correctly, only one LED should remain lit on the controller.

Using SIXAD to connect to your PS3 controller

1. Before we start compiling and configuring SIXAD on our Raspberry Pi, we must first install some packages we need.

The essential packages here are libusb-dev and libbluetooth-dev as they contain the code we need to compile the sixad software.

Libusb-dev contains code that allows us to interact with USB devices that are connected to the computer through code.

Libbluetooth-dev provides the necessary code to be able to interact with the Bluetooth stack of the operating system. In the case of sixad, this is used to detect when a PS3 device is connected to the Raspberry Pi.

sudo apt install git libbluetooth-dev checkinstall libusb-dev sudo apt install joystick pkg-config

2. Now that we have all the packages we might need, let’s go ahead and clone Retropie’s SIXAD repository, the reason we used the Retropie fork is that it has some improvements and is tested on the Raspberry Pi.

Run the following two lines on your Raspberry Pi to clone the GIT repository.

cd ~ git clone https://github.com/RetroPie/sixad.git

3. With the repository now cloned onto our Raspberry Pi, we can now move on to building it. Compiling SIXAD is simple to do and only requires running the following two commands.

The first command moves us to the folder, the second line runs the makefile and compiles the program.

cd ~/ sixad make

4. Now, with the sixad software now compiled, there are a couple more things to do before we can use it.

See Also:  How to create your own picture quotes without an app

The first of these is to make a folder where sixad keeps track of all your profiles.

Run the following command to create a folder for it.

sudo mkdir -p /var/lib/sixad/profiles

5. Finally, let’s run the checkinstall package we installed in step 1 of this section.

Basically, what this tool does is check the current installation and then proceed to run the “make install” commands if needed.

sudo checkinstall

At specific points you will be prompted with a few things, ignore them and just press ENTER to continue until for the installation to complete.

Once the installation is complete, you should see the following appear on your command line.

***************** ******************** ******************************** ***** Made. The new package has been installed and saved to /home/pi/sixad/sixad_20171230-1_armhf.deb You can remove it from your system at any time using: dpkg -r sixad **************** **************************************************** ** *****

6. Now that we have finished installing sixad, we can finally run it by typing the following command on our Raspberry Pi.

sudo sixad -start

If everything works as intended, you will now be prompted to press the PS button on your controller. Do this now to connect your controller to your Raspberry Pi.

7. Now that we know Sixad is working, we want to make sure it starts on boot so we can always connect our PS 3 controller.

To do this, we can run the following command to add sixad to the Raspberry Pi boot sequence.

sudo update-rc.d sixad defaults

Setting Up a PlayStation 4 Controller on the Raspberry Pi

There are a few different ways to use your PlayStation 4 controller with your Raspberry Pi. Some of these are easier to handle than others.

Sony USB Wireless Adapter

The Sony USB Wireless Adapter is probably the easiest solution for pairing your PS4 controller with your Raspberry Pi. Especially since the dongle should be able to work out of the box and pair with any official PS4 controller.

Bluetooth

Bluetooth is a bit more complicated than using Sony’s official wireless USB adapter and requires have a Raspberry Pi 3, Raspberry Pi Zero W, or USB Bluetooth adapter.

However, this method doesn’t work correctly for all PS4 controllers, and you may end up using a space controller named ds4drv in order to interact with it.

Note that if you previously configured the SIXAD tool, you will need to uninstall it in order to use your PS4 controller with the Raspberry Pi.

USB cable

Using a USB cable is the easiest way to use your PS4 controller, simply connect it with a Micro USB cable as you would when connecting your controller to the PS4 for the first time. .

Using the USB connection, the PS4 controller should work right out of the box.

Pairing your PS4 controller via Bluetooth hCTL

Please note that If you previously followed our guide on how to connect a PS3 controller to your Raspberry Pi via Bluetooth, you’ll need to follow the next two steps. Otherwise, skip to step 2 in this section.

1. The reason SIXAD has to be removed is that it seems to conflict with PlayStation 4 drivers. and it doesn’t allow them to pair and work properly.

To uninstall the sixad package that we compiled and installed in our PS3 section, we just need to run the following command on the Raspberry Pi.

sudo dpkg -r sixad

2. Now, before configuring everything, let’s make sure our Raspberry Pi is fully up to date by running the following two commands.

sudo apt update sudo apt upgrade

3. Now let’s begin the process of pairing our PS4 controller with our Raspberry Pi. For this guide, we will be using the Bluetooth command line tool.

Run the following command on your Raspberry Pi to start it.

sudo bluetoothctl

4. With the bluetoothctl tool now active, we need to run the following two commands in it, this enables the agent and sets the default agent.

agent on default-agent

5 . Now that we have enabled the agent, we can finally start scanning for devices. Enabling scanning is crucial, as it will display our controller when we tell it to start syncing.

scan in

6. Now it’s time to hit the “Share” button and the PS button on your controller at the same time as shown in the diagram below. Hold them down until the light on your controller starts blinking.

7. You should see something like the following on your command line, once you see this make a note of the MAC address.

The MAC address is the hexadecimal number separated by the symbol ‘:‘.

[NEW] Device 00:01:6C:B4:06: 7E Wireless Controller

In this case, the MAC address is “00:01:6C:B4:06:7E“.

8. While your controller is still flashing, type the following command. Be sure to replace “YOUR_MAC_ADDRESS” with the MAC address you obtained in Step 8. This command establishes a connection to your PS4 controller.

See Also:  How to Make a Website

If your controller stops flashing, simply press the “Share” and “PS” buttons again .

connect YOUR_MAC_ADDRESS

9. Upon a successful connection, you should see the following on your command line.

Attempting to connect to 00:01:6C:B4:06 :7E [CHG] Device 00:01:6C:B4:06:7E Connected: yes [CHG] Device 00:01:6C:B4:06:7E UUID: 00001124-0000-1000-8000-00805f9b34fb [CHG] Device 00:01:6C:B4:06:7E UUID: 00001200-0000-1000-8000-00805f9b34fb [CHG] Device 00:01:6C:B4:06:7E Services Resolved: yes [CHG] Device 00:01:6C : B4:06:7E Paired: yes Connection successful

10. Now we need to add our MAC address to the trusted list so that the PS4 controller can automatically connect to the Raspberry Pi.

trust YOUR_MAC_ADDRESS

11. Now that the Raspberry Pi’s Bluetooth device trusts the PS4 controller, we can now exit the tool by pressing CTRL + D or typing “exit”.

Now we can proceed to test if the controller is working.

12. Now let’s install the joystick, although this comes with some Raspbian installations, we’ll run the install command just in case. This package includes the applications we need to be able to test if our controller works correctly.

Run the following Linux command on your Raspberry Pi to install the software.

sudo apt install joystick

13. With the joystick package now installed on your Raspberry Pi, you can now run the following command, this will test js0 and receive the values ​​back.

sudo jstest /dev/input /js0

14. Now, if the values ​​change when you move and press buttons on your controller, then you are ready to use your PS4 controller and you can end the tutorial here.

No However, if your driver refuses to work, you may need to try the alternate way and use the user-space driver, please follow our guide in the next section below.

Using ds4driv to connect the PS4 controller to Raspberry Pi

Only use this option if standard Bluetooth is not does not work at all. This method makes use of a user-space driver that talks to the controller and allows the Raspberry Pi to understand it.

You will need to have paired your PS4 controller with your Raspberry Pi before you can continue with the following steps. .

1. To get started, we need to install the packages we need for ds4drv. To install the necessary python3 components, run the following command on your Raspberry Pi.

sudo apt install python3-dev python3-pip

2. With the necessary python packages now installed on the Raspberry Pi, we can use pip to get ds4drv and the python libraries needed for it. Run the following command to use pip3 to install it.

sudo pip3 install ds4drv

3. Now let’s configure the Raspberry Pi so that non-root users can access the joystick device that ds4drv creates To do this, run the following three commands on your Raspberry Pi. These commands download the set of rules and then apply them.

sudo wget https://raw.githubusercontent.com/chrippa/ds4drv/master/udev/50-ds4drv.rules -O /etc/udev/rules. d/50 -ds4drv.rules sudo udevadm control -reload-rules sudo udevadm trigger

4. Now, while your PlayStation 4 controller is still paired with the Raspberry Pi, we can run the following command to see if ds4drv can read and interact with your driver.

sudo ds4drv -hidraw -led 000008

5. Once you see text like the following on your command line, that means that ds4drv can see and talk to your PS4 controller that is paired with the Raspberry Pi.

[info][controller 1] Connected to Bluetooth controller (00:01:6C:B4:06:7E hidraw5) [info][hidraw] Searching for devices [info][controller 1] Battery: Fully charged

Now exit ds4drv by pressing CTRL + C.

6. We need to modify the startup script now, so that it automatically starts ds4drv at startup. To start doing this, run the following command on the Raspberry Pi.

sudo nano /etc/rc.local

7. Now we need to add the following line to this file. This line will start ds4drv when the Raspberry Pi starts.

Find

exit 0

Add to top

/usr/ local/bin/ds4drv -hidraw -led 000008 &

Once you’ve made your changes, you can save the file by pressing CTRL + X then Y then ENTER.

8 . You can now reboot the Raspberry Pi to check if it is booting up correctly. Do this by running the following command.

sudo reboot

9. Once your Raspberry Pi has rebooted, you can now use the following command to test if everything works. If the numbers change, then everything works as it should.

sudo jstest /dev/input/js0

Conclusions

Hopefully, by the end of this guide, you’ll have your Raspberry Pi up and running. with your PlayStation controllers successfully connecting to it.

Be sure to also check out some of our other gaming tutorials for the Pi, like Parsec streaming. If you have any feedback or need help with this guide, feel free to leave a comment below.

.

Leave a Reply

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