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.

43 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

    • Darren

      Did you ever have luck using a LM-540 with the USB Host Shield?

      If it works, I’d consider giving it a try for some added range for a PS3 controller.

  • 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

  • Synapsido

    Is possible use the Bluetooth module BTM-5 for connect PS3 and PS4 controllers?
    You have some examples for wiring?

  • langwan

    put Bluetooth Dongle tty no this message

    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

    “PS4 Bluetooth Library Started” only

  • RAVI

    Sir When I am Using this library to connect my PS4 controller with Arduino Mega ADK using a bluetooth dongle i am getting the reqired data but along with continuous error messages like 1.HCI Command Failed: 01 which is creating a lot of lag in my actual data.Please Help Immediately..I am using a Sony PS4 dualshock PS4 controller.

  • José Méndez

    I have problems to compile the code:

    Arduino:1.6.0 (Windows 8), Placa:”Arduino Uno”

    C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_2.0-master\BTD.cpp: In member function ‘void BTD::setBdaddr(uint8_t*)’:
    C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_2.0-master\BTD.cpp:1346:66: error: ‘bmREQ_HID_OUT’ was not declared in this scope
    pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0×03, 0×00, 8, 8, buf, NULL);
    ^
    C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_2.0-master\BTD.cpp: In member function ‘void BTD::setMoveBdaddr(uint8_t*)’:
    C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_2.0-master\BTD.cpp:1362:66: error: ‘bmREQ_HID_OUT’ was not declared in this scope
    pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0×05, 0×03, 0×00, 11, 11, buf, NULL);
    ^
    Error de compilación

    This report would have more information with
    “Show verbose output during compilation”
    activala desde Archivo > Preferencias

  • bryan

    whenever I try to run example sketches for the usb host library, there is an error. I have tried it on two different arduino IDE versions 1.0.6 and 1.6.1 to see if that was the problem. this is the error message that returns when I try and verify the code

    /Users/bryanmiller/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/BTD.cpp: In member function ‘void BTD::setBdaddr(uint8_t*)’:
    /Users/bryanmiller/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/BTD.cpp:1346: error: ‘bmREQ_HID_OUT’ was not declared in this scope
    /Users/bryanmiller/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/BTD.cpp: In member function ‘void BTD::setMoveBdaddr(uint8_t*)’:
    /Users/bryanmiller/Documents/Arduino/libraries/USB_Host_Shield_2.0-master/BTD.cpp:1362: error: ‘bmREQ_HID_OUT’ was not declared in this scope

  • mits

    hey i have the same problem in a deferent project

    C:\Users\Mitsatsos13\workspace\Documents\Arduino\libraries\USBHostShield2\BTD.cpp: In member function ‘void BTD::setBdaddr(uint8_t*)’:
    C:\Users\Mitsatsos13\workspace\Documents\Arduino\libraries\USBHostShield2\BTD.cpp:1346:66: error: ‘bmREQ_HID_OUT’ was not declared in this scope
    pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0xF5, 0×03, 0×00, 8, 8, buf, NULL);
    ^
    C:\Users\Mitsatsos13\workspace\Documents\Arduino\libraries\USBHostShield2\BTD.cpp: In member function ‘void BTD::setMoveBdaddr(uint8_t*)’:
    C:\Users\Mitsatsos13\workspace\Documents\Arduino\libraries\USBHostShield2\BTD.cpp:1362:66: error: ‘bmREQ_HID_OUT’ was not declared in this scope
    pUsb->ctrlReq(bAddress, epInfo[BTD_CONTROL_PIPE].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0×05, 0×03, 0×00, 11, 11, buf, NULL);
    ^
    Error compiling.

    how to fix this error is for different project.
    Ty For your time

  • Do you know if anyone has ported your USB Host library to Cortex M microcontroller (such as the STM32F4)?

  • Tom Frederick

    I am trying to pair a PS4 controller with an Arduino UNO with Host Shield and BT dongle. I know that the dongle is supported by the libraries. I am able to use the code as it sits to pair over the air with the Share button, but I was wondering if pairing via a USB cable was possible in the current framework? I am interested in configuring the code to behave like the PS3 library did. Have the option to pair over USB or connect to any device that has been paired.

    Thank you for all of your work on this great library.

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="">