Home > Arduino, Bluetooth, TKJ Electronics, USB > PS3 Controller BT Library for Arduino

PS3 Controller BT Library for Arduino

I just finished porting the bluetooth library to Arduino. It’s based on the library for the USB Host Shield from Circuits@Home. It works exactly the same way as the class for the boards from GHIElectronics – FEZ Panda, FEZ Rhino etc. You should check out my other post, if you haven’t already: FEZ Panda & PS3 Controller, FEZ Panda & PS3 Controller via Bluetooth, and Demonstration of the PS3 Controllers in action.
To make it work, you’ll need a USB Host Shield or an Arduino ADK.

Update
I have now created another library that only supports the controller via USB. The source code for the USB library can be found at the github repository. An example can be found as well: PS3USB.ino.

Video Demonstration

The library can be found at our Github: https://github.com/TKJElectronics/USB_Host_Shield_2.0. You should also see the Github wiki for more details.

Categories: Arduino, Bluetooth, TKJ Electronics, USB Tags:
  1. Joan
    October 24th, 2012 at 10:39 | #1

    First of all: Really nice work ;)

    my question.
    When i try to connect the PS3 controller, I get this in serial console:

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:15:83:33:5F:7E
    Wait For Incoming Connection Request

    And the controller doesn’t connect…. I’ve no idea…
    I must say that i’m using the sparkfun’s shield, but the PS3USB example works really good…

  2. October 24th, 2012 at 10:50 | #2

    @Joan
    It’s properly a power issue. Try to plug in a external powersupply.
    The problem is that the Sparkfun shield has an onboard 5V regulator connected to VIN, so you have to connect the Arduino to a source that is more than 5V.

  3. Joan
    October 25th, 2012 at 16:42 | #3

    @Lauszus
    Thank you for your reply, I’ve put a external suply but now i get that:

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:15:83:33:5F:7E
    Wait For Incoming Connection Request

    When I press the PS button nothing happen….
    Is the bluetooth dongle incompatible or if there appears the bt address it is ok?

    (excuse me of my english)
    Thx

  4. October 25th, 2012 at 17:14 | #4

    @Joan
    Did you remember to pair with the PS3 controller first? See the wiki for more details: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller.

    Your english is not a problem :)

  5. Joan
    October 25th, 2012 at 18:42 | #5

    Ok, really thank you.

  6. October 25th, 2012 at 18:43 | #6

    @Joan
    Your welcome :)

  7. Joan
    October 26th, 2012 at 15:09 | #7

    I still have one question that i can’t understand….
    when I press any button i get 8 times the same button pressed….
    I only erased the ps3.move code

    any suggestion??
    did u understand or u want the serial output?

    thanx

  8. October 26th, 2012 at 18:06 | #8

    @Joan
    What version of the code are you running? It should have been fixed.

  9. matt whitehouse
    December 7th, 2012 at 01:55 | #9

    do you have any ideas on how to make a motor(via a motor shield) respond proportionally to one of the ps 3 controllers joy sticks?

  10. December 7th, 2012 at 23:59 | #10

    @matt whitehouse
    Yes simply connect your Arduino to a motorcontroller and then you can use the output of the PS3 joystick as the input to the analogWrite function: http://arduino.cc/en/Reference/AnalogWrite

  11. matt whitehouse
    February 3rd, 2013 at 20:47 | #11

    are you using the statement:

    if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {

    to check and see if it is centered?

  12. February 3rd, 2013 at 22:25 | #12

    @matt whitehouse
    Yes exactly.
    PS: I modified your comment a bit, as our server messed up the formatting.

  13. Martin
    March 26th, 2013 at 08:58 | #13

    Hi!

    I’ve just tried the wired USB as a start. The PS3USB-example compiles and runs. But my PS3 controller doesn’t want to acknowledge that it is plugged in to anything. It just blinks for a while and then shuts down.

    The arduino with the shield is connected to a power source.

    Is there any kind of configuration that has to be made so that it can detect that it is plugged in?

    Regards,
    Martin

  14. March 27th, 2013 at 14:27 | #14

    @Martin
    No I should work automatically. What does it print when you run this example sketch: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/PS3USB/PS3USB.ino?

  15. Juan Carlos
    March 28th, 2013 at 05:19 | #15

    im trying to use the ps3bt example. but i got this massage when i connect my playstatiion controller
    PS3 Bluetooth Library Started
    Dualshock 3 Controller Connected
    Bluetooth Address was set to: 00:00:00:00:00:00

  16. Juan Carlos
    March 28th, 2013 at 05:26 | #16

    and when i have the dongle connect it says this
    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1F:81:00:08:30
    Wait For Incoming Connection Request

  17. March 28th, 2013 at 18:18 | #17

    @Juan Carlos
    You need to set the Bluetooth address of the dongle into the PS3 controller. Simply plug in the dongle, unplug it and then plug in the controller. The reason why you need to plug in the dongle first is because the program doesn’t know the dongle’s Bluetooth address.

    This can also be set at compile time by changing the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3BT/PS3BT.ino#L12 to:

    PS3BT PS3(&Btd,0x00,0x1F,0x81,0x00,0x08,0x30);

    See this this page for more information:
    https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller

  18. Juan Carlos
    March 29th, 2013 at 02:21 | #18

    I got it!! thanks you very much

  19. Juan Carlos
    March 29th, 2013 at 22:56 | #19

    I want to connect a bluetooth shield and a motor shield in an arduino uno. I know that my motor shield uses pins 4 throu 8 and 12. How can i know what pins are needed for the bluetooth

  20. March 30th, 2013 at 15:01 | #20

    @Juan Carlos
    The pins used by the USB Host Shield are 9, 10 and the SPI pins. These are 11, 12, and 13 on an Arduino Uno.

  21. Martin
    April 1st, 2013 at 13:35 | #21

    @Lauszus
    It just says PS3 library started. Although I have the Sparkfun USB host shield and I’ve read that I should couple pin 7 to the reset pin. Is this true?

    I’m going back to the lab tomorrow to try this if it is the case!

    Regards,
    Martin

  22. April 1st, 2013 at 13:50 | #22

    @Martin
    Yes that is true. Check out the schematics: https://www.sparkfun.com/datasheets/DevTools/Arduino/USBHostShield-v13.pdf and http://www.circuitsathome.com/wp/wp-content/uploads/2011/02/UHS_20.pdf. You can also just bend the GPX pin located at pin 8, as it’s not used by the library by default.
    You might also need to connect a external power supply to the Arduino, as the Sparkfun shield has a 5V regulator connected to the VIN pin.

  23. OSCAR
    April 12th, 2013 at 16:09 | #23

    HELP ME PLEASE: Bluetooth Address was set to: 00:1F:81:00:08:30
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1F:81:00:08:30
    Wait For Incoming Connection Request

  24. April 14th, 2013 at 23:30 | #24

    @OSCAR
    I guess you have set the Bluetooth address inside the PS3 controller: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller?

    Please describe you problem in order for me to help you.

  25. OSCAR
    April 16th, 2013 at 19:28 | #25

    OK THANks my problem is: Bluetooth Address was set to: 00:1F:81:00:08:30
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Write class of device: in this part I do no understand, how write class of device? Can you help me please

  26. April 16th, 2013 at 20:15 | #26

    @OSCAR
    You don’t have to do write anything! These are just debug strings. Simply plug in the dongle, wait a bit, then unplug it. Plug in your PS3 controller and finally plug in your dongle again.
    After that simply press PS on your PS3 controller and it will connect to the Bluetooth dongle.

  27. OSCAR
    April 23rd, 2013 at 18:07 | #27

    ok I have communication but what is the code motor dc in a car rc. I have

    int pwm = 3;
    int left = 2;
    int right = 4;

    void setup()
    {
      Serial.begin(115200);
      pinMode (pwm, OUTPUT);
      pinMode (left, OUTPUT);
      pinMode (right, OUTPUT);
    }
    void loop()
    {
      if ( Serial.available())
      {
        char Up = Serial.read();
        switch(Up)
        {
        case ‘Up’:
          analogWrite (pwm , HIGH);
          digitalWrite (left , HIGH);
          digitalWrite (right , LOW);
          break;
        }
      }
    }

    but it does not Because no stop

  28. April 23rd, 2013 at 19:09 | #28

    @OSCAR
    In order to stop the motor you will need to set both left and right LOW or both of them HIGH.

  29. OSCAR
    May 5th, 2013 at 16:40 | #29

    Your support really helped me to much, A question I CAN program SIXAXIS? and how is the code?

  30. May 6th, 2013 at 13:41 | #30

    @OSCAR
    What do you mean? You want to program the actual PS3 controller? Then the answer is no. This code simply allows you to communicate with a PS3 controller.
    Btw you can find much more information here: http://felis.github.io/USB_Host_Shield_2.0/class_p_s3_b_t.html and by reading the readme: https://github.com/felis/USB_Host_Shield_2.0#usb-host-library-rev20.

  31. May 13th, 2013 at 05:03 | #31

    Lauszus,
    Thanks for the post! Really helpfull! I am trying to accomplish this “simple” task of pair the controller with the dongle. But when I am already done with plugging dongle, registering address, unplugging it, plugging then the PS3 controller via USB cable, and…. when I put back the dongle into USB Host Shield, and press PS button, it starts the comunication, the blue light starts to blink at BT dongle, all of the lights of the controller became blinking rapidlly, and a message of Incomming connection appears at Serial monitor… But the handshaking does not complete itself. Any ideas? Thanks!
    Renato Aloi

  32. May 13th, 2013 at 11:36 | #32

    @Renato Aloi
    Please send me the output from your serial monitor and I will have a look :)

  33. May 13th, 2013 at 17:30 | #33

    Thanks! Here it is: PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    Wait For Incoming Connection Request
    Dualshock 3 Controller Connected
    Bluetooth Address was set to: 00:1B:10:00:2A:EC
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    Wait For Incoming Connection Request
    Incoming Connection Request

    Sorry about one thing I forgot to tell, my USB Host Shield is Keyes from funduino.com
    Is it an issue?

    Thanks,
    Renato

  34. May 13th, 2013 at 23:25 | #34

    Lauszus,

    I have added an DEBUG log for hci_state to print at Serial. Here is the output:

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initializedhci_state: 0
    hci_state: 0
    hci_state: 0
    hci_state: 0
    hci_state: 0
    hci_state: 1
    hci_state: 1
    hci_state: 1
    HCI Reset complete
    hci_state: 2
    hci_state: 2
    Write class of device
    hci_state: 3
    hci_state: 3
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    hci_state: 4
    hci_state: 4
    hci_state: 6
    hci_state: 10
    Wait For Incoming Connection Request
    hci_state: 11
    hci_state: 11
    hci_state: 11
    hci_state: 11
    hci_state: 11
    hci_state: 11
    hci_state: 11
    hci_state: 11
    Incoming Connection Request
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12
    hci_state: 12

    So when it enters in hci_state = 12 nothing more happens…

    Hope you can help me. I dont know what I am doing wrong. I just bought a brand new PS3 controller, change the bluetooth dongle for that one with red light… HID compliant, of course.

    Thanks again!
    Renato

  35. May 14th, 2013 at 07:35 | #35

    Lauszus,

    Sorry about flooding the comments area with debug logs, but this one appears to be important. I rolled back the comment on EXTRADEBUG and voila!

    PS3 Bluetooth Library Started
    BTD Init
    Addr: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 81
    Attributes: 03
    MaxPktSize: 0010
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 82
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 01
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    Wait For Incoming Connection Request
    Class of device: 00 05 08
    Incoming Connection Request
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    Connection Failed
    Wait For Incoming Connection Request
    Class of device: 00 05 08
    Incoming Connection Request
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    Connection Failed
    Wait For Incoming Connection Request
    Class of device: 00 05 08
    Incoming Connection Request
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    Connection Failed
    Wait For Incoming Connection Request
    Class of device: 00 05 08
    Incoming Connection Request
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    HCI event error: 06
    Connection Failed
    Wait For Incoming Connection Request

    Praying for these error messages help to solve the problem, I am anxious to see this working! It is an amazing job you have done with this lib! Thank you very much!

    Renato

Comment pages
1 2 1955
  1. February 17th, 2013 at 15:00 | #1
  2. February 17th, 2013 at 15:17 | #2