Home > Arduino, Bluetooth, TKJ Electronics, USB > PS4 controller now supported by the USB Host library

PS4 controller now supported by the USB Host library

I am very pleased to announce that I have now added support for the PS4 controller via Bluetooth. This will allow you to read all the buttons and joysticks with the same API as all the other libraries I have written for the USB Host library.

PS4 controller

To get started you should look at the provided example. It shows how to read the different buttons and joysticks. I still haven’t figured out how to control the light, rumble and read the accelerometer, gyroscope and touchpad, but hopefully I will figure that out soon.

The pairing process for the PS4 controller is a little different than the PS3 controller, as it works like a regular Bluetooth joystick, as you simply make the PS4 controller discoverable by holding down the PS and Share button at the same time. The light will then start to blink rapidly.

After that you should be able to pair with the controller, by creating the PS4BT instance like so:

PS4BT PS4(&Btd, PAIR);

You should also check out the readme which will always have the newest information available.

The PS4 Bluetooth library actually uses the BTHID library to handle all the Bluetooth communication. This is much more modular and easier to maintain. I will work on making all the Bluetooth classes like that, so it will reduce the footprint of the libraries, but also make it much easier to maintain, as all the L2CAP communication would be handled in only one class.

I still haven’t written a library to use it via USB, but I will do that in the coming weeks, when I have time.

This is all for now. Please leave a comment below if you got any questions and I will answer as quickly as possible.

Update 18. January 2014
A USB version of the library is now also available. It allows you to read the gyroscope, accelerometer and touchpad as well.

Update 22. January 2014
I now also figured out how to read the IMU and touchpad data via Bluetooth. The problem is that the controller does not send out this information via Bluetooth by default.
To enable the full output the code sends out a get feature report. For more information see this excellent Wiki: http://eleccelerator.com/wiki/index.php?title=DualShock_4 by Frank Zhao.

Update 16. February 2014
It is now also possible to control the rumble and light as well. The code was inspired by this Linux driver: https://github.com/chrippa/ds4drv.

Categories: Arduino, Bluetooth, TKJ Electronics, USB Tags:
  1. Vinit
    February 11th, 2015 at 07:48 | #1

    Sorry to be late !!

    Link for the controller -- http://www.sony.co.in/product/ps4+dualshock+wave+blue .

  2. February 12th, 2015 at 00:29 | #2

    @Vinit
    It’s sounds like a problem with your dongle. Please try another one.

  3. Krunal
    February 26th, 2015 at 16:15 | #3

    Hello,
    I am using two PS4 controllers to control two robots with arduino Uno simultaneously. But, the PS4 often loses synchronization with the arduino. As soon as 1 controller loses sync, the other one loses it immediately. And this happens very often. Please help!!!

  4. February 26th, 2015 at 17:33 | #4

    @Krunal
    Can you post your code somewhere? For instance here: https://gist.github.com/.

    Also make sure that you have a stable 5V rail.

  5. Krunal
  6. Krunal
    February 28th, 2015 at 18:18 | #7

    @Lauszus
    Actually I had put that line because if the connection is lost, I had to upload the program again to pair the controllers.
    And also how can i cahnge the pairing key for the controller?

  7. March 1st, 2015 at 00:32 | #8

    @Krunal
    That is not the correct way to do it!

    You should call:

    PS4.pair();

    But why do you want to pair it again and again? It is only needed once. After that you can simply just press on the PS button on the controller.

  8. Krunal
    March 1st, 2015 at 03:37 | #9

    @Lauszus
    Actually while using 2 controllers, there is aproblem occuring that the controllers often get disconnected. I thought it will be so;ved if I change the pairing key for anyone controller which is set to 0000 by default. Bu how to do that?

  9. March 1st, 2015 at 11:38 | #10

    @Krunal
    Please remove that line first. I might be the reason why they are disconnecting. The pairing key doesn’t matter for the PS4 controllers.

  10. Krunal
    March 2nd, 2015 at 08:14 | #11

    @Lauszus
    Ohkk. Now even after removing that line, theres a problem coming. Consider that one of my controllers is connected, when I try to connect my second controller, the first one is disconnected if the second one goes into partial pairing mode (ie a constant white led is on). But this happens often. So please tell me a solution for this.

  11. March 2nd, 2015 at 22:41 | #12

    @Krunal
    Okay now I understand what you are trying to do. You need to make a instance for each controller. Please see this example for the PS3 controller for inspiration: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3Multi/PS3Multi.ino.

  12. Marco
    March 17th, 2015 at 21:12 | #13

    Hello, my son and I are willing to connect PS4 controller using Arduino due native USB port, but seems that Bluetooth dongle is not recognised by the library. We tried also with PS3 controller (and related software) but same bad result.
    Do the library support also native USB port or only USB shield?
    Thank you

  13. March 18th, 2015 at 00:21 | #14

    @Marco
    Unfortunately the Due native port is not supported as of yet, but this is something we are working on supporting. Hopefully it will get released in a couple of months.

    If you can’t wait, then you can buy a shield. The API should be almost the same in the new library, so you won’t have to rewrite your code once it is released.

  14. Frank
    March 25th, 2015 at 23:58 | #15

    I’m attempting to use a PS4 controller over BT. It doesn’t seem very stable at all, and there are delays that happen when using the PS4BT sketch. For instance I will press the up button which should turn the LED red. IT doesn’t. I press it again, and then it lights up red. I next press right, which should go to blue, but it stays red. Then I press it again and it finally goes to blue. I do see the button presses happening, but the led isn’t responding right. After a short bit of time the controller loses connection for whatever reason and won’t reconnect.

  15. March 26th, 2015 at 00:13 | #16

    @Frank
    Make sure that there is actually battery left on the PS4 controller. Also please enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging and post the output.

Comment pages
1 2 4247
  1. No trackbacks yet.