Shopping Cart

Posts

PS4 controller support for the USB Host library

The PS4 controller is now also supported via Bluetooth. It uses the same API as the other libraries I have written, so if you have used them before, then you should be quite familiar with it.

The example code is available at Github: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS4BT/PS4BT.ino.

For more information take a look at my blog post: http://blog.tkjelectronics.dk/2014/01/ps4-controller-now-supported-by-the-usb-host-library/. This explains how to pair with the controller and have some background information as well.

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

That is all for now. Hopefully this will be useful to anybody out there that wants to use the PS4 controller with the library.

Update 18. January 2014
A USB version of the library is now also available.

No related posts.

24 comments to PS4 controller support for the USB Host library

  • Todd DeWitt

    Is the code capable of transmitting/receiving audio? If so, how is this done? I would like to utilize the headphones and microphone in a project.

    Also, can this be used with the BT HID Keyboard? Basically, two BT devices at the same time. If possible, how is that done?

    I’m currently using the previous code version and the BT dongles suggested from Amazon.com.

    Thanks!!

  • Todd DeWitt

    I received the below errors when attempting to send the PS4BT to an Arduino 2560. Thoughts?


    PS4BT.cpp: In function 'void setup()':
    PS4BT:32: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:35: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT.cpp: In function 'void loop()':
    PS4BT:42: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:44: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:46: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:48: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:53: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:55: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:59: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:64: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:66: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:68: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:70: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:73: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:75: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:77: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:79: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:82: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:84: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:86: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:88: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:91: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:93: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness
    PS4BT:95: error: reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away constness

  • Todd DeWitt

    I also ran into this with the PS3Multi compiling the program.


    PS3Multi.cpp: In function 'void loop()':
    PS3Multi:118: error: 'class PS3BT' has no member named 'printStatusString'
    PS3Multi.cpp: In function 'void onInit()':
    PS3Multi:141: error: 'LEDEnum' was not declared in this scope

    • What version of the Arduino IDE do you use? I can not reproduce that. Please update to the newest available – at the moment it 1.5.5.

      Make sure you have updated the library and not just the examples. Those errors are caused by a change I did a few weeks back.

  • Todd DeWitt

    Looks like it was the IDE version issue. Thanks for the help! Works like a charm!

  • Matej

    I’m using your library for some time now and it is great!
    I have only one problem and that is the Controller Bluetooth range. Do you know any solution to this problem? Thank you.

  • mczemek

    I have an odd problem that appears to be related to the USB Host Software Library.

    I have a UNO, Seeed Motor Driver Shield and the USB Host Shield. The Seeed Motor Driver Shield uses pins P8,P9,P10,P11,P12 and P13 so I moved P9 and P10 to P7 and P6 on the USB Host Shield and updated the USBCore.H file as follows:

    #else
    typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo etc.) or Teensy 2.0 and 3.0
    #endif

    What I am seeing is random pulses on P11,P12,P13 which the Motor Driver Shield uses for direction. It only occurs when the USB Host software is active. P8 is clean. ie. it starts after this line in the sketch runs.

    if (Usb.Init() == -1)
    {
    if (debug || debug1) Serial.print(F(“\r\nOSC did not start”));
    while (1); //halt
    }
    if (debug || debug1) Serial.print(F(“\r\nPS3 Bluetooth Library Started”));

    The motor drive software and USB software work separately so it does not appear to be a hardware problem.

    Is the library doing anything with these pins? Any suggestions?

    McZ

  • mczemek

    Matej, LM Technologies has a long range BlueTooth USB Adapter, LM-540, that has a 1000m range when used in pairs. I have not tried them but I am trying to get my hands on a pair for testing the range and with the PS-3 controller.

    http://lm-technologies.com/wireless-adapters/lm540-bluetooth-usb-adapters/

    McZ

  • W11cE

    Hi. Im having problems with DS4 pairing. I flash teensy with “PS4BT” example, connect BT adapter and open serial monitor. This shows up:

    PS4 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1A:7D:DA:71:13
    Please enable discovery of your device

    I press PS and share buttons on DS4 and it starts blinking. This shows up:

    Gamepad found
    HID device found
    Now just create the instance like so:
    BTHID hid(&Btd);
    And then press any button on the device
    Connecting to HID device
    Connection Failed: 04
    Please enable discovery of your device
    Couldn’t find HID device
    Wait For Incoming Connection Request

    DS4 keeps still blinking. I comment “PS4BT PS4(&Btd, PAIR);” and uncomment “PS4BT PS4(&Btd);” and flash teensy with this. BT dongle cant find the controller. I quess the pairing didnt work.

    Am i doing something wrong here or is this bug ?
    Im using teensy 3.1 and tested with PS3BT that the dongle works.

  • W11cE

    Ah, i misunderstood the pairing. DS4 never went to pairing process. Imo, the pairing isnt enough crearly described.
    The share button must be pressed and held first. Then PS button. Both must be held down for approx 5 sec. DS4 led will go to “double” blink state. I was mixing this with the regular blinking it does when its searching previously paired device.

    Works now, thanks.

  • Thank you for your feedback. I just updated the readme at Github: https://github.com/felis/USB_Host_Shield_2.0/commit/2b31f96bcd278711846d33006edab7ec83639ea5. Please tell me if it’s still not clear enough.

  • Nique

    Hi,
    What do you think, will your code and the usb host shield be a good point to start to connect an Thrustmaster Hotas Warthog Joystick? I want to use it with a teensy 3.1 to generate ppm output to finally control a rc airplane. The Warthog is somehow to expencive to try’n'error. Hopefully someone can provide some hope, thanks

Leave a Reply

  

  

  



You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">