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. Uddhav
    January 11th, 2016 at 20:05 | #1

    Can you explain these line how they work..
    if (Usb.Init() == -1) {
    Serial.print(F(“\r\nOSC did not start”));
    while (1); // Halt
    Serial.print(F(“\r\nPS4 USB Library Started”));

  2. January 18th, 2016 at 14:51 | #2

    Those lines will initialise the USB host shield. I.e. it checks that SPI communication is working with the MAX3421E.

  3. Shawn
    March 6th, 2016 at 07:34 | #3

    I’ve been using this library and the host shield for a long time, and I love it. I normally have been running a PS4 controller wired to the shield because I didn’t have a BT dongle. I finally got one, and am running the example sketch for PS4 BT.

    I’m having issues with the PS4 controller and BT dongle keeping communication open. I get it paired, and it works great only for about 5 seconds. But they stop talking after that 5 seconds or so. When I press the PS button on the controller, they start talking again, for about 5 more seconds… rinse and repeat. I can tell when they are talking because I have the serial monitor open and am holding one of the joysticks to the side to have traffic to pass.

    Here’s what I’ve done:
    I upload the code, keeping the “PS4BT PS4(&Btd, PAIR);” line uncommented and active, and the “PS4BT PS4(&Btd);” line commented out. I pair the controller with the dongle. I switch those 2 lines of code, so now the “PS4BT PS4(&Btd, PAIR);” line is commented out, and the “PS4BT PS4(&Btd);” is active. I reupload the code. I open the serial monitor. I press the PS button and hold a joystick to the right. For a brief period, I get the values of the hats. Then, without me changing the stick position, the PS4 controller light goes out, and the serial monitor stops giving me new values for the stick position.

    I’m really hoping that I just have a user error. Please help :)

  4. March 8th, 2016 at 23:41 | #4

    Please enable serial debugging and post the output: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging.

  5. Yuji
    March 28th, 2016 at 06:53 | #5

    Hi,I’m Yuji.

    I attach the usb host shield to Arduino uno rev.3 and Intel Edison for Arduino, I try or PS4BT moves.
    Arduino uno was able to move the PS4BT. But Intel was not able to move the PS4BT.

    Intel Edison for Arduino, do you need to do something special process?

    Since English is not good, I’m sorry if was hard to understand.

  6. April 14th, 2016 at 23:08 | #6

    The Arduino Edison is currently not supported. Please see: https://github.com/felis/USB_Host_Shield_2.0/issues?q=edison+label%3A%22Intel+Edison%22.

  7. Uddhav
    April 30th, 2016 at 05:24 | #7

    I have “2 PS4 CONTROLLERS” and 2 bluetooth dongles connected to usb host shield.

    Is it possible to connect ps4 controller to only “one” specific bth dongle…not other one.
    or like having “seperate address” for each ps4 to connect to host shield dongle.

    I’m trying to make two wireless controlled bots with ps4 controller using library example PS4BT.
    So I want each bot to connect to specific controller not other one.

    Please help…Thanks

  8. mitch
    April 30th, 2016 at 06:35 | #8

    I used the USB Host 2.0 library for a month, and loved it. Thank you.
    All of a sudden, I can no longer pair up dongles with the PS3 controllers. I upload the code PS3BT and I start the serial monitor. The shield is detected ok. When I plug the dongle, nothing happens. I tried 5 dongles, from 5 brands, all version 3 or 4.

    When I plug the PS3 controller still , nothing appears in the serial screen. I am desperate. I am using this for controlling an RC tank. It worked so nice for an hour and got un-paired.

    Please help

    CK it out on

  9. Fernando
    May 11th, 2016 at 13:33 | #10

    I’m having the same issue as Shawn..
    @Shawn, did you fix it?

Comment pages
1 2 3 4247
  1. No trackbacks yet.