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/felis/USB_Host_Shield_2.0. You should also see the Github wiki for more details.

Categories: Arduino, Bluetooth, TKJ Electronics, USB Tags:
  1. Roger Carmona
    April 26th, 2012 at 22:57 | #1

    I congratulate you on your work with PS3BT library. I want to know if you think on complement this library with RFCOMM protocol (over L2CAP) for use this library as Serial port emulator (Virtual Serial Port for arduino with Dongle USB Bluetooth). Thanks

  2. April 27th, 2012 at 06:06 | #2

    @Roger Carmona
    Dear Roger.
    Yes we are, and we will keeper you posted as always.

    Thomas

  3. Lauszus
    April 27th, 2012 at 07:08 | #3

    @Roger Carmona
    I’m currently just about to start my exams, so I haven’t got the time right now, but it’s differently one of the next project I will work on, but don’t expect it to be finished the next couple of month!

    Regards
    Lauszus

  4. matt whitehouse
    July 25th, 2012 at 18:22 | #4

    i cant get it to work with arduino adk board, it says in serial moniter” osc not started”

  5. Lauszus
    July 25th, 2012 at 18:30 | #5

    @matt whitehouse
    You should uncomment the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/avrpins.h#L25 for it to work with the Arduino ADK.

    Regards
    Lauszus

  6. matt whitehouse
    July 25th, 2012 at 19:06 | #6

    @lauszus
    thank you, i was just about to give up!!

  7. Lauszus
    July 25th, 2012 at 19:08 | #7

    @matt whitehouse
    You’re welcome 🙂

  8. matt whitehouse
    July 25th, 2012 at 19:29 | #8

    another question, what type of bluetooth dongle are you using, the program doesnt recognize mine?

  9. Lauszus
    July 25th, 2012 at 19:31 | #9

    @matt whitehouse
    Does it print anything?
    You will need a bluetooth dongle which supports bluetooth version 2.0+EDR. See the wiki for a list of confirmed devices: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Hardware.

  10. matt whitehouse
    July 25th, 2012 at 20:04 | #10

    this is what it prints out

    PS3 Bluetooth Library Started
    Unknown Device Connected – VID: 0A5C PID: 4500
    PS3 Init Failed, error code: 0

    my bluetooth adapter says class 2 v2.1

  11. Lauszus
    July 25th, 2012 at 20:08 | #11

    @matt whitehouse
    Make sure you are using the newest version from github. Also try to change the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3BT.cpp#L227 to:

    ConfigDescParser<0, 0, 0, 0> confDescrParser(this);

    And see if it make it work.

  12. matt whitehouse
    July 25th, 2012 at 20:26 | #12

    it still says the same thing, ugh

  13. Lauszus
    July 25th, 2012 at 20:28 | #13

    @matt whitehouse
    Then you will have to buy a new dongle, sorry.

  14. matt whitehouse
    July 25th, 2012 at 20:29 | #14

    thank you any way

  15. matt whitehouse
    July 26th, 2012 at 02:00 | #15

    Lauszus :
    @matt whitehouse
    Make sure you are using the newest version from github. Also try to change the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3BT.cpp#L227 to:
    ConfigDescParser<0, 0, 0, 0> confDescrParser(this);
    And see if it make it work.

    is it supposed to say “this”?

  16. Lauszus
    July 26th, 2012 at 02:16 | #16

    @matt whitehouse
    Yes it’s supposed to say that 🙂

  17. matt whitehouse
    July 26th, 2012 at 02:55 | #17

    ok i found an old bluetooth dongle, this is what the seril moniter says now
    __________________________________________________________________________
    PS3 Bluetooth Library Started
    getDevDescr:
    PS3 Init Failed, error code: 13
    __________________________________________________________________________

  18. matt whitehouse
    July 26th, 2012 at 03:55 | #18

    @matt whitehouse
    i fixed this now it says
    PS3 Bluetooth Library Started
    and then nothing

  19. Lauszus
    July 26th, 2012 at 13:34 | #19

    @matt whitehouse
    Try to uncomment EXTRADEBUG (https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3BT.cpp#L20) and it should then print the endpoints (https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3BT.cpp#L352-367). Please send me the output for both dongles and I will have a look.

  20. matt whitehouse
    July 26th, 2012 at 16:31 | #20

    it still says

    PS3 Bluetooth Library Started

    does the controller need to be connected, because it wont connect, the dongle has a button that is supposed to be used to connect but i dont know if that has any thing to do with it or not

  21. Lauszus
    July 26th, 2012 at 16:37 | #21

    @matt whitehouse
    You have to set the bluetooth address of the dongle to the ps3 controller. See this section of the wiki for more information: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Setting_the_BT_Address_on_your_PS3_Controller.

  22. matt whitehouse
    July 26th, 2012 at 16:41 | #22

    i did that, thats how i got it to stop saying error code 13

  23. Lauszus
    July 26th, 2012 at 16:42 | #23

    @matt whitehouse
    Try to add a external power source, it might be a power issue.

  24. matt whitehouse
    July 26th, 2012 at 17:17 | #24

    and now its back to

    PS3 Bluetooth Library Started
    PS3BT Init
    getDevDescr:
    PS3 Init Failed, error code: 13

  25. matt whitehouse
    July 26th, 2012 at 17:18 | #25

    and now its back to

    error code 13

  26. Lauszus
    July 26th, 2012 at 17:19 | #26

    @matt whitehouse
    Okay. Is that the ps3 controller or the bluetooth dongle?
    Try to plug the cable in and then restart the Arduino, I had some problems with some dongles not being ready fast enough for the library.

  27. matt whitehouse
    July 26th, 2012 at 18:35 | #27

    thats the dongle

  28. Lauszus
    July 26th, 2012 at 18:38 | #28

    @matt whitehouse
    Okay. Have you added a external power supply like I sad? And have you tried to connect the dongle and then reset the Arduino? And then please uncomment EXTRADEBUG and send me the output, so I can have a real change of figuring out what is going on!

  29. matt whitehouse
    July 26th, 2012 at 19:48 | #29

    ive done all of the above when i uncommented extradebug it said

    PS3 Bluetooth Library Started

    and that was it

  30. Lauszus
    July 26th, 2012 at 20:26 | #30

    @matt whitehouse
    What shield are you using? Try to plug in another device like you phone and it should print:
    “Unknown Device Connected – VID: 0xXXXX PID: 0xXXXX”. Where 0xXXXX are hex numbers. By doing so you can see if the shield is working correctly.

  31. matt whitehouse
    July 26th, 2012 at 22:16 | #31

    @Lauszus

    i am using the arduino adk, i just got a new dongle it is a belkin with bluetooth v2.1 +edr, is it compatible

  32. Lauszus
    July 26th, 2012 at 22:22 | #32

    @matt whitehouse
    Okay, but what happens if you plug in a different device?

  33. matt whitehouse
    July 26th, 2012 at 22:24 | #33

    sorry i forgot to put that, the first usb dongle i tried did the unknown device connected, and the ps3 controller works over usb

  34. Lauszus
    July 26th, 2012 at 22:32 | #34

    @matt whitehouse
    Yes, but what does it print when you plug in a different device like your phone???

  35. matt whitehouse
    July 26th, 2012 at 22:39 | #35

    this is what it prints

    PS3 USB Library Started
    Unknown Device Connected – VID: 045E PID: 0719
    PS3 Init Failed, error code: 0

  36. matt whitehouse
    July 26th, 2012 at 22:45 | #36

    wow i just put what it prints for usb code heres what it does for bt PS3BT Init
    Addr: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 81
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 01
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 08
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 82
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 02
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 04
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 83
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 03
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 08
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 84
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 02
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 04
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 04
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 85
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 05
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 08
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 86
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 02
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 06
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 04
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 87
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 07
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 08
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 88
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 02
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 08
    Attributes: 03
    MaxPktSize: 0020
    Poll Intrv: 04
    Bluetooth Dongle Initialized
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05
    ACL data in error: 05

    it loops through this

  37. Lauszus
    July 26th, 2012 at 23:39 | #37

    @matt whitehouse
    I looks like you will need a different dongle. I have never seen a dongle like that.
    There is a list of confirmed dongles at the wiki: https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information#wiki-Hardware.

  38. matt whitehouse
    July 26th, 2012 at 23:48 | #38

    will any dongle 2.0 or higher with edr work?

  39. Lauszus
    July 27th, 2012 at 00:31 | #39

    @matt whitehouse
    Not any, as you just saw. But most of them!

  40. Matej
    October 7th, 2012 at 12:54 | #40

    I am running PS3BT sample code on my Arduino Mega with USB host shield.
    In Serial Monitor i always get the same data(joystick position, button preses, …)
    If i change the sample code, delete the whole loop() function code, the Serial output is stil the same!? How is this possible? I also commented all the DEBUG lines…
    How can i control a simple LED with a square button if none of the code in loop is actualy run?

  41. October 7th, 2012 at 16:08 | #41

    @Matej
    That sounds very weird. Are you sure that you are actually uploading the new code? Try to unplug the ADK and then quit and reopen the Arduino IDE and see if that works.

    Could you also send me the serial output?

  42. Matej
    October 7th, 2012 at 17:20 | #42

    @Lauszus
    I get this Serial output if the void loop() function is empty:

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:15:83:3D:0A:57
    Wait For Incoming Connection Request
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3 Controller
    Connected to Device: 04:76:6E:DA:DD:8C
    Scan Disabled
    Your dongle may not support reading the analog buttons, sensors and status
    Your HCI Version is: 1
    But should be at least 3
    This means that it doesn’t support Bluetooth Version 2.0+EDR
    HID Control Incoming Connection Request
    Wait For Incoming Connection Request
    HID Control Configuration Request
    HID Control Successfully Configured
    HID Interrupt Incoming Connection Request
    HID Interrupt Configuration Request
    HID Interrupt Successfully Configured
    Dualshock 3 Controller Enabled
    RightHatX: 138
    RightHatX: 138
    RightHatX: 138
    ——–
    I am runing this on 64bit Windows 8.

  43. October 7th, 2012 at 17:24 | #43

    @Matej
    So you are not even calling USB.Task()?
    The output is from the library it self to debugging.
    Btw it seems like you will need another dongle for it to work.

  44. Matej
    October 7th, 2012 at 17:26 | #44

    @Lauszus
    I get this Serial output even if the sketch looks like this:
    void setup() {
    Serial.begin(115200);

    }
    void loop() {
    Serial.print(“OK”);
    }

    This must be something with the IDE, wright? Or Windows 8 compatibility

  45. October 7th, 2012 at 17:27 | #45

    @Matej
    Yes I must be something with the IDE. Try a different computer.

  46. Matej
    October 7th, 2012 at 17:41 | #46

    When I click Upload i get this message after upload is complete (IDE consol)
    avrdude: stk500_getsync(): not in sync: resp=0x0d

    What does it mean?

  47. Matej
    October 7th, 2012 at 17:54 | #47

    I solved my problem. The IDE is hawing permissions errors, it cant remember my settings for board selection. So it loads Arduino Uno instead of Mega. This is probably Windows 8 compatibility error 😉

  48. October 7th, 2012 at 18:00 | #48

    @Matej
    Okay, so everything is working now?

  49. Matej
    October 7th, 2012 at 19:20 | #49

    Yes, everything is working now. Thank you for your help 😉

  50. October 7th, 2012 at 19:25 | #50

    @Matej
    Good. Your welcome!

  51. Joan
    October 24th, 2012 at 10:39 | #51

    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…

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

    @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.

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

    @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

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

    @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 🙂

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

    Ok, really thank you.

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

    @Joan
    Your welcome 🙂

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

    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

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

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

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

    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?

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

    @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

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

    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?

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

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

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

    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

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

    @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?

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

    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

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

    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

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

    @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

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

    I got it!! thanks you very much

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

    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

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

    @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.

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

    @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

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

    @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.

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

    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

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

    @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.

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

    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

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

    @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.

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

    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

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

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

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

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

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

    @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.

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

    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

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

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

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

    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

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

    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

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

    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

  86. Josh
    June 23rd, 2013 at 03:40 | #86

    Hey, so I have been trying to get this to work but it seems to hang after outputting ‘PS3 Bluetooth Library Started’

    any help?

  87. June 23rd, 2013 at 09:14 | #87
  88. Josh
    June 23rd, 2013 at 14:32 | #88

    ok new message,
    PS3 Bluetooth Library Started
    Unknown Device Connected – VID: 0A5C PID: 4500
    BTD Init Failed, error code: D1

    i assumme then that my adapter isnt supported

  89. June 23rd, 2013 at 16:44 | #89

    @Josh
    Have you uncomment this line as well: https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3BT.cpp#L20? It should print much more debugging if it’s uncommented. Also try to connect the dongle and then reset the Arduino.

  90. nero
    July 1st, 2013 at 13:56 | #90

    Hello , I would like to thank you for the library .
    Iâ??m using it to control a motor of a rc Car using the ps3 controller by Bluetooth and arduino .
    Im now in the programming process and I want to use switches or else the programe will be too long
    so what should I edit to me code so that the the switch happens when I press a button
    switch (when button pressed) {
    case â??PS3.getButtonPress(CROSS)â??:
    digitalWrite(BLP, HIGH);
    break;
    case â??PS3.getButtonPress(SQUARE)â??:
    digitalWrite(BLP, LOW);
    break;
    }

  91. Jeremy
    July 25th, 2013 at 19:56 | #92

    Lauszus :
    @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.

    Firstly, Cool Bot. I only wish I could make half of that.
    I’m having same trouble as this. Just says “PS3 Bluetooth Library Started” and nothing else. Can you elaborate on this please, I don’t understand the schematics? Which pin7 or what is the GPX pin8?

  92. July 25th, 2013 at 20:02 | #93

    @Jeremy
    Before you do anything, please uncomment the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/message.h#L21 and then see it it works – the reason why you think it’s not working might be because it’s simply not printing any serial debugging.

    First of all you will need to connect pin 7 on the Arduino to reset on the Arduino. After that simply bend pin 8 on the shield, as it’s not used currently by the library.

  93. Jeremy
    July 25th, 2013 at 23:26 | #94

    Thank you Lauszus,

    I should have explained a bit more. It this point I am trying to run the sketch PS3BT from the USB host shield 2.0 library. I’ve tried two new USB host shields and two new BT dongles but I get that message â??PS3 Bluetooth Library Startedâ?.
    Is this what you mean by reset 7? This is part of sketch “Changing the Name or Security Code of an Arduino BT” that I found…

    int LED = 13; // select the pin for the LED
    int RESET = 7; // BT module uses pin 7 for reset

    void setup() {
    pinMode(LED,OUTPUT); // declare the LED and BT RESET pins as output
    pinMode(RESET,OUTPUT);

    Serial.begin(115200); // connect to the serial port

    digitalWrite(RESET, HIGH);
    delay(10);
    digitalWrite(RESET, LOW);
    delay(2000);

    Is this something I would include in the PS3BT sketch or just run by itself once?
    By pin 8 do you mean the pin on shield that would go into D8 on arduino uno?

    Thanks for your help…

  94. July 26th, 2013 at 00:06 | #95

    @Jeremy
    No you misunderstand me totally. You shouldn’t change my example code (I’m developer of all the Bluetooth stuff) but simply connect a wire from pin 7 on the Arduino to reset on the Arduino.
    And yes by pin 8 I mean pin 8 on the shield.

  95. Jeremy
    July 26th, 2013 at 00:54 | #96

    My apologies and thanks for the library. I tend to over think stuff. & over look the obvious.
    OK that’s done. But no change still. Just “PS3 Bluetooth Library Started”.
    I plug in the dongle and nothing, I plug in the ps3 controller and the 4 lights flash on the controller but still nothing on the serial monitor, I plug the dongle back in and try the PS button but no connection is made. Mean while nothing but “PS3 Bluetooth Library Started” on monitor.
    I have the external power plugged in and turned on.
    I’ve run your board_qc test and tested ok, however I could only complete the test if I jumped the GP in and out pins like suggested in sketch. I could not continue unless I did that?

  96. July 26th, 2013 at 01:05 | #97

    @Jeremy
    Have you remembered to uncomment this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/message.h#L21 as I told you?

    You can simply press any key to skip the test, as mentioned in the example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/board_qc/board_qc.ino#L4 – it’s used when testing the boards after manufacturing, so you can just skip it.

  97. Jeremy
    July 26th, 2013 at 01:30 | #98

    No because I thought that was code for a different sketch??? Is it part of the library? How do I find it?

  98. July 26th, 2013 at 01:47 | #99

    @Jeremy
    It’s inside the root of the library. Simply search for the file “message.h” and then locate the line and then uncomment it. Then simply compile and upload the example to your Arduino again.

  99. Jeremy
    July 26th, 2013 at 01:54 | #100

    Eureka, Thank you so much for you help! I’ve been trying to figure this out for about a month.

  100. July 26th, 2013 at 01:55 | #101

    @Jeremy
    You are welcome. You should just have send me a message from the beginning 😉

  101. Jeremy
    July 26th, 2013 at 12:15 | #102

    I didn’t realize you built the library until you told me. I stumbled across your website searching for answers. I know who to ask if I have any questions in the future though.
    Thanks again..

  102. July 26th, 2013 at 12:21 | #103

    @Jeremy
    You are welcome! It’s always nice to see that people use the libraries I wrote 🙂

  103. Jeremy
    July 27th, 2013 at 01:27 | #104

    @Lauszus
    Ok, turns out last night was a fluke that it connected. It seems to connect only sometimes (like 4 times today).
    If I reset, disconnect, reconnect, repair, open, close serial monitor enough times, eventually something clicks and it will connect to the ps3 controller and work perfectly. I got it once just by opening and closing the serial monitor a few times.
    I can’t pinpoint what’s causing the problem?
    Any suggestions?

  104. July 27th, 2013 at 14:13 | #105
  105. Jeremy
    July 27th, 2013 at 19:52 | #106

    @Lauszus
    Yes but only if I jump the pins 0 to 7, 1 to 6 etc. If I don’t it gets to the “press any key to continue” message but I can’t continue.

  106. July 27th, 2013 at 20:24 | #107

    @Jeremy
    Did you remember to connect pin 7 to the reset pin on the Arduino?
    You know that you have to send a character to the Arduino to get pass the test, right?

    When you write “pins 0 to 7” you are talking about the GPIO pins on the shield, right?

  107. Jeremy
    July 27th, 2013 at 21:48 | #108

    Pin 7 to reset, yes. GPIO pins yes. Sending character worked to continue test.

  108. July 27th, 2013 at 22:07 | #109

    @Jeremy
    Okay and the now “board_qc.ino” works everytime?
    If it is working you need to post your serial debug when it’s not working, so I can have an idea of what is going on.

    What Arduino are you using and have you connected an external power supply to the Arduino?

  109. Jeremy
    July 27th, 2013 at 22:19 | #110

    Ok, it’s an Arduino uno, I have external power connected. The following print out was me reseting the arduino and pulling out and plugging in the dongle untill it connected. I put a space between each reset or dongle plug out/in.

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    Incoming Connection Request

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    Incoming Connection Request

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    Incoming Connection Request

    PS3 Bluetooth Library Started

    getConf
    BTD Init Failed, error code: 0D

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    Incoming Connection Request

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Write class of device

    getConf
    BTD Init Failed, error code: 0D

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3 Controller
    Connected to Device: 00:06:F5:65:5C:A3
    L2CAP Connection Request – PSM: 00 11 SCID: 03 58 Identifier: 01
    HID Control Incoming Connection Request
    HID Control Configuration Request
    HID Control Successfully Configured
    L2CAP Connection Request – PSM: 00 13 SCID: 03 59 Identifier: 03
    HID Interrupt Incoming Connection Request
    HID Interrupt Configuration Request
    HID Interrupt Successfully Configured
    Wait For Incoming Connection Request
    Dualshock 3 Controller Enabled

  110. July 28th, 2013 at 11:17 | #111

    @Jeremy
    I think it’s a problem with your dongle as it stops at different places each time. Try to add delay(10) in your main loop. If that doesn’t work, then you need to try another dongle.

  111. Jeremy
    July 28th, 2013 at 18:45 | #112

    Thanks, tried it but no change. I ordered some more dongles about a week ago, will try them when they get here.
    I’m using Windows 7, do you think it might be conflicting with some other software or maybe another device?

  112. July 28th, 2013 at 21:54 | #113

    @Jeremy
    Okay good.
    How would that be possible? It’s not connected to your PC.

  113. Kyle Schigner
    November 9th, 2013 at 16:39 | #114

    Hey I’m having trouble even running the https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/board_qc/board_qc.ino it says that it is having trouble uploading to the board. I am using a arduino leonardo with a usb shield.

  114. November 12th, 2013 at 14:04 | #115

    @Kyle Schigner
    Please write the full error message, so I’m able to help you out.

  115. Mark
    November 29th, 2013 at 15:11 | #116

    Hi,
    When i upload the example ps3 bluetooth sketch, the serial monitor says: PS3 Bluetooth Library Started. it never shows its initialized, or gives an error. it just doenst say anything. when i reset it will just say “PS3 Bluetooth Library Started” again.
    When using the Ps3USB example, it works flawless. the Dongle blinks and i tried multiple ones but they won’t work. I am using an Arduino Mega 2560.

  116. November 29th, 2013 at 15:13 | #117

    @Mark
    You will need to enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging 😉

  117. Enobrega
    December 10th, 2013 at 09:25 | #118

    First of all … Great library and very well documented. I am newbie in Arduino and just started a biped robot project. Following your instructions I was able to connect my PS3 controller and talk with the Arduino Mega. The problem is when I press any button I get several times the same button pressed.
    I am using getButtonPress() but even with a very quick touch in the controller button, I am getting a bunch of signals in the serial monitor.
    Any suggestion?
    thanks

  118. December 10th, 2013 at 15:28 | #119

    @Enobrega
    Simply use getButtonClick as showed in the example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3BT/PS3BT.ino.

    Also documentation for the class can be found here: http://felis.github.io/USB_Host_Shield_2.0/class_p_s3_b_t.html.

  119. Enobrega
    December 10th, 2013 at 20:59 | #120

    @Lauszus
    thanks for your quick response … for my aplication I want to press the button UP to start the walking movement (a biped robot) and the robot must keep walking while the button is pressed. The robot must stop when I release the UP button but, what is happening, the walking movement keep running for at least 4 to 5 steps before the robot stop.
    looking the serial monitor, I can see some commands lines been sent even if the UP buttom is released (4 or 5 lines).
    probably I am doing something wrong!
    thanks for your help!

  120. December 10th, 2013 at 21:03 | #121

    @Enobrega
    Okay, then it it correct to use getButtonPress, as it will return true as long as the button is held down. Please post your code somewhere and I will take a look at it 😉

  121. enobrega
    December 10th, 2013 at 21:31 | #122

    See below.
    sorry for the poor code!
    I am new on Arduino!

    /*
    Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
    For more information visit my blog : http : //blog.tkjelectronics.dk/ or
    send me an e - mail :  kristianl@tkjelectronics.com
    */


    #include
    #include
    int Pos = 0;
    int Cont = 0;

    USB Usb;
    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    PS3BT PS3(&Btd, 0x00, 0x1F, 0x81, 0x00, 0x08, 0x30); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
    boolean printTemperature;
    boolean printAngle;
    void setup() {
      Serial.begin(9600);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 Bluetooth Library Started"));
    }

    void loop() {
      Usb.Task();

      if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

        if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
          Move2();
        }
        if (PS3.getButtonClick(PS)) {
          Serial.print(F("rnPS"));
          PS3.disconnect();
        }
        if (PS3.getButtonClick(TRIANGLE)) {
          Move();
        }
        if (PS3.getButtonClick(CROSS)) {
          Move1();
        }

        if (PS3.getAnalogHat(LeftHatY) &gt; 137 || PS3.getAnalogHat(LeftHatY) &lt; 117) { // Servo 1 Left joystick test
          map(PS3.getAnalogHat(LeftHatY), 0, 255, 255, 0);
          Pos = (PS3.getAnalogHat(LeftHatY) * 13);
          if (Pos & lt; 800) {
            Pos = 800;
          }
          Serial.print(F(&quot; rn#1P&quot;));
          Serial.print(Pos);
          Serial.print(&quot; T100 & quot;);
        }
        if (PS3.getButtonPress(UP)) {
          if (PS3.getButtonPress(UP)) {
            Move2();
          }
          MovePara();
        }
        if (PS3.getButtonPress(CIRCLE)) {
          Move3();
        }
      }
    }
  122. December 10th, 2013 at 23:07 | #123

    @enobrega
    I need to see your full code including your different “Move” functions.

    Please also embed your code like so:
    < code >your code< /code >

    Be sure to remove the whitespaces – I just added them so it would show up correctly for you.

  123. enobrega
    December 10th, 2013 at 23:56 | #124

    @Lauszus

    here it will go it again with Move() functions.
    It is just a code to test the PS3 controller.
    I am using the Arduino Mega connected in a USC32 servo controller board and the serial.print() is sending the move codes to the servo board.
    thanks for your help.

    /*
     Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
     For more information visit my blog: http://blog.tkjelectronics.dk/ or
     send me an e-mail:  kristianl@tkjelectronics.com
     */

    #include
    #include
    int Pos = 0;
    int Cont = 0;
    USB Usb;
    BTD Btd(&amp; Usb); // You have to create the Bluetooth Dongle instance like so
    PS3BT PS3(&amp; Btd, 0x00, 0x1F, 0x81, 0x00, 0x08, 0x30); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
    boolean printTemperature;
    boolean printAngle;
    void setup() {
      Serial.begin(9600);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 Bluetooth Library Started"));
    }
    void loop() {
      Usb.Task();
      if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
        if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
          Move2();
        }
        if (PS3.getButtonClick(PS)) {
          Serial.print(F("rnPS"));
          PS3.disconnect();
        }
        if (PS3.getButtonClick(TRIANGLE)) {
          Move();
        }
        if (PS3.getButtonClick(CROSS)) {
          Move1();
        }
        if (PS3.getAnalogHat(LeftHatY) &gt; 137 || PS3.getAnalogHat(LeftHatY) &lt; 117) { // Servo 1 Left joystick test
          map(PS3.getAnalogHat(LeftHatY), 0, 255, 255, 0);
          Pos = (PS3.getAnalogHat(LeftHatY) * 13);
          if (Pos & lt; 800) {
            Pos = 800;
          }
          Serial.print(F(&quot; rn#1P&quot;));
          Serial.print(Pos);
          Serial.print(&quot; T100 & quot;);
        }
        if (PS3.getButtonPress(UP)) {
          if (PS3.getButtonPress(UP)) {
            Move2();
          }
          MovePara();
        }
        if (PS3.getButtonPress(CIRCLE)) {
          Move3();
        }
      }
    }

    // movement tests
    void Move() {
      Serial.println(&quot; #1P800T1000&quot;);
      delay(1000);
      Serial.println(&quot; #1P2500T1000&quot;);
      delay(1000);
      Serial.println(&quot; #1P800T1000&quot;);
      delay(1000);
      Serial.println(&quot; #1P2500T1000&quot;);
      delay(1000);
      Serial.println(&quot; #1P800T1000&quot;);
      delay(1000);
    }
    void Move1() {
      Serial.println(&quot; #1P1200T1000&quot;);
      delay(1000);
      Serial.println(&quot; #1P800T1000&quot;);
      delay(1000);
    }
    void Move2() {
      Serial.println(&quot; #1P1200#2P1000#3P900#4P1000T700&quot;);
      delay(700);
      Serial.println(&quot; #1P2000#2P2500#3P3000#4P1500T700&quot;);
      delay(700);
    }
    void Move3() {
      Serial.println(&quot; #1P1200#2P1500#3P900#4P1000T100&quot;);
      delay(100);
      Serial.println(&quot; #1P1800#2P800#3P1200#4P1300T100&quot;);
      delay(100);
    }
    void MovePara() {
      Serial.println(&quot; #1P1800#2P1800#3P1800#4P1800T300&quot;);
      delay(300);
    }
  124. December 11th, 2013 at 13:40 | #125

    @enobrega
    The problem is that you should not use all those delays, as you must call Usb.Task() frequently in order to read the input pipe.

    You could do something like this instead:

    uint32_t timer = millis();
    while (millis() - timer <= 1000) // Wait 1000ms
        Usb.Task();

    Also please post your code with the < code > tags, so your code shows up correctly. Please see how I have edited your messages.

  125. Enobrega
    December 13th, 2013 at 02:03 | #126

    @Lauszus
    It works great!
    Thanks for your support!
    Cheers,

  126. December 13th, 2013 at 11:28 | #127

    @Enobrega
    You’re welcome 🙂

  127. Rodrigo
    December 28th, 2013 at 08:03 | #128

    @Lauszus
    Your PID control is amazing! I’m an engineering student and I’d like to continue learning control, do you have any recommendations such as books, articles, etc?
    Thanks and congrats!

  128. December 28th, 2013 at 09:36 | #129

    @Rodrigo
    Thanks. I actually just read about it on the internet. You can start out with this guide: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/ 🙂

  129. icoxbox
    January 7th, 2014 at 16:28 | #130

    Great Library. I’m new to arduino and have successfully ran simple sketches.
    I’m at a road block trying to figure out this next issue.
    I’m trying to turn a digital output on with a input from one of the joysticks.
    This is my sample code. I’m just not sure how to write a digital command with an analog input from the controller.

    #include

    USB Usb;
    /* You can create the instance of the class in two ways */
    PS3USB PS3(&amp;Usb); // This will just create the instance
    //PS3USB PS3(&amp;Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

    int LED = 3;

    boolean printAngle;
    uint8_t state = 0;

    void setup() {
      pinMode(LED, OUTPUT);
      Serial.begin(115200);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 USB Library Started"));
      pinMode(LED, OUTPUT);
    }
    void loop() {
      Usb.Task();

      if (PS3.PS3Connected || PS3.PS3NavigationConnected)
       digitalWrite(LED, PS3.getAnalogHat(LeftHatX)120-155));
       else
       digitalWrite(LED, LOW);

    }

    Also looking for a way to write the 0-255 value on a joystick into a 0-5v output using PWN and smoothing the signal. I have the hardware figured out just need help with how to write the code so 0-255 value from controller relates to 0-256 value from PWM pin on arduino board.

  130. January 7th, 2014 at 19:31 | #131

    @icoxbox
    Can you repost your code. You did not close it correctly. You should use the code tags like so:

    < code > your awesome code < / code>

    Just without the spaces. Note that I edited your original code, so it shows up somewhat correctly.
    If you do that, then WordPress should not screw it up 😉

    Anyway this is how you should do it:

    void loop() {
      Usb.Task();

      if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
        analogWrite(pwmPin, PS3.getAnalogHat(LeftHatX)); // PWM output
        digitalWrite(LED, PS3.getAnalogHat(LeftHatX) > 128 ? 0 : 1); // Control LED using the joystick
      }
    }
  131. icoxbox
    January 7th, 2014 at 21:14 | #132

    Thanks for the info and the code.

    I did try and wrap the code with < code > but forgot the / in the last part.

    could you please explain what the entire line means? I mean I understand the greater than but lost on the ? and then the :

    PS3.getAnalogHat(LeftHatX) > 128 ? 0 : 1);

    Also I’m not sure even how to start the code for the second part of my question on how to
    get the 0-255 signal from the joystick to a 0-255 output on a PWM arduino pin. so that say value 150 on joystick represents 150count on PWM pin.

    Thanks again for the help.

  132. January 8th, 2014 at 00:04 | #133

    @icoxbox
    See: http://stackoverflow.com/questions/4885143/what-does-in-c-mean/4885175#4885175.

    Please see this line of the code:

    analogWrite(pwmPin, PS3.getAnalogHat(LeftHatX));

    That does exactly what you are asking for 😉

  133. icoxbox
    January 8th, 2014 at 23:02 | #134

    Thanks again so much it works great.

    One more question what if I need to invert it?
    I mean instead of 255count on controller =255count pwm from pin.
    It would be 0count from controller=255count pwm from pin

  134. January 10th, 2014 at 20:00 | #135

    @icoxbox
    You can invert it like so:

    analogWrite(pwmPin, 255 - PS3.getAnalogHat(LeftHatX));
  135. icoxbox
    January 14th, 2014 at 07:03 | #136

    Thanks again for that info.

    One more question and I’m quite lost on this one. I’m trying to use the MCP4725 DAC chip on the I2C line to write a 0-5v output from the ps3 controller input from 0-255.

    So I need a smaple code or directions on how to set it up so that when ps3.getAnalogHat is say 127 the DAC needs to output about 2.5v or so.

    Thanks,

  136. January 14th, 2014 at 22:46 | #137

    @icoxbox
    Have you tried Google? 😉 This was the first thing that came up: http://learn.adafruit.com/mcp4725-12-bit-dac-tutorial/using-with-arduino.

  137. icoxbox
    January 15th, 2014 at 04:27 | #138

    I have searched google and thats exactly the chip I’m using in a breakout style.
    I can get a 0-5v signl from the DAC chip depending on the address I send. My issue is trying to interface that so i will send the correct address over I2C to correspond to the posistion of the PS3 controller.

    I mean if PS3 controller for example was at 127 then I would want the DAC to write the address for 2.5v of 0x07FF

  138. January 15th, 2014 at 18:25 | #139

    @icoxbox
    Have you seen this library: https://github.com/adafruit/Adafruit_MCP4725?

    You can simply set the voltage like so:

    uint16_t output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);
    dac.setVoltage(output, false);

    Simply modify this example: https://github.com/adafruit/Adafruit_MCP4725/blob/master/examples/trianglewave/trianglewave.pde.

  139. icoxbox
    January 16th, 2014 at 06:07 | #140

    Ok Thanks again I have two more questions.

    I’m starting to write the code but I notice the usb host shield is on a different baud rate than the DAC chip. Do they need to be the same speed?

    Also I can’t seem to get the usb host shield to work with the new DUE I bought. I have been using an UNO but just bought a Due as well. It states the

    if (Usb.Init() == -1) { class USB’ has no member named init. Also I’m using the programming port

    It will however compile under the UNO with no issues.

    Thanks,

  140. January 17th, 2014 at 19:57 | #141

    @icoxbox
    They communicate using two different protocols. The Usb Host Shield uses SPI and the DAC uses I2C, so I don’t understand what you mean?

    You can not use the Due with the shield, but it might be supported in the future.

  141. icoxbox
    January 18th, 2014 at 00:30 | #142

    So can you do this

    PS3 sends message over spi to arduino
    Arduino reads message then sends mesage to DAC over I2C

    Can they both work at the same time?

    Darn I was hoping the Due would work because it has the on board DAC output I need badly for this project.

    What does it take to talk to the due from the usb host…whats so different from the uno to the due? I thought the codes for uno would work on the due?

    How long down the road until it could be supported because it would solve the extrenal DAC need?

    Thanks again so much for the help

  142. icoxbox
    January 18th, 2014 at 08:31 | #143

    So I tried this code

    */
    /**************************************************************************/
    #include
    #include
    #include

    Adafruit_MCP4725 dac;
    USB Usb;
    /* You can create the instance of the class in two ways */
    PS3USB PS3(&Usb);

    uint16_t output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);


    void setup(void) {
      Serial.begin(9600);
      Serial.println("Hello!");

      // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
      // For MCP4725A0 the address is 0x60 or 0x61
      // For MCP4725A2 the address is 0x64 or 0x65
      dac.begin(0x62);

      Serial.println("Generating a triangle wave");
    }

    void loop(void) {

    dac.setVoltage(output, false);


    }

    I cant seem to get it to change with the controller. I know I’m missing something..I do get 2.5v or so so the DAC is working.

    Thanks,

  143. January 18th, 2014 at 10:01 | #144

    Hi Icobox.
    I think your code should be working, but you forget one very important thing!
    In the main loop (void loop(void)) you have to keep reading the analog hat from the PS3 controller and save it in the output variable.

    Can you please try and add these two lines just about the dac.setVoltage line:

    Usb.Task();
    output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);

    Regards Thomas

  144. January 18th, 2014 at 11:51 | #145

    @icoxbox
    Yes I2C and SPI can work at the same time.

    The Due is totally different from the Uno, as it uses a ARM Cortex-M3 CPU while the Uno uses a AVR microcontroller. Also I don’t own a Due, so I can’t look into it at the moment.

    Yes, just do what Thomas just wrote. You need to put the reading of the PS3 controller inside your loop or it will never get updated.

    Also you should check if PS3 controller is actually connected. This is how I would do it:

    void loop() {
      Usb.Task();
      if (PS3.PS3Connected)
        output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);
      else
        output = 4095 / 2;
      dac.setVoltage(output, false);
    }

    Btw you should embed your code like so: “< code> your code < /code>” – remember to remove the spaces, I just added them, so it shows up correctly.

  145. icoxbox
    January 18th, 2014 at 21:47 | #146

    Ok,

    Thanks for the info.

    If I get this working I wont need need the Due. I would let you borrow it for development for the arduino community. I would just need a shipping address. I know it would take sometime but all that I ask it that once your done with it you would just send it back to me?

    Let me know if that would work.

    Thanks to booth of you

  146. January 18th, 2014 at 23:18 | #147

    @icoxbox
    That would be awesome, but since I am just about to move I need you to send it to a friend of mine. I have send you his address to your email.

  147. icoxbox
    January 19th, 2014 at 00:41 | #148

    I still cant get it to work with the controller it’s putting out 2.5v which is what its supposed to do. here is the code. I also used the serial to see if it was connecting but still not sure how to verify it is.

    /**************************************************************************/
    #include
    #include
    #include

    Adafruit_MCP4725 dac;
    USB Usb;
    /* You can create the instance of the class in two ways */
    PS3USB PS3(&Usb);

    uint16_t output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);


    void setup(void) {
      Serial.begin(115200);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 USB Library Started"));

      dac.begin(0x62);

    }

    void loop() {
      Usb.Task();
      if (PS3.PS3Connected)
        output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);
      else
        output = 4095 / 2;
      dac.setVoltage(output, false);
    }
  148. icoxbox
    January 19th, 2014 at 00:43 | #149

    dang I used the < code> < code/> that time without the spaces not sure what t still shows up like that

  149. January 19th, 2014 at 00:59 | #150

    @icoxbox
    You could start out by simply printing out the output:

    Serial.println(output);

    Also this line:

    uint16_t output = map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 4095);

    Should just be replaced with:

    uint16_t output;

    Have you tried the PS3BT example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3BT/PS3BT.ino. This will show if you are connected properly or not. You should enable serial debugging, as described here: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging.

    Please also read the following section of the readme: https://github.com/felis/USB_Host_Shield_2.0#ps3-library.

    @icoxbox
    No you did not. Use used “< code/>” in the end, but it should be “< /code>” – again without the spaces. Notice that the slash is in the front of “code”.

  150. icoxbox
    January 19th, 2014 at 01:25 | #151

    So I tried the above and still no success. I have read the above links and that library is what I used when I first got the usb sheild. here is the code I’m trying to add this DAC control to. This code works 100% but I need a analog 0-5v output rather than a 0-255 output whch is why I’m using the DAC. Thats also why I boght the due was for the built in DAC but didnt know the shield wouldnt work with it. anyway here is the code

    #include <PS3USB.h>

    USB Usb;
    /* You can create the instance of the class in two ways */
    PS3USB PS3(&Usb); // This will just create the instance
    //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
    int leftsteer = 7;
    int rightsteer = 6;
    int horn = 5;
    int safetyrelay = 4;
    int fwdrev = 3;

    boolean printAngle;
    uint8_t state = 0;

    void setup() {
      pinMode(leftsteer, OUTPUT);
      pinMode(rightsteer, OUTPUT);
      pinMode(horn, OUTPUT);
      pinMode(safetyrelay, OUTPUT);
      pinMode(fwdrev, OUTPUT);

      Serial.begin(115200);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 USB Library Started"));

    }
    void loop() {
      Usb.Task();

      if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
         digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);
         digitalWrite(rightsteer, PS3.getAnalogHat(RightHatX) < 120 ? 1 : 0);
         digitalWrite(horn, PS3.getButtonPress(TRIANGLE));
         digitalWrite(safetyrelay, PS3.getButtonPress(L1));
         analogWrite(fwdrev, PS3.getAnalogHat(LeftHatY));
      }
    }

    The last line is what I’m trying to replace with the DAC line then the project will be done. I do know I have communication with the controller because the above works well.

    Thanks,

  151. January 19th, 2014 at 01:38 | #152

    @icoxbox
    Okay. Did you try to add:

    Serial.println(output);

    In your loop, as I told you? Then I can see if the data is actually changing.

    Also have you tried this example: https://github.com/adafruit/Adafruit_MCP4725/blob/master/examples/trianglewave/trianglewave.pde and confirmed that it actually works as intended?

  152. icoxbox
    January 19th, 2014 at 01:54 | #153

    Yes I did try that and I can see any data but maybe I put it in the wrong heres the two codes together

    #include <PS3USB.h>
    #include <Wire.h>
    #include <Adafruit_MCP4725.h>

    Adafruit_MCP4725 dac;
    USB Usb;
    /* You can create the instance of the class in two ways */
    PS3USB PS3(&Usb); // This will just create the instance
    //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
    int leftsteer = 7;
    int rightsteer = 6;
    int horn = 5;
    int safetyrelay = 4;
    int fwdrev = 3;
    uint16_t output;

    boolean printAngle;
    uint8_t state = 0;

    void setup() {
      pinMode(leftsteer, OUTPUT);
      pinMode(rightsteer, OUTPUT);
      pinMode(horn, OUTPUT);
      pinMode(safetyrelay, OUTPUT);
      pinMode(fwdrev, OUTPUT);

      Serial.begin(115200);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 USB Library Started"));
      Serial.println(output);

      dac.begin(0x62);

    }
    void loop() {
      Usb.Task();
      if (PS3.PS3Connected)
         digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);
         digitalWrite(rightsteer, PS3.getAnalogHat(RightHatX) < 120 ? 1 : 0);
         digitalWrite(horn, PS3.getButtonPress(TRIANGLE));
         digitalWrite(safetyrelay, PS3.getButtonPress(L1));
      if (PS3.PS3Connected) output = map(PS3.getAnalogHat(LeftHatY), 0, 255, 0, 4095);

      else
         output = 4095 / 2;
      dac.setVoltage(output, false);
    }

    Thanks

  153. icoxbox
    January 19th, 2014 at 01:55 | #154

    I still just get 2.5v with no changing

  154. January 19th, 2014 at 01:57 | #155

    @icoxbox
    You should put it in your loop like so:

    void loop() {
      Usb.Task();
      if (PS3.PS3Connected)
         digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);
         digitalWrite(rightsteer, PS3.getAnalogHat(RightHatX) < 120 ? 1 : 0);
         digitalWrite(horn, PS3.getButtonPress(TRIANGLE));
         digitalWrite(safetyrelay, PS3.getButtonPress(L1));
      if (PS3.PS3Connected)
         output = map(PS3.getAnalogHat(LeftHatY), 0, 255, 0, 4095);
      else
         output = 4095 / 2;
      Serial.println(output);
      dac.setVoltage(output, false);
    }
  155. icoxbox
    January 19th, 2014 at 02:19 | #156

    So good and bad news.

    The good news is it works!!

    The bad news is the serial data is very slow to update?
    Not sure why?

    Its not a big deal for my project but it is slow.

    Thanks again and I’m trying to find a god way to ship that Due. I live in the middle of the USA in Iowa so its quite a ways there.

  156. January 19th, 2014 at 02:32 | #157

    @icoxbox
    I know what might be wrong. You forgot brackets after “if (PS3.PS3Connected)”.
    Here is how it should look:

    void loop() {
      Usb.Task();
      if (PS3.PS3Connected) {
         digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);
         digitalWrite(rightsteer, PS3.getAnalogHat(RightHatX) < 120 ? 1 : 0);
         digitalWrite(horn, PS3.getButtonPress(TRIANGLE));
         digitalWrite(safetyrelay, PS3.getButtonPress(L1));
         output = map(PS3.getAnalogHat(LeftHatY), 0, 255, 0, 4095);
      } else
         output = 4095 / 2;
      Serial.println(output);
      dac.setVoltage(output, false);
    }

    I believe that will solve the problem. You might also want to turn the outputs off, when the controller is not connected.

    Just to be sure. Your Arduino is running at 16MHz, right? Because I found a bug in the Adafruit library – will send a pull request to them tomorrow.

    If it is more than $50, then it would be cheaper to just buy one here in EU. I also need to pay import tax if it shipped from outside EU.

  157. icoxbox
    January 19th, 2014 at 03:53 | #158

    Yes that worked

    I def want a way to turn off all outputs including button presses if controller is disconnected

    I may have found a place that will ship for around 20 usd. I’ll keep you posted

  158. icoxbox
    January 19th, 2014 at 09:02 | #159

    So I tried to modify the code and it half works. I tried it on the left steering and if the controller is disconnected it will turn off the output. It will also only activate if the R1 button is pressed.

    However if the R1 button is pressed and the left analog is in range to activate the output and the R1 is released the left analog output stays activated which I need to deactivate if R1 is released.

    Theres probably a simple line Im forgetting but bassically I want the steering out puts only on with activation of R1 and if R1 is not pressed down or communication is lost with controller I want them to turn off.

    I did try a line off

    digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0) & (PS3.getButtonPress(R1);

    but couldn’t get it to compile

    I also added a else statement to test and doing so made it so the last else staement wouldn’t compile.

    I also only tried the else statement on the left output to test.

    Here is the full code without the above line I tried

    #include <PS3USB.h>
    #include <Wire.h>
    #include <Adafruit_MCP4725.h>

    Adafruit_MCP4725 dac;
    USB Usb;
    /* You can create the instance of the class in two ways */
    PS3USB PS3(&Usb); // This will just create the instance
    //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
    int leftsteer = 7;
    int rightsteer = 6;
    int horn = 5;
    int safetyrelay = 4;
    int fwdrev = 3;
    uint16_t output;

    boolean printAngle;
    uint8_t state = 0;

    void setup() {
      pinMode(leftsteer, OUTPUT);
      pinMode(rightsteer, OUTPUT);
      pinMode(horn, OUTPUT);
      pinMode(safetyrelay, OUTPUT);
      pinMode(fwdrev, OUTPUT);

      Serial.begin(115200);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 USB Library Started"));


      dac.begin(0x62);

    }
    void loop() {
      Usb.Task();
      if (PS3.PS3Connected) {
        if (PS3.getButtonPress(R1))
         digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);
      }
      else
       {
         digitalWrite(leftsteer, LOW);
       }
        if (PS3.getButtonPress(R1))
         digitalWrite(rightsteer, PS3.getAnalogHat(RightHatX) < 120 ? 1 : 0);
         digitalWrite(horn, PS3.getButtonPress(TRIANGLE));
         digitalWrite(safetyrelay, PS3.getButtonPress(L1));
      if (PS3.PS3Connected)
        if (PS3.getButtonPress(L1))
         output = map(PS3.getAnalogHat(LeftHatY), 255, 0, 0, 3750);
     ) else
        output = 4095 / 2;
      Serial.println(output);
      dac.setVoltage(output, false);
      }

    Thanks,

  159. January 19th, 2014 at 17:54 | #160

    @icoxbox
    Sorry but this line does not make any sense:

    digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0) & (PS3.getButtonPress(R1);

    What you are using is a bitwise and operator – see: http://arduino.cc/en/Reference/BitwiseAnd.

    I think this is what you are looking for:

    digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 && PS3.getButtonPress(R1) ? 1 : 0);

    Regarding your code. You are missing a lot of brackets! You can only leave them out, if you only got ONE statement underneath.

    Here is the code, as I believe you want it:

    #include <PS3USB.h>
    #include <Wire.h>
    #include <Adafruit_MCP4725.h>

    Adafruit_MCP4725 dac;
    USB Usb;
    /* You can create the instance of the class in two ways */
    PS3USB PS3(&Usb); // This will just create the instance
    //PS3USB PS3(&Usb, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

    int leftsteer = 7;
    int rightsteer = 6;
    int horn = 5;
    int safetyrelay = 4;
    int fwdrev = 3;

    uint16_t output;

    void setup() {
      pinMode(leftsteer, OUTPUT);
      pinMode(rightsteer, OUTPUT);
      pinMode(horn, OUTPUT);
      pinMode(safetyrelay, OUTPUT);
      pinMode(fwdrev, OUTPUT);

      Serial.begin(115200);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 USB Library Started"));

      dac.begin(0x62);
    }
    void loop() {
      Usb.Task();

      if (PS3.PS3Connected) {
        if (PS3.getButtonPress(R1)) {
          digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);
          digitalWrite(rightsteer, PS3.getAnalogHat(RightHatX) < 120 ? 1 : 0);
          digitalWrite(horn, PS3.getButtonPress(TRIANGLE));
          digitalWrite(safetyrelay, PS3.getButtonPress(L1));
        }
        if (PS3.getButtonPress(L1))
          output = map(PS3.getAnalogHat(LeftHatY), 255, 0, 0, 4095);
      } else {
        digitalWrite(leftsteer, LOW);
        output = 4095 / 2;
      }

      Serial.println(output);
      dac.setVoltage(output, false);
    }

    But it’s hard for me to see what you are trying to archive, when there is so many errors in it…

    Also why did you change 4095 to 3750?

    Btw if you are not using a microcontroller running at 16MHz, then you should see the following pull request I just sent: https://github.com/adafruit/Adafruit_MCP4725/pull/2.

  160. icoxbox
    January 19th, 2014 at 22:16 | #161

    I will try that.

    I knew there were errors..still learning the syntax.

    Also I changed it from 4095 to 3750 to cap the voltage at around 4.5v from the DAC.

    I thought the & sign was for and but now I see what its for.

    Thanks

  161. icoxbox
    January 19th, 2014 at 22:39 | #162

    The reason I was adding

    }
      else
       {
         digitalWrite(leftsteer, LOW);

    was to write the output low if controller is disconnected. I’m sure there’s a better way to write all outputs low if controller is disconnected.

    The second issue I have is I need the output to write low or turn off if the either input buttons are not pressed.

    As it stands now if I press the R1 button and then move the right analog left and let go of the R1 button the left analog output is still high or on and I need it to turn off if R1 button is depressed.

    I looked through your original example and couldn’t find a command line for buttons depressed so I’m not sure what to do for that?

    Thanks,

  162. January 21st, 2014 at 15:28 | #163

    @icoxbox
    Here is how you could do that:

    void loop() {
      Usb.Task();

      if (PS3.PS3Connected && PS3.getButtonPress(R1)) {
        digitalWrite(leftsteer, PS3.getAnalogHat(RightHatX) > 160 ? 1 : 0);
        digitalWrite(rightsteer, PS3.getAnalogHat(RightHatX) < 120 ? 1 : 0);
        digitalWrite(horn, PS3.getButtonPress(TRIANGLE));
        digitalWrite(safetyrelay, PS3.getButtonPress(L1));
      } else {
        digitalWrite(leftsteer, LOW);
        digitalWrite(rightsteer, LOW);
        digitalWrite(horn, LOW);
        digitalWrite(safetyrelay, LOW);
      }

      if (PS3.PS3Connected && PS3.getButtonPress(L1))
        output = map(PS3.getAnalogHat(LeftHatY), 255, 0, 0, 4095);
      else
        output = 4095 / 2;

      Serial.println(output);
      dac.setVoltage(output, false);
    }

    If you wanted to check if a button was depressed/released you could just check it like so:

    if (!PS3.getButtonPress(L1))

    Note this is the same as:

    if (PS3.getButtonPress(L1) == false)

    But you will see the first one more often, as it is much more compact.

  163. icoxbox
    January 21st, 2014 at 23:10 | #164

    Thanks once again.

    The code is 98% done. I just need help on this last one. I have tried for about 4 hours and cant get it to work right.

    I want the map to be

    output = map(PS3.getAnalogHat(LeftHatY), 106, 0, 0, 3750);

    That works great. It starts 0v at posistion 104 and ends around 4.5v at posistion 0.

    what I need added is the range 105-255 = 0 as well.

    so bassically anything higher than posistion 104 the out put will = 0v

    I tried

    output = map(PS3.getAnalogHat(LeftHatY), 255-105 , 0 , 0, 3750);

    but that didn’t work but thats what I’m going for.

    Also shipping will be too high for the Due so I will be sending 40 dollars towards Due support on the usb shield once this project is complete.

    Thanks again for your help

  164. January 22nd, 2014 at 01:16 | #165

    @icoxbox
    You can just use the constrain macro: http://arduino.cc/en/reference/constrain like so:

    output = map(constrain(PS3.getAnalogHat(LeftHatY), 0, 104), 104, 0, 0, 3750);
  165. icoxbox
    January 22nd, 2014 at 16:59 | #166

    so that won’t compile.

    Not sure whats going on

    C:Program FilesArduinohardwarearduinocoresarduino/Arduino.h: In function ‘void loop()’:
    C:Program FilesArduinohardwarearduinocoresarduino/Arduino.h:209: error: too few arguments to function ‘long int map(long int, long int, long int, long int, long int)’
    PS3USBpusher32:61: error: at this point in file
    PS3USBpusher32:61: error: expected `;’ before ‘)’ token

    Thats the error I get.

    Thanks,

  166. icoxbox
    January 22nd, 2014 at 18:10 | #167

    So I got this line to compile

    output = map((PS3.getAnalogHat(LeftHatY), 0, 104), 104, 0, 0, 3750);

    but it didnt work it always reads zero now

    Thanks,

  167. January 22nd, 2014 at 18:18 | #168

    @icoxbox
    Did you copy the code in correctly? I just tried and it compiles fine.

    Anyway I think you should change it to:

    output = 3750 - map(constrain(PS3.getAnalogHat(LeftHatY), 0, 104), 0, 104, 0, 3750);
  168. icoxbox
    January 22nd, 2014 at 21:11 | #169

    Sorry had it written wrong works great.

    what would I gain if I changed it to the above?

    Thanks

  169. January 22nd, 2014 at 23:26 | #170

    @icoxbox
    Just try it and you will see 😉

  170. February 25th, 2014 at 12:18 | #171

    @icoxbox
    I just added support for the Due, but since I do not own one I can not test it. Could you follow the instructions here: https://github.com/felis/USB_Host_Shield_2.0/issues/76#issuecomment-35995738 and let me know if it works?

  171. Manu
    April 16th, 2014 at 03:03 | #172

    Hi,

    I’m having problems trying to connect the ps3 controller with the dongle. When I run the PS3USB example the controller works fine, but when I try to use it with the dongle I get the following message:

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:15:83:3D:0A:57
    Wait For Incoming Connection Request
    Dualshock 3 Controller Connected
    Bluetooth Address was set to: 00:15:83:3D:0A:57
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:15:83:3D:0A:57
    Wait For Incoming Connection Request
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3 Controller
    Connected to Device: 00:26:5C:82:A4:CA
    HID Control Incoming Connection Request
    HID Control Configuration Request
    HID Control Successfully Configured
    HID Interrupt Incoming Connection Request
    HID Interrupt Configuration Request
    HID Interrupt Successfully Configured
    Wait For Incoming Connection Request
    Dualshock 3 Controller Enabled

    Then it stasts to pop out this without stopping:

    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0

    Please help me!

  172. April 17th, 2014 at 15:01 | #173

    @Manu
    That is caused by a problem with your dongle, as it doesn’t support EDR (Enhanced Data Rate), please try another one.

  173. Bundit
    April 26th, 2014 at 18:36 | #174

    I use Arduino ADK R3 and a bluetooth adapter, but arduino stops at “PS3 Bluetooth Library Started” and does not go forward. what ‘s wrong ?

  174. Bundit
    April 26th, 2014 at 18:40 | #175

    Sorry, it is Arduino Uno R3, not ADK.

  175. April 26th, 2014 at 22:30 | #176

    @Bundit
    Can you please try and enable the Debugging functionality.
    To turn it on simply change ENABLE_UHS_DEBUGGING to 1 in settings.h like so:

    #define ENABLE_UHS_DEBUGGING 1

    This should give you some more information about what is going on and if your Bluetooth dongle is recognized at all.

  176. Jasper
    August 25th, 2014 at 08:31 | #177

    my bluetooth dongle just arrived and i ran the PS3BT sketch with the dongle plugged in and it just says “PS3 bluetooth library started” and then nothing else. it is really confusing me because i have only encountered one other person on the internet with this problem but no one could answer their question.

  177. August 25th, 2014 at 23:21 | #178

    @Jasper
    You need to enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging – also see the comment just above yours.

  178. Jasper
    August 26th, 2014 at 02:17 | #179

    sorry about this but i am not sure how to find the settings.h file. is does it come with the usb host shield library.

  179. August 26th, 2014 at 03:25 | #180
  180. Jasper
    August 26th, 2014 at 05:57 | #181

    sorry for all the trouble but i have found the settings.h file in the USB host shield library but am unsure how to open it. i am not very experienced so your help is very much appreciated

  181. August 26th, 2014 at 06:07 | #182

    @Jasper
    Just open it in any text editor. It’s just a text file 😉

  182. Jasper
    August 26th, 2014 at 09:15 | #183

    thanks kristian, i got it connected and working but i have one more question. i am building a quadcopter and was going to use this as the controller. in the code for the quadcopter, how would i use the buttons and joysticks on the remote to control things such as motors and led’s.

  183. August 26th, 2014 at 18:19 | #184

    @Jasper
    Can you share some of your code, then it might be easier for me to help you out. Btw building a quadcopter flight controller is a very complicated task and not something I would recommend for a beginner. Also note that Bluetooth has limited range, so I would not recommend it for remote control of a quadcopter. It should only be used for instance to change different parameters etc.

  184. Jasper
    August 27th, 2014 at 00:47 | #185

    i have not yet started the code because i just wanted to make sure i could connect the ps3 remote up and get it working. now that i have done that i am going to start the code. the only thing i cant figure out is how to input the digital and analog buttons into the code. if i can figure that out, then i have petty much finished the quadcopter.

  185. August 27th, 2014 at 03:25 | #186
  186. Jasper
    August 27th, 2014 at 06:09 | #187

    for example if i was to code it to turn an led
    on when the cross button is pressed, would this work:

    #include
    #include

    int ledpin = 13;

    void setup() {

    pinMode(ledpin, OUTPUT);
    }

    void loop() {

    if (PS3.getButtonClick(Cross))
    digitalWrite(ledpin, HIGH)

    }

  187. Jasper
    August 27th, 2014 at 06:19 | #188

    sorry it didn’t let me put anything after the #include’s but there was the include PS3BT line and the include usbhub line.

  188. August 27th, 2014 at 06:22 | #189

    @Jasper
    No. You should use “getButtonPress”. Also you forgot to initialize the library and call Usb.Task() in the loop.

    Here is some code that should work:

    #include <PS3BT.h>
    #include <usbhub.h>

    USB Usb;
    //USBHub Hub1(&Usb); // Some dongles have a hub inside

    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    PS3BT PS3(&Btd); // This will just create the instance

    uint8_t ledpin = 2;

    void setup() {
      Serial.begin(115200);
      while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while (1); //halt
      }
      Serial.print(F("rnPS3 Bluetooth Library Started"));
    }

    void loop() {
      Usb.Task();
      if (PS3.PS3Connected && PS3.getButtonPress(CROSS))
        digitalWrite(ledpin, HIGH);
      else
        digitalWrite(ledpin, LOW);
    }

    PS: You need to embed the code inside:
    < code>
    your code
    < /code>

    Just remember to remote the spaces I have put in before “code”, then it should show up correctly.

  189. Jasper
    August 27th, 2014 at 09:36 | #190

    thank you for the code but it keeps saying ‘Cross” was not declared in this scope. this is another thing i need cleared up for me. i know that you have to include other files for it to refer to but i just can’t figure out what is wrong with it

  190. Jasper
    August 27th, 2014 at 09:43 | #191

    nevermid, i figured it out. cheers

  191. Jasper
    August 27th, 2014 at 10:00 | #192

    sorry about the above^^. i haven’t figured it out yet.
    i added the led pin int and uploaded it. after upload it says that the remote is connected but when i hit the cross button it the led does not change.

  192. August 27th, 2014 at 18:08 | #193

    @Jasper
    Sorry about that. I have updated my comment, so it should work now. Please note that if you are using an Arduino Uno, then you can NOT connect a LED to pin 13, 12, 11, 10 or 9 as these are all used by the shield.

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

  193. Jasper
    August 28th, 2014 at 10:20 | #194

    i tried the updated code but nothing has changed. i changed the button to the triangle to see if the controller was broken but i get the same response. i noticed that pins 1, 10, 11, 12 and 13 turn the led on even without uploading anything to the board. is this because they are used by the shield.

  194. August 28th, 2014 at 17:35 | #195

    @Jasper
    Please enable serial debugging, so I can see what is going on!

    Pin 1 lights up because it is used as TX. As I said pins 9, 10, 11, 12 and 13 are all used by the shield on the Uno, so please do not connect anything to those pins!

  195. Jasper
    August 29th, 2014 at 03:24 | #196

    i have enabled serial debugging but nothing changes

  196. September 1st, 2014 at 07:45 | #197

    @Jasper
    What does it print when you plug in the dongle?

  197. nickthecook
    September 3rd, 2014 at 05:23 | #198

    Hi, thanks for the library, I look forward to using it to make use of these three PS3 controllers I have lying around!

    Unfortunately, I have run into the same problem as Josh did a while back (a couple pages ago in these comments). With serial debugging enabled, and the dongle plugged in, I see this:

    HID Bluetooth Library Started
    Unknown Device Connected – VID: 0A5C PID: 4500
    BTD Init Failed, error code: D1

    It also looks very similar to this:

    https://github.com/felis/USB_Host_Shield_2.0/issues/58

    You resolved that issue by having the bug reporter try a branch that I can’t find on github any more. That was about a year ago, so I assume your changes made it to the master I just downloaded today. Like the user on that issue, I’m using an Uno, and having trouble uploading sketches greater than around 28080B (the size of the HID example with serial debugging enabled, and EXTRADEBUG disabled). I can’t seem to upload the PS3BT example with serial debugging enabled or the HID example with both serial and extra debug enabled.

    Any idea what might be causing error D1?

    I have an Android device if you’d like blueterm output or anything like that. Let me know.

    Nick

  198. September 3rd, 2014 at 06:08 | #199

    @nickthecook
    This has indeed been fixed, but it looks like it is not extracting all the endpoints, as it is returning here: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L229-L230.

    Please run the following example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/USB_desc/USB_desc.ino and post the output.

  199. nickthecook
    September 3rd, 2014 at 23:37 | #200

    Here we go:

    Start

    01

    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0200
    Device class: 09
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 08
    Vendor ID: 0A5C
    Product ID: 4500
    Revision ID: 0100
    Mfg.string index: 01
    Prod.string index: 02
    Serial number index: 00
    Number of conf.: 01

    Configuration descriptor:
    Total length: 0019
    Num.intf: 01
    Conf.value: 01
    Conf.string: 00
    Attr.: A0
    Max.pwr: 2F

    Interface descriptor:
    Intf.number: 00
    Alt.: 00
    Endpoints: 01
    Intf. Class: 09
    Intf. Subclass: 00
    Intf. Protocol: 00
    Intf.string: 00

    Endpoint descriptor:
    Endpoint address: 81
    Attr.: 03
    Max.pkt size: 0001
    Polling interval: FF

    Addr:1(0.0.1)

  200. September 3rd, 2014 at 23:45 | #201

    @nickthecook
    It looks like your dongle presents itself as a USB Hub, please uncomment the following line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/PS3BT/PS3BT.ino#L15.

  201. nickthecook
    September 4th, 2014 at 00:26 | #202

    I also picked up another dongle today, and although I got the Sixaxis paired, PS3BT isn’t reliably able to initialize the new dongle.

    If I plug in the dongle, then power the arduino, the dongle will not be initialized. Tested about 20 times, 100% failure in this case.

    The only other way I can get it to initialize is to open the serial monitor. If I power up the arduino from a lipo, without USB connected, I can wait for 5 minutes and the light on the dongle never comes on. If I connect the USB cable to the arduino in this state, I can wait for a couple more minutes and nothing will happen. HOWEVER, as soon as I open the serial monitor, the dongle begins to function within a few seconds – light blinking, I can connect sixaxis. In this case, nothing is printed on the serial monitor. I have removed all Serial.* calls from the code. I even created my own bttest.ino which had only enough code from PS3BT.ino to print the hat status, no occurrences of “Serial” anywhere in the code, and the same problem occurs – the dongle won’t initialize until I open the serial monitor, but as soon as I do, it comes up without a problem.

    What’s up??

  202. nickthecook
    September 4th, 2014 at 00:47 | #203

    Uncommenting the hub line did it for dongle #1! Thanks. 🙂

    Looks like it tried devices until it found the right one. Nice.

    PS3 Bluetooth Library Started
    Unknown Device Connected – VID: 0A5C PID: 4502
    BTD Init Failed, error code: D1

    Unknown Device Connected – VID: 0A5C PID: 4503
    BTD Init Failed, error code: D1

    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:0A:3A:83:A6:62
    Wait For Incoming Connection Request

    If you want to track down what’s wrong with the other dongle, I’ll provide info and testing. But if not, no worries – I have one working now.

    Nick

  203. September 4th, 2014 at 07:20 | #204

    @nickthecook
    That sounds really strange! I have never had that issue or have anyone else reporting it. I you 100% sure that is really the cause? Note that the Balanduino uses the PS3BT code all the time and it has no issue, so it’s more likely a hardware issue on your side than a software issue.

    @nickthecook
    Nice 🙂 Could you uncomment this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/USB_desc/USB_desc.ino#L10 and run the USB_desc.ino example again? It would be fun to see what the other two devices are 🙂

  204. nickthecook
    September 4th, 2014 at 15:11 | #205

    It is really strange. There’s a possibility that something other than the serial monitor and reset button that is changing between tests and affecting the results, but I can’t think of what it might be. Here’s the device info from the kernel log on a linux box for this strange dongle:

    Sep 4 09:41:34 xenon kernel: [1377044.875737] usb 2-1.2: new high-speed USB device number 10 using ehci-pci
    Sep 4 09:41:34 xenon kernel: [1377044.968794] usb 2-1.2: New USB device found, idVendor=22b8, idProduct=2e62
    Sep 4 09:41:34 xenon kernel: [1377044.968805] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    Sep 4 09:41:34 xenon kernel: [1377044.968811] usb 2-1.2: Product: XT1058
    Sep 4 09:41:34 xenon kernel: [1377044.968817] usb 2-1.2: Manufacturer: motorola
    Sep 4 09:41:34 xenon kernel: [1377044.968823] usb 2-1.2: SerialNumber: TA17606B4R
    Sep 4 09:45:55 xenon kernel: [1377306.032580] usb 2-1.2: USB disconnect, device number 10
    Sep 4 09:56:13 xenon kernel: [1377924.655929] usb 2-1.2: new full-speed USB device number 11 using ehci-pci
    Sep 4 09:56:14 xenon kernel: [1377924.891055] usb 2-1.2: New USB device found, idVendor=0a12, idProduct=0001
    Sep 4 09:56:14 xenon kernel: [1377924.891063] usb 2-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
    Sep 4 09:56:14 xenon kernel: [1377924.891068] usb 2-1.2: Product: CSR8510 A10
    Sep 4 09:56:14 xenon kernel: [1377925.044687] usbcore: registered new interface driver btusb

    Here’s a picture: https://tinytown.ca/owncloud/public.php?service=files&t=6a051097b2d499c7d3ed4e9e31e6aa04

    I got it at The Source, and it’s branded NexxTech, but the same hardware probably shows up in a lot of places.

    For the one that works, I will post the output you asked for this evening. We might find something interesting!

  205. nickthecook
    September 7th, 2014 at 03:07 | #206

    Here’s the output for the dongle that worked when I uncommented the UsbHub line:

    Start

    01

    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0200
    Device class: 09
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 08
    Vendor ID: 0A5C
    Product ID: 4500
    Revision ID: 0100
    Mfg.string index: 01
    Prod.string index: 02
    Serial number index: 00
    Number of conf.: 01

    Configuration descriptor:
    Total length: 0019
    Num.intf: 01
    Conf.value: 01
    Conf.string: 00
    Attr.: A0
    Max.pwr: 2F

    Interface descriptor:
    Intf.number: 00
    Alt.: 00
    Endpoints: 01
    Intf. Class: 09
    Intf. Subclass: 00
    Intf. Protocol: 00
    Intf.string: 00

    Endpoint descriptor:
    Endpoint address: 81
    Attr.: 03
    Max.pkt size: 0001
    Polling interval: FF

    Addr:1(0.0.1)

    It’s a Belkin dongle, 2-4 years old. Here’s the kernel log that appears when I plug it in:

    Sep 5 19:57:13 xenon kernel: [894084.457937] usb 7-3: new full-speed USB device number 81 using ohci-pci
    Sep 5 19:57:13 xenon kernel: [894084.631050] usb 7-3: New USB device found, idVendor=0a5c, idProduct=4500
    Sep 5 19:57:13 xenon kernel: [894084.631054] usb 7-3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    Sep 5 19:57:13 xenon kernel: [894084.631056] usb 7-3: Product: BCM2046B1
    Sep 5 19:57:13 xenon kernel: [894084.631058] usb 7-3: Manufacturer: Broadcom
    Sep 5 19:57:13 xenon kernel: [894084.633086] hub 7-3:1.0: USB hub found
    Sep 5 19:57:13 xenon kernel: [894084.635052] hub 7-3:1.0: 3 ports detected
    Sep 5 19:57:13 xenon kernel: [894084.922078] usb 7-3.1: new full-speed USB device number 82 using ohci-pci
    Sep 5 19:57:14 xenon kernel: [894085.121092] usb 7-3.1: New USB device found, idVendor=0a5c, idProduct=4502
    Sep 5 19:57:14 xenon kernel: [894085.121095] usb 7-3.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
    Sep 5 19:57:14 xenon kernel: [894085.127368] input: HID 0a5c:4502 as /devices/pci0000:00/0000:00:16.0/usb7/7-3/7-3.1/7-3.1:1.0/input/input40
    Sep 5 19:57:14 xenon kernel: [894085.127546] hid-generic 0003:0A5C:4502.001B: input,hidraw3: USB HID v1.11 Keyboard [HID 0a5c:4502] on usb-0000:00:16.0-3.1/input0
    Sep 5 19:57:14 xenon kernel: [894085.202101] usb 7-3.2: new full-speed USB device number 83 using ohci-pci
    Sep 5 19:57:14 xenon kernel: [894085.309103] usb 7-3.2: New USB device found, idVendor=0a5c, idProduct=4503
    Sep 5 19:57:14 xenon kernel: [894085.309106] usb 7-3.2: New USB device strings: Mfr=0, Product=0, SerialNumber=0
    Sep 5 19:57:14 xenon kernel: [894085.316433] input: HID 0a5c:4503 as /devices/pci0000:00/0000:00:16.0/usb7/7-3/7-3.2/7-3.2:1.0/input/input41
    Sep 5 19:57:14 xenon kernel: [894085.316674] hid-generic 0003:0A5C:4503.001C: input,hidraw6: USB HID v1.11 Mouse [HID 0a5c:4503] on usb-0000:00:16.0-3.2/input0
    Sep 5 19:57:14 xenon kernel: [894085.390122] usb 7-3.3: new full-speed USB device number 84 using ohci-pci
    Sep 5 19:57:14 xenon kernel: [894085.505119] usb 7-3.3: New USB device found, idVendor=050d, idProduct=016a
    Sep 5 19:57:14 xenon kernel: [894085.505121] usb 7-3.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    Sep 5 19:57:14 xenon kernel: [894085.505124] usb 7-3.3: Product: BLUETOOTH USB +EDR ADAPTER v2.1 UHE
    Sep 5 19:57:14 xenon kernel: [894085.505126] usb 7-3.3: Manufacturer: Broadcom Corp
    Sep 5 19:57:14 xenon kernel: [894085.505127] usb 7-3.3: SerialNumber: 000A3A83A662
    Sep 5 19:57:14 xenon kernel: [894085.524113] usb 7-3.1: input irq status -75 received
    Sep 5 19:57:14 xenon kernel: [894085.540120] usb 7-3.1: input irq status -75 received
    Sep 5 19:57:14 xenon kernel: [894085.556122] usb 7-3.1: input irq status -75 received
    Sep 5 19:57:14 xenon kernel: [894085.572117] usb 7-3.1: input irq status -75 received

    Why does there appear to be a keyboard and mouse in there? This isn’t even a dongle that came with a keyboard and mouse, it was all by itself.

  206. dhanraj choudhary
    September 8th, 2014 at 17:46 | #207

    hello!

    I am trying to interface a ps3 controller via bluetooth to arduino mega 2560 adk.BUt didn?t change the data coming from the ps3 controller.
    after uploading the code i get result on serial monitor as given below.

    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
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1B:10:00:2A:EC
    Wait For Incoming Connection Request
    Keyboard is connecting
    Incoming Connection Request
    Remote Name: PLAYSTA
    Connected to Device: 00:26:5C:D1:B8:D6
    HID Control Incoming Connection Request
    HID Control Successfully Configured
    HID Interrupt Incoming Connection Request
    HID Interrupt Successfully Configured
    Wait For Incoming Connection Request
    Dualshock 3 Controller Enabled

    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    .
    .
    .
    NEED HELP!

  207. September 9th, 2014 at 00:02 | #208

    @nickthecook
    You forgot to uncomment this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/USB_desc/USB_desc.ino#L10 which enables Hub support 😉 Anyway that is indeed strange. Perhaps they are bundling the dongle with something else as well.

    @dhanraj choudhary
    This means that your dongle does not support 2.0+EDR – basically you will need a new dongle! If you uncomment this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/PS3BT.cpp#L21 and reupload you will see that the last couple of bytes are just always 0, this is because the dongle doesn’t support reading the entire report sent from the controller.

  208. Akshay
    October 9th, 2014 at 21:55 | #209

    I am having the same problem as nickthecook has…….
    It is showing that

    PS3 Bluetooth Library Started
    Unknown Device Connected – VID: 040B PID: 2013
    BTD Init Failed, error code: D1

    please suggest me solution as earlier as you can.
    please mail you reply if you can…..
    Waiting

  209. October 10th, 2014 at 01:54 | #210
  210. Ashwin
    October 18th, 2014 at 18:17 | #211

    @Lauszus
    Exactly same problem as Akshay….

    Start

    01

    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0110
    Device class: 00
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 08
    Vendor ID: 040B
    Product ID: 2013
    Revision ID: 0200
    Mfg.string index: 00
    Prod.string index: 01
    Serial number index: 00
    Number of conf.: 01

    Configuration descriptor:
    Total length: 003B
    Num.intf: 02
    Conf.value: 01
    Conf.string: 00
    Attr.: A0
    Max.pwr: 32

    Interface descriptor:
    Intf.number: 00
    Alt.: 00
    Endpoints: 01
    Intf. Class: 03
    Intf. Subclass: 01
    Intf. Protocol: 01
    Intf.string: 00
    Unknown descriptor:
    Length: 09
    Type: 21
    Contents: 100100012243000705

    Endpoint descriptor:
    Endpoint address: 81
    Attr.: 03
    Max.pkt size: 0008
    Polling interval: 0A

    Interface descriptor:
    Intf.number: 01
    Alt.: 00
    Endpoints: 01
    Intf. Class: 03
    Intf. Subclass: 01
    Intf. Protocol: 02
    Intf.string: 00
    Unknown descriptor:
    Length: 09
    Type: 21
    Contents: 1001000122B9000705

    Endpoint descriptor:
    Endpoint address: 82
    Attr.: 03
    Max.pkt size: 0008
    Polling interval: 0A

    Addr:1(0.0.1)

    Above mentioned is the output for the USB_Desc you demanded from him.
    Please Help. Thank You

  211. October 18th, 2014 at 19:52 | #212

    @Ashwin
    I’m afraid that you will have to find another dongle.

  212. Ashwin
    October 18th, 2014 at 19:57 | #213

    @Lauszus
    As in the dongle is having some issues or it doesn’t support PS3…? Because I use it for everyday purpose with Mouse and Keyboard and it works fine….

  213. October 18th, 2014 at 19:58 | #214

    @Ashwin
    To me it looks like it doesn’t present itself correctly. Did you try to uncomment this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/USB_desc/USB_desc.ino#L10 and see if the output changes? Also please connect an external power supply to your Arduino.

  214. Ashwin
    October 18th, 2014 at 20:02 | #215

    @Lauszus
    Ohhh… So external power supply other than USB from Laptop is compulsory..?? And do you think it might be some problem with my connections.. Because I’m not using the Arduino USB Host Shield.. I have to make connection using 1 to 1 connectors..

  215. Ashwin
    October 18th, 2014 at 20:10 | #216

    @Lauszus
    The above given output is with that line uncommented…

  216. October 18th, 2014 at 20:15 | #217

    @Ashwin
    No, it depends a lot on your laptop. By USB spec each usb port can only provide 500mA, so if you have a lot of stuff connected to the Arduino and the device connected to the USB Host shield tries to draw 500mA, then the voltage will most likely drop.

    What shield are you using? There is a design flaw with the Sparkfun shield, so you will have to use an external powersupply, as their is a 5V regulator on the shield connected to VIN.

    But please consider buying the official shield in order to support the developers of the actual hardware and software.

  217. Ashwin
    October 18th, 2014 at 20:22 | #218

    @Lauszus
    Oh.. Thank you for your help so far… I will surely buy the original shield, but I was in a kind of hurry and bought the one which was available to me (BhashaTech ADK Adapter)… I will try with external power supply and let you know… Thank You once again…

  218. October 18th, 2014 at 20:32 | #219

    @Ashwin
    Okay thanks 🙂 You are welcome!

  219. Kim
    January 10th, 2015 at 08:32 | #220

    I am trying to interface a duplicate ps3 controller. the controller is giving false reaadings continously.
    This is the output on the serial monitor:

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:15:83:3D:0A:57
    Wait For Incoming Connection Request
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3 Controller
    Connected to Device: 00:26:5C:10:2D:E6
    HID Control Incoming Connection Request
    HID Control Configuration Request
    HID Control Successfully Configured
    HID Interrupt Incoming Connection Request
    HID Interrupt Configuration Request
    HID Interrupt Successfully Configured
    Wait For Incoming Connection Request
    Dualshock 3 Controller Enabled

    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1

    the leds on the controller are still continously flashing.
    also i am using a dongle with v2.0+EDR
    Thanking in advance
    hope for a speedy reply.

  220. January 12th, 2015 at 15:14 | #221

    @Kim
    Unfortunately this means that your dongle does not support 2.0+EDR, so you will need to buy another dongle. A list of dongles can be found here: https://github.com/felis/USB_Host_Shield_2.0/wiki/Bluetooth-dongles.

  221. Jordan Broome
    January 27th, 2015 at 00:27 | #222

    So I’m having some issues. I have and Arduino Uno and an Arduino Mega2560. I connect the usb host shield (directly from http://arduino.cc/en/Main/ArduinoUSBHostShield) to either shield. I download the libraries form Arduino and run the PS3BT code with a compatible dongle. I get the message PS3 Bluetooth Library Started, but no info on the MAC address or any of that. Any advice would be greatly appreciated!

  222. January 27th, 2015 at 04:59 | #223

    @Jordan Broome
    Please enable serial debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging.

    Please consider buying the official shield to support the development of the library.

  223. DucTor
    January 28th, 2015 at 20:49 | #224

    Hello
    tnx for great work!
    I have got most of the function to work, both with only usb cable on a mini and uno. today i got usb dongles and they worked fine also on first try. But, I cant figure out how to use the rumble function in the controller… I read somewhere here that its the same way as whit the leds on the controller. They worked with the example code. I cant fine any examples with the rumble function and my understandg of the lib code is to poor to get the right syntax on how to use the setRumbleOn and setRumbleOff function..

    This is what i want, use an input on the Uno to active the rumble on the controller.
    This is my current code :

    #include <PS3BT.h>
    USB Usb;
    /* You can create the instance of the class in two ways */
    //PS3USB PS3(&Usb); // This will just create the instance
    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    PS3BT PS3(&Btd); // This will just create the instance
    //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

    #include <Servo.h>
    Servo servo;  // create servo object to control a servo

    const uint8_t LED = 2;
    const uint8_t Shake = 3;

    // variables will change:
    //int buttonState = 0;         // variable for reading the pushbutton status

    void setup() {
      pinMode(LED, OUTPUT);   // just a led to test buttons..
      pinMode(Shake, INPUT);  // the input I wanna use to activate the rumble in the controller (
      Serial.begin(115200);
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while(1); //halt
      }
      servo.attach(8); // Use pin 8, as signal pin
      Serial.print(F("rnPS3 Bluetooth Library Started"));
    }

    void loop() {
    //  setRumbleOn();
      Usb.Task();
      if (PS3.PS3Connected)
        digitalWrite(LED, PS3.getButtonPress(CROSS));
      else
        digitalWrite(LED, LOW);
      if (PS3.PS3Connected)
        servo.write(map(PS3.getAnalogHat(LeftHatX), 0, 255, 170, 0));
      else
        servo.write(85); // Set to middle position

    }
    void setRumbleOn();

    So may question is, what is the code to activate rumble in the controller?
    my post about the topic on http://forum.arduino.cc/index.php?topic=295755.0

  224. DucTor
    January 29th, 2015 at 00:48 | #225

    After some testing I find out that the PS3.getAnalogButton(R2_ANALOG) and PS3.getAngle(Pitch) do not work with the library but works fine with the library. Meaning when I’m using the controller connected with usb cabel all functions works, but not vhen using wireless..

    Have changed my code a little bit with the input and output to use more pwm as servocontrol.

    #include <PS3BT.h>
    USB Usb;
    /* You can create the instance of the class in two ways */
    //PS3USB PS3(&Usb); // This will just create the instance
    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    PS3BT PS3(&Btd); // This will just create the instance
    //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

    #include <Servo.h>
    Servo servo1;  // create servo object to control a servo
    Servo servo2;  // create servo object to control a servo
    Servo servo3;  // create servo object to control a servo

    const uint8_t LED = 2;
    const uint8_t Shake = 4;
    const uint8_t Buzzer = 7;

    // variables will change:
    //int buttonState = 0;         // variable for reading the pushbutton status

    void setup() {
      pinMode(LED, OUTPUT);  // just a led to test buttons..
      pinMode(Buzzer, OUTPUT);    // A buzzer connected to the output
      pinMode(Shake, INPUT);  // the input I wanna use to activate the rumble in the controller(an IR-08H sensor is connected)
      Serial.begin(115200);
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while(1); //halt
      }
      servo1.attach(3); // Use pin 3, as signal pin
      servo2.attach(5); // Use pin 5, as signal pin
      servo3.attach(6); // Use pin 6, as signal pin
      Serial.print(F("rnPS3 Bluetooth Library Started"));
    }

    void loop() {
      //  setRumbleOn();
      Usb.Task();
      if (PS3.PS3Connected)
        digitalWrite(LED, PS3.getButtonPress(CROSS));
      else
        digitalWrite(LED, LOW);
      if (PS3.PS3Connected)
        servo1.write(map(PS3.getAnalogButton(R2_ANALOG), 0, 255, 180, 0));
      else
        servo1.write(180); // Set to position
      if (PS3.PS3Connected)
        servo2.write(map(PS3.getAnalogHat(RightHatX), 0, 255, 180, 0));
      else
        servo2.write(90); // Set to position
      if (PS3.PS3Connected)
        servo3.write(map(PS3.getAngle(Pitch), 0, 255, 180, 0));
      else
        servo3.write(90); // Set to position
      //read the input value into a variable
      int sensorVal = digitalRead(4);
      if (sensorVal == HIGH) {
        digitalWrite(Buzzer, HIGH);
      }
      else {
        digitalWrite(Buzzer, LOW);
      }
    }
    void setRumbleOn();

    Do I have to change things inside the library files?

  225. DucTor
    January 29th, 2015 at 03:21 | #226

    Just realized that i had an older USB Host shield library installed..
    Removed that one and installed USB Host Shield 2.0 Master.

    But still the same.. only differense I can se is that the function PS3.getAnalogButton(R2_ANALOG) have a new name like this PS3.getAnalogButton(R2) and my Binary sketch size: 31 248 bytes (of a 32 256 byte maximum)
    has got alot bigger… with the first vesion I used the file was around 26 Kbytes.

  226. DucTor
    January 30th, 2015 at 00:53 | #228

    Tnx!
    Finally I got the handle on the rumble function!! 🙂

    Pretty darn easy actually! There are two rumble motors inside the controller, one #heavy” and one “light”.
    This command and you got the most “rumble” for the longest duration:
    PS3.setRumbleOn(RumbleHigh)

    With this you got the “hardest” light rumble for long duration:
    PS3.setRumbleOn(RumbleLow)

    If you use numbers instead, you can set both duration an level for both motors:
    PS3.setRumbleOn(0x10,0xFF,0x08,0xFF) here have the little motor slightly longer duration than the strong motor. Both on the strongest level.

    #include <PS3BT.h>
    USB Usb;
    /* You can create the instance of the class in two ways */
    //PS3USB PS3(&Usb); // This will just create the instance
    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    PS3BT PS3(&Btd); // This will just create the instance
    //PS3USB PS3(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

    #include <Servo.h>
    Servo servo1;  // create servo object to control a servo
    Servo servo2;  // create servo object to control a servo
    Servo servo3;  // create servo object to control a servo

    const uint8_t LED = 2;
    const uint8_t Shake = 4;
    const uint8_t Buzzer = 7;

    // variables will change:

    void setup() {
      pinMode(LED, OUTPUT);  // just a led to test buttons..
      pinMode(Buzzer, OUTPUT);    // A buzzer connected to the output
      pinMode(Shake, INPUT);  // the input I wanna use to activate the rumble in the controller(an IR-08H sensor is connected)
      Serial.begin(115200);
      if (Usb.Init() == -1) {
        Serial.print(F("rnOSC did not start"));
        while(1); //halt
      }
      servo1.attach(3); // Use pin 3, as signal pin
      servo2.attach(5); // Use pin 5, as signal pin
      servo3.attach(6); // Use pin 6, as signal pin
      Serial.print(F("rnPS3 Bluetooth Library Started"));
    }

    void loop() {
      Usb.Task();
      if (PS3.PS3Connected)
        digitalWrite(LED, PS3.getButtonPress(CROSS));
      else
        digitalWrite(LED, LOW);
      if (PS3.PS3Connected)
        servo1.write(map(PS3.getAnalogButton(R2), 0, 255, 180, 0));
      else
        servo1.write(180); // Set to position
      if (PS3.PS3Connected)
        servo2.write(map(PS3.getAnalogHat(RightHatX), 0, 255, 180, 0));
      else
        servo2.write(90); // Set to position
      if (PS3.PS3Connected)
        servo3.write(map(PS3.getAngle(Roll), 0, 360, 180, 0));
      else
        servo3.write(90); // Set to position
      if (PS3.getButtonClick(PS))
      {
        Serial.print(F("rnPS"));
        PS3.disconnect();
      }
      if (digitalRead(4) == HIGH) {
        digitalWrite(Buzzer, HIGH);
      }
      else {
        digitalWrite(Buzzer, LOW);
        PS3.setRumbleOn(0x10,0xFF,0x08,0xFF);
      }
    }

    But still cant get some analog values from controller when using the BT library. And that I dont get, because the syntax and code are the same in both library. And this is not just with my code, also the same result running the example code.
    Neither the PS3.getAnalogButton(R2) or PS3.getAngle(Roll) works when using PS3BT.h , but works with the PS3USB.h
    Can “trim” some of the Library files? this sketch is now 31kBytes.. Is it possible to remove some library files when only using the library for PS3 BT?

  227. January 30th, 2015 at 15:41 | #229

    @DucTor
    Good to hear you got rumble working.

    Please enable debugging: https://github.com/felis/USB_Host_Shield_2.0#enable-debugging and run the example with the serial monitor open. My guess is that your dongle does not support 2.0+EDR, so it can’t read all the data via Bluetooth.

    I don’t get why yours sketch is 31k bytes. I just tried compiling your code and I get only 18k bytes. You should try downloading Arduino 1.5.8: http://arduino.cc/en/Main/Software and see if it helps. It has a newer version of gcc.

  228. DucTor
    January 30th, 2015 at 17:42 | #230

    Yes, I seems like its a dongle problem. At work i had another dongle, and with that one everything worked perfect! 🙂
    I had debugging enabled all the time. I have version 1.0.6, both at home and work. did an compile and upload of the code at work also. the strange thing is that now i get a lot of errors when when trying the use it at my home pc. Now its showing a lot of Error sending L2CAP message: 0x0D – Channel ID: 00 00 messages when running my code, with both dongles.. I’m gonna remove the 1.0.6 installation now, and install 1.5.8:

  229. DucTor
    January 30th, 2015 at 18:54 | #231

    With a new clean installation of 1.5.8 and only the USB_Host_Shield 2.0 library instald. When I compile the code that i posted here I got this compile result:
    Sketch uses 23 250 bytes (72%) of program storage space. Maximum is 32 256 bytes.
    Global variables use 1 009 bytes (49%) of dynamic memory, leaving 1 039 bytes for local variables. Maximum is 2 048 bytes.

    On a windows 7 64 bit os. Very strange that there is so big difference inn file size..

  230. DucTor
    January 30th, 2015 at 19:23 | #232

    When I enable debugging the file size increase to:
    Sketch uses 28 472 bytes (88%) of program storage space. Maximum is 32 256 bytes.
    Global variables use 1 011 bytes (49%) of dynamic memory, leaving 1 037 bytes for local variables. Maximum is 2 048 bytes.

  231. kiran
    February 11th, 2015 at 10:38 | #233

    hi
    i was trying to connect usb mouse with arduino adk to read its xy coordinates on serial monitor

    i powered adk with usb cabled and 9v volt adaptor
    still mouse light does not glow

    any body help please

    here is my code

    #include
    #include
    // Satisfy IDE, which only needs to see the include statment in the ino.
    #ifdef dobogusinclude
    #include
    #endif

    class MouseRptParser : public MouseReportParser
    {
    protected:
    virtual void OnMouseMove (MOUSEINFO *mi);
    virtual void OnLeftButtonUp (MOUSEINFO *mi);
    virtual void OnLeftButtonDown (MOUSEINFO *mi);
    virtual void OnRightButtonUp (MOUSEINFO *mi);
    virtual void OnRightButtonDown (MOUSEINFO *mi);
    virtual void OnMiddleButtonUp (MOUSEINFO *mi);
    virtual void OnMiddleButtonDown (MOUSEINFO *mi);
    };
    void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
    {
    Serial.print(“dx=”);
    Serial.print(mi->dX, DEC);
    Serial.print(” dy=”);
    Serial.println(mi->dY, DEC);
    };
    void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
    {
    Serial.println(“L Butt Up”);
    };
    void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
    {
    Serial.println(“L Butt Dn”);
    };
    void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
    {
    Serial.println(“R Butt Up”);
    };
    void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
    {
    Serial.println(“R Butt Dn”);
    };
    void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
    {
    Serial.println(“M Butt Up”);
    };
    void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
    {
    Serial.println(“M Butt Dn”);
    };

    USB Usb;
    USBHub Hub(&Usb);
    HIDBoot HidMouse(&Usb);

    uint32_t next_time;

    MouseRptParser Prs;

    void setup()
    {
    Serial.begin( 115200 );
    while (!Serial); // Wait for serial port to connect – used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    Serial.println(“Start”);

    if (Usb.Init() == -1)
    Serial.println(“OSC did not start.”);

    delay( 200 );

    next_time = millis() + 5000;

    HidMouse.SetReportParser(0,(HIDReportParser*)&Prs);
    }

    void loop()
    {
    Usb.Task();
    }

    i have downloaded library from
    https://github.com/felis/USB_Host_Shield_2.0

  232. February 12th, 2015 at 00:34 | #234

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

  233. Dhiraj Shrotri
    February 23rd, 2015 at 07:35 | #235

    I am using your host sheild library v2 to connect a PS3 dualshock3 sixaxis joystick to a mega adk r3 board via a Bluetooth v2.0 with edr and csr class 4 dongle. I am using a separate external power supply for the microcontroller. I am facing some problems while doing so. The dongle sometimes doesn’t initialize when the micro is initially powered on. Sometimes the dongle does start on resetting the micro but sometimes it requires a lot of resets. Also when the dongle is initialized and connection is established sometimes the joystick gets disconnected during the code execution and the micro keeps on executing the previous command received from the joystick before the connection was broken.

  234. February 24th, 2015 at 00:47 | #236

    @Dhiraj Shrotri
    Does it always work if you unplug the dongle and plug the dongle in again? You might want to try the following modification to your shield: http://www.circuitsathome.com/mcu/vbus-power-control-on-usb-host-shield.

    It will allow you to turn off the power of the dongle in code in case something goes wrong. This is done in the Balanduino code like so: https://github.com/TKJElectronics/Balanduino/blob/master/Firmware/Balanduino/Bluetooth.ino#L51-L57.

    The disconnection problem sounds to me more like a issue with either the battery inside the controller or your 5V rail is not stable for USB host.

  235. bon salido
    February 28th, 2015 at 23:37 | #237

    hi
    need help with ps3 controller connected to usb host via usb cable.
    I have same problem with martin controller does not respond or anything blinks for couple of secs and do nothing.

    thanks in advance.

  236. March 1st, 2015 at 00:29 | #238

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

    Also see the faq on how to use a hub: https://github.com/felis/USB_Host_Shield_2.0#faq.

  237. cyber2th
    March 6th, 2015 at 20:14 | #239

    “class usb has no member named init” is the error I am getting. I am new to Arduino. I am using an Arduino Uno with Keyes USB host shield. Is there a way to fix it?
    Thank you.

  238. Zhach
    March 13th, 2015 at 22:16 | #240

    Men I use this dongle http://www.amazon.com/gp/product/B00IMALOZ0/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

    The program is the original
    /*
    Example sketch for the PS3 Bluetooth library – developed by Kristian Lauszus
    For more information visit my blog: http://blog.tkjelectronics.dk/ or
    send me an e-mail: kristianl@tkjelectronics.com
    */

    #include
    #include
    // Satisfy IDE, which only needs to see the include statment in the ino.
    #ifdef dobogusinclude
    #include
    #include
    #endif

    USB Usb;
    //USBHub Hub1(&Usb); // Some dongles have a hub inside

    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    /* You can create the instance of the class in two ways */
    //PS3BT PS3(&Btd); // This will just create the instance
    PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch

    bool printTemperature;
    bool printAngle;

    void setup() {
    Serial.begin(115200);
    #if !defined(__MIPSEL__)
    while (!Serial); // Wait for serial port to connect – used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    #endif
    if (Usb.Init() == -1) {
    Serial.print(F(“rnOSC did not start”));
    while (1); //halt
    }
    Serial.print(F(“rnPS3 Bluetooth Library Started”));
    }
    void loop() {
    Usb.Task();

    if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
    if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) 137 || PS3.getAnalogHat(LeftHatY) 137 || PS3.getAnalogHat(RightHatX) 137 || PS3.getAnalogHat(RightHatY) < 117) {
    Serial.print(F("rnLeftHatX: "));
    Serial.print(PS3.getAnalogHat(LeftHatX));
    Serial.print(F("tLeftHatY: "));
    Serial.print(PS3.getAnalogHat(LeftHatY));
    if (PS3.PS3Connected) { // The Navigation controller only have one joystick
    Serial.print(F("tRightHatX: "));
    Serial.print(PS3.getAnalogHat(RightHatX));
    Serial.print(F("tRightHatY: "));
    Serial.print(PS3.getAnalogHat(RightHatY));
    }
    }

    // Analog button values can be read from almost all buttons
    if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
    Serial.print(F("rnL2: "));
    Serial.print(PS3.getAnalogButton(L2));
    if (PS3.PS3Connected) {
    Serial.print(F("tR2: "));
    Serial.print(PS3.getAnalogButton(R2));
    }
    }
    if (PS3.getButtonClick(PS)) {
    Serial.print(F("rnPS"));
    PS3.disconnect();
    }
    else {
    if (PS3.getButtonClick(TRIANGLE))
    Serial.print(F("rnTraingle"));
    if (PS3.getButtonClick(CIRCLE))
    Serial.print(F("rnCircle"));
    if (PS3.getButtonClick(CROSS))
    Serial.print(F("rnCross"));
    if (PS3.getButtonClick(SQUARE))
    Serial.print(F("rnSquare"));

    if (PS3.getButtonClick(UP)) {
    Serial.print(F("rnUp"));
    if (PS3.PS3Connected) {
    PS3.setLedOff();
    PS3.setLedOn(LED4);
    }
    }
    if (PS3.getButtonClick(RIGHT)) {
    Serial.print(F("rnRight"));
    if (PS3.PS3Connected) {
    PS3.setLedOff();
    PS3.setLedOn(LED1);
    }
    }
    if (PS3.getButtonClick(DOWN)) {
    Serial.print(F("rnDown"));
    if (PS3.PS3Connected) {
    PS3.setLedOff();
    PS3.setLedOn(LED2);
    }
    }
    if (PS3.getButtonClick(LEFT)) {
    Serial.print(F("rnLeft"));
    if (PS3.PS3Connected) {
    PS3.setLedOff();
    PS3.setLedOn(LED3);
    }
    }

    if (PS3.getButtonClick(L1))
    Serial.print(F("rnL1"));
    if (PS3.getButtonClick(L3))
    Serial.print(F("rnL3"));
    if (PS3.getButtonClick(R1))
    Serial.print(F("rnR1"));
    if (PS3.getButtonClick(R3))
    Serial.print(F("rnR3"));

    if (PS3.getButtonClick(SELECT)) {
    Serial.print(F("rnSelect – "));
    PS3.printStatusString();
    }
    if (PS3.getButtonClick(START)) {
    Serial.print(F("rnStart"));
    printAngle = !printAngle;
    }
    }
    #if 0 // Set this to 1 in order to see the angle of the controller
    if (printAngle) {
    Serial.print(F("rnPitch: "));
    Serial.print(PS3.getAngle(Pitch));
    Serial.print(F("tRoll: "));
    Serial.print(PS3.getAngle(Roll));
    }
    #endif
    }
    #if 0 // Set this to 1 in order to enable support for the Playstation Move controller
    else if (PS3.PS3MoveConnected) {
    if (PS3.getAnalogButton(T)) {
    Serial.print(F("rnT: "));
    Serial.print(PS3.getAnalogButton(T));
    }
    if (PS3.getButtonClick(PS)) {
    Serial.print(F("rnPS"));
    PS3.disconnect();
    }
    else {
    if (PS3.getButtonClick(SELECT)) {
    Serial.print(F("rnSelect"));
    printTemperature = !printTemperature;
    }
    if (PS3.getButtonClick(START)) {
    Serial.print(F("rnStart"));
    printAngle = !printAngle;
    }
    if (PS3.getButtonClick(TRIANGLE)) {
    Serial.print(F("rnTriangle"));
    PS3.moveSetBulb(Red);
    }
    if (PS3.getButtonClick(CIRCLE)) {
    Serial.print(F("rnCircle"));
    PS3.moveSetBulb(Green);
    }
    if (PS3.getButtonClick(SQUARE)) {
    Serial.print(F("rnSquare"));
    PS3.moveSetBulb(Blue);
    }
    if (PS3.getButtonClick(CROSS)) {
    Serial.print(F("rnCross"));
    PS3.moveSetBulb(Yellow);
    }
    if (PS3.getButtonClick(MOVE)) {
    PS3.moveSetBulb(Off);
    Serial.print(F("rnMove"));
    Serial.print(F(" – "));
    PS3.printStatusString();
    }
    }
    if (printAngle) {
    Serial.print(F("rnPitch: "));
    Serial.print(PS3.getAngle(Pitch));
    Serial.print(F("tRoll: "));
    Serial.print(PS3.getAngle(Roll));
    }
    else if (printTemperature) {
    Serial.print(F("rnTemperature: "));
    Serial.print(PS3.getTemperature());
    }
    }
    #endif
    }

    that is my monitor

    PS3 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
    Wait For Incoming Connection Request
    Dualshock 3 Controller Connected
    Bluetooth Address was set to: 00:1A:7D:DA:71:13
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:1A:7D:DA:71:13
    Wait For Incoming Connection Request
    Keyboard is connecting
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3 Controller
    Connected to Device: 00:26:5C:1D:17:10
    HID Control Incoming Connection Request
    HID Control Successfully Configured
    HID Interrupt Incoming Connection Request
    HID Interrupt Successfully Configured
    Wait For Incoming Connection Request
    Dualshock 3 Controller Enabled

    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0

  239. March 15th, 2015 at 00:08 | #241

    @cyber2th
    You have included the library incorrectly. Please see: https://github.com/felis/USB_Host_Shield_2.0#how-to-include-the-library.

    @Zhach
    This is a problem with your dongle. Please see: https://github.com/felis/USB_Host_Shield_2.0#faq.

  240. March 15th, 2015 at 00:09 | #242

    @cyber2th
    Also please consider buying the official shield in the future in order to support the actual developers of the library and hardware.

  241. Marvin
    June 22nd, 2015 at 13:18 | #243

    Hi! I got a problem while connecting my PS3 Controller via Bluetooth. I got no problems via USB.
    I’m using the actual library and tested with 3 different (all confirmed working by the list) Bluetooth sticks.
    My Serial is stuck there:
    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 5C:F3:70:66:0E:E0
    Wait For Incoming Connection Request
    Gamepad is connecting
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3 Controller

    Sometimes the Remote Name is cut off. Like “Remote Name: PLAYST”

    Tried with external Power but no success.

    Any Ideas?

  242. July 4th, 2015 at 19:29 | #244

    @Marvin
    Hmm okay. What shield and Arduino are you using?

  243. Marvin
    July 6th, 2015 at 11:23 | #245

    @Kristian Lauszus
    I am using a Keyes Shield. Right now I’m testing it with a PS4 Controller. It indicates that it discovered the controller and i should create the instance like “PS4BT PS4(&Btd);” But then it doesn’t connect either.

  244. July 6th, 2015 at 13:09 | #246

    @Marvin
    Okay. Have you tried another dongle? Also please try to connect an external power supply.

  245. Marvin
    July 6th, 2015 at 13:30 | #247

    @Kristian Lauszus
    Like I’ve said, 3 different dongles, all confirmed by the list. 3 different external power supplies and 2 different Arduino Uno’s. Nothing worked.

  246. July 6th, 2015 at 15:58 | #248

    @Marvin
    Sorry it must be a problem with your shield then, please try the official one from either: http://shop.tkjelectronics.dk/ or https://www.circuitsathome.com/products-page/arduino-shields.

  247. tony
    July 6th, 2015 at 21:48 | #249

    Hi, has the library got a function of button release? Or hat release? As hat analogs never return to 128 centre when released they can be random depending how hard you release the trigger

    Thanks

  248. July 6th, 2015 at 22:18 | #250

    @tony
    To check if a button is pressed simply use the function getButtonPress: http://felis.github.io/USB_Host_Shield_2.0/class_p_s3_b_t.html#a5e7842bef25e7c7210974f5405e1bc81.

    The hat should return back to 128? Are you using an official controller?

  249. tony
    July 6th, 2015 at 22:45 | #251

    @Kristian Lauszus
    Hi

    I am using official controller but it is about 5 years old now, get buttonpressed is ok, i can send out command but i need it to then send another command when i release the button.

    E.g ptz camera, button left press, moves left but it seems like when you press it just knows it was pressed not held, then released, then i send stop command to camera

    Thanks

  250. July 6th, 2015 at 23:01 | #252

    @tony
    You can implement that logic yourself. Simply hold the state in a static variable and then check if it just went from pressed to released.

    I am not sure what you mean? I sounds like you are using getButtonClick where you should be using getButtonPress?

  251. tony
    July 6th, 2015 at 23:15 | #253

    Sorry i ment buttonclick, i have tried getbuttonpress but that is analog and same as hat the button never returns to 0 when i release, its always a random analog value. I am new to coding and not sure hos to implement the static variable.

    I was looking at the ps2 library and it has a buttonrelease statement, can i add one to the ps3 lib?

    Thanks again

  252. July 6th, 2015 at 23:18 | #254

    @tony
    No getButtonPress returns a bool: http://felis.github.io/USB_Host_Shield_2.0/class_p_s3_b_t.html#a5e7842bef25e7c7210974f5405e1bc81.

    What PS2 library are you talking about? You can check if a button is released like so:

    if (!PS3.getButtonPress(CROSS)) {
       // Button is released
    }
  253. tony
    July 7th, 2015 at 07:08 | #255

    Hi, this is the ps2 https://github.com/madsci1016/Arduino-PS2X/blob/master/PS2X_lib/PS2X_lib.h

    Thanks for your help i will try your solution

  254. tony
    July 7th, 2015 at 21:04 | #256

    hi I tied your solution but it does not work,

    if (!PS3.getAnalogHat(LeftHatY)){
    }

    doesn’t output until then hat is fully forward, as 0 is fully forward.

    if (!PS3.getButtonPress(CROSS)) {
    // Button is released
    }

    does not output anything, can I send you my code please to make sure iam not making a mistake

  255. July 7th, 2015 at 21:28 | #257

    @tony
    You should not check the analog hat that way, then the statement will only become true when the joystick reads 0. What are you trying to archive? If you want to check if it is in the center, then do something like this:

    if (PS3.getAnalogHat(LeftHatY) < 137 && PS3.getAnalogHat(LeftHatY) > 117) {
    }

    The second code should be true every time you release the button. Did you actually try to print anything or how did you check if the code where run or not? Share your code somewhere and I will take a look.

  256. tony
    July 7th, 2015 at 22:05 | #258

    hi

    http://codeviewer.org/view/code:5315

    is my code,
    ok so under the button click left, I have modified this now because I have added a buttonreleased but what is happening. I press button left it outputs my code but then I get the stop command straight away, it doesn’t output the stop when I depress the button.

    thanks

  257. July 11th, 2015 at 12:01 | #259

    @tony
    First of all you are missing brackets after:

    if (PS3.PS3Connected || PS3.PS3NavigationConnected)

    You can only leave them out if there is only one line after the statement! Also a single ‘&’ is used as a bitwise operator and you should use two i.e. ‘&&’ for the the AND operator. Please read: https://www.arduino.cc/en/Reference/BitwiseAnd.

    Sorry it is hard for me to figure out what is wrong in your code when I can’t see the source code for your getButtonReleased function.

  258. tony
    July 12th, 2015 at 16:08 | #260

    @Kristian Lauszus
    thanks Kristian, I have since redone my code and have it working, thanks for your help. although Its not the best method, I had to use a lot of serial ends and serial begins.

    http://codeviewer.org/view/code:533c

  259. July 12th, 2015 at 17:15 | #261

    @tony
    You should begin and end the serial communication like that. I believe you can solve your problem with the flush command: https://www.arduino.cc/en/serial/flush.

  260. Gaston
    July 18th, 2015 at 03:43 | #262

    Hi @Kristian Lauszus

    I’m also experiencing the same connectivity issue as Marvin posted on June 22nd, 2015.

    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 5C:F3:70:67:FF:A0
    Wait For Incoming Connection Request
    Dualshock 3 Controller Connected
    Bluetooth Address was set to: 5C:F3:70:67:FF:A0
    PS3 Bluetooth Library Started
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 5C:F3:70:67:FF:A0
    Wait For Incoming Connection Request
    Gamepad is connecting
    Incoming Connection Request
    Remote Name: PLAYSTA

    After this, On the PS3 Controller the four LED’s are blinking for around 1 minute, but no connection.
    I’m working with an Arduino UNO and the Circuits@Home USB Host Shield rev. 2.0.1
    and Original PS3 Controller Dualshock 3 Sixaxis.

    I’ve also tried with 2 different “listed” BT dongles
    Exactly the same behavior with both dongles,

    Could you please provide me with some ideas?

    Thanks

  261. Gaston
    July 18th, 2015 at 08:24 | #263

    @Gaston
    @Kristian Lauszus

    Nevermind, I just got it running now,
    The issue was an old version of the Arduino IDE software

    Maybe you can help me to explain,
    When I google Arduino IDE the first hit sends me to:
    https://www.arduino.cc/en/Main/Software
    There I can download the “latest” version which is ARDUINO 1.6.5

    Now, if you go to http://www.arduino.org/downloads
    There you can download a later version Arduino 1.7.6

    I have installed that newer version and the connectivity issue is gone,

    How is it possible to have 2 different sites to download the IDE software!!!???

    I will appreciate your comments,

    Thanks

    Gaston

  262. July 18th, 2015 at 08:31 | #264

    @Gaston
    This issue was solved just recently: https://github.com/felis/USB_Host_Shield_2.0/pull/168.

    You should download the IDE from arduino.cc, the arduino.org has basically copied them and claimed that they are the folks behind Arduino. You can read more about it here: http://hackaday.com/2015/02/25/arduino-v-arduino/.

    I know it version number says 1.7.6, but the code is much older than 1.6.5. Again you can read some more information here: http://hackaday.com/2015/04/06/arduino-ide-forked/.

  263. Avilash sahoo
    July 31st, 2015 at 09:09 | #265

    @Kristian Lauszus

    sir please help i want to connect ps3 controller to usb host shield by bluetooth. i have tried with 3 different Bluetooth dongle and two of them were supported and conformed working by diiferent users from internet. one the Chinese one used here and one was kinivq BTD-400 and one was Leoxsys Bluetooth 4.0 USB 2.0/3.0 Adapter Dongle: 2.1+EDR Compliant. all of them are edr supported. but all shows

    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 5C:F3:70:67:3F:58
    Wait For Incoming Connection Request
    Keyboard is connecting
    Incoming Connection Request
    Remote Name: PLAYSTA
    Connected to Device: 00:26:5C:4F:4D:00
    HID Control Incoming Connection Request
    HID Control Successfully Configured
    HID Interrupt Incoming Connection Request
    HID Interrupt Successfully Configured
    Wait For Incoming Connection Request
    Dualshock 3 Controller Enabled
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 1
    ??.
    I am using a keyes host shield usb uno and mega. ps3 controller working well with usb connector but when i connect using bluetooth dongle and corresponding code its giving above results.
    what to do please help

  264. August 3rd, 2015 at 00:18 | #266

    @Avilash sahoo
    Please use the official shield, as there is all kind of weird issues with clones. You can buy it either from us: http://shop.tkjelectronics.dk/ or here: https://www.circuitsathome.com/products-page/arduino-shields.

    The problem you are facing is due to your dongle not supporting 2.0+EDR. Please see: https://github.com/felis/USB_Host_Shield_2.0#faq. Here is a list of confirmed working dongles: https://github.com/felis/USB_Host_Shield_2.0/wiki/Bluetooth-dongles.

  265. Anadika
    April 2nd, 2016 at 17:23 | #267

    Hi, after uploading the PS3BT example (without changing settings.h debugging), I only get the following message in the serial monitor: “PS3 Bluetooth Library Started”
    It does not go beyond that. Could you please advise on how to solve this issue? Thanks in advance.

  266. Anadika
    April 6th, 2016 at 19:46 | #268

    @Lauszus
    Hey, I need some help. In the serial monitor, I’m stuck at ‘PS3 Bluetooth Library Started’. I went through the comments and according to the suggestions, did the following:
    – Uncommented L20 and L21 in PS3BT.cpp file (no change, I still was stuck at the same message)
    – Changed debug from 0 to 1 in settings.h file (got a whole bunch of compilation errors)

    PS3BT.ino: In function ‘void loop()’:
    PS3BT.ino:55:31: error: no matching function for call to ‘PS3BT::getAnalogButton(Button)’
    PS3BT.ino:55:31: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: uint8_t PS3BT::getAnalogButton(AnalogButton)
    uint8_t getAnalogButton(AnalogButton a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: no known conversion for argument 1 from ‘Button’ to ‘AnalogButton’
    PS3BT.ino:55:58: error: no matching function for call to ‘PS3BT::getAnalogButton(Button)’
    PS3BT.ino:55:58: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: uint8_t PS3BT::getAnalogButton(AnalogButton)
    uint8_t getAnalogButton(AnalogButton a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: no known conversion for argument 1 from ‘Button’ to ‘AnalogButton’
    PS3BT.ino:57:42: error: no matching function for call to ‘PS3BT::getAnalogButton(Button)’
    PS3BT.ino:57:42: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: uint8_t PS3BT::getAnalogButton(AnalogButton)
    uint8_t getAnalogButton(AnalogButton a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: no known conversion for argument 1 from ‘Button’ to ‘AnalogButton’
    PS3BT.ino:60:44: error: no matching function for call to ‘PS3BT::getAnalogButton(Button)’
    PS3BT.ino:60:44: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: uint8_t PS3BT::getAnalogButton(AnalogButton)
    uint8_t getAnalogButton(AnalogButton a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:80:13: note: no known conversion for argument 1 from ‘Button’ to ‘AnalogButton’
    PS3BT.ino:85:25: error: no matching function for call to ‘PS3BT::setLedOff()’
    PS3BT.ino:85:25: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: void PS3BT::setLedOff(LED)
    void setLedOff(LED a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: candidate expects 1 argument, 0 provided
    PS3BT.ino:92:25: error: no matching function for call to ‘PS3BT::setLedOff()’
    PS3BT.ino:92:25: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: void PS3BT::setLedOff(LED)
    void setLedOff(LED a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: candidate expects 1 argument, 0 provided
    PS3BT.ino:99:25: error: no matching function for call to ‘PS3BT::setLedOff()’
    PS3BT.ino:99:25: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: void PS3BT::setLedOff(LED)
    void setLedOff(LED a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: candidate expects 1 argument, 0 provided
    PS3BT.ino:106:25: error: no matching function for call to ‘PS3BT::setLedOff()’
    PS3BT.ino:106:25: note: candidate is:
    In file included from PS3BT.ino:7:0:
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: void PS3BT::setLedOff(LED)
    void setLedOff(LED a);
    ^
    /Users/BAGHEL/Documents/Arduino/libraries/USB_Host_Shield_Library/PS3BT.h:94:10: note: candidate expects 1 argument, 0 provided
    PS3BT.ino:122:13: error: ‘class PS3BT’ has no member named ‘printStatusString’
    Error compiling.

    Can you please advice? Thanks a lot!

  267. jonnys
    April 11th, 2016 at 11:28 | #269

    Hi kristian, i just begin to use your ps3 library for Arduino and i wanted to thank you for this awesome job, we really appreciate it!

    I started with PS3BT and everything worked well, but i wanted also to add the PS3USB so i can use one of them each time without to have to upload the sketch every time. I tried to see if PS3Multi does this function but what i’ve understand it’s that that need just to use multiple controllers at the same time, right? tell me that i’m wrong 😀

  268. Johnson Nguyen
    April 12th, 2016 at 04:35 | #270

    Hi Kristian,

    I need some help with my code using the USB host shield 2.0! I’m trying to use my PS3 controller to turn on an RGB bulb at a specified color by press either CROSS, SQUARE, TRIANGLE, or CIRCLE. But I’ve only been able to get the RGB to turn on momentarily or as long as I pressed the button. I want the RGB to stay on until another color is selected or it is shut off. It should also be noted that I am using a common anode RGB. My code so far is as such:

    #include

    USB Usb;
    BTD Btd(&Usb);
    PS3BT PS3(&Btd);
    int redPin = 6;
    int greenPin = 5;
    int bluePin = 3;

    #define COMMON_ANODE

    void setup()
    { Serial.begin(115200);
    if (Usb.Init() == -1) {
    Serial.print(F(“rnOSC did not start”));
    while(1); //halt
    }
    Serial.print(F(“rnPS3 Bluetooth Library Started”));
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);
    }

    void loop()
    {
    Usb.Task();
    if(PS3.getButtonPress(CROSS)){
    moveSetBulb(0, 0, 255); // red
    }
    else if(PS3.getButtonPress(CIRCLE)){
    moveSetBulb(0, 255, 0); // green
    }
    else if(PS3.getButtonPress(SQUARE)){
    moveSetBulb(255, 255, 0); // aqua
    }
    else if(PS3.getButtonPress(TRIANGLE)){
    moveSetBulb(335, 0, 335); // purple
    }
    else{
    moveSetBulb(0, 0, 0);
    }
    if(PS3.getButtonClick(PS)) {
    PS3.disconnect();
    }
    }

    void moveSetBulb(int red, int green, int blue)
    {
    #ifdef COMMON_ANODE
    red = 255 – red;
    green = 255 – green;
    blue = 255 – blue;
    #endif
    analogWrite(redPin, red);
    analogWrite(greenPin, green);
    analogWrite(bluePin, blue);
    }

  269. April 14th, 2016 at 23:06 | #271

    @Anadika
    There was a issue in the library that cause it to fail compiling when the serial debugging where turned on: https://github.com/felis/USB_Host_Shield_2.0/commit/8f3faf2bb86e090cec99601c06a7beb28d159c6c and https://github.com/felis/USB_Host_Shield_2.0/commit/00397199706b1c1f4029f78f0bd6f3ab2ef08e3f. Please download the newest code from Github and try again.

    @jonnys
    Yes PS3Multi is meant for using multiple controllers at the same time.

    You can simply create two instances:

    PS3USB PS3_USB(&Usb);
    PS3BT PS3_BT(&Btd);

    And then use the provided function in order to read the buttons etc.

    @Johnson Nguyen
    Simply use the “getButtonClick” function instead.

  270. jonnys
    April 21st, 2016 at 16:11 | #272

    Thank Lauszus for your reply,
    I try as you told me, it worked but i had almost to duplicate every if()
    I created the two instances as:
    PS3USB PS3_USB(&Usb);
    PS3BT PS3_BT(&Btd);

    But to use the same function to read the buttons like:

    if (PS3.getButtonClick(UP)) {
    how i can call it one time but for both instance BT and USB?
    it’s correct to call it in this way?
    if (PS3_USB.getButtonClick(UP)) || (PS3_BT.getButtonClick(UP)) {

    And to assign it to a value like in this way, how i can add the PS3_BT ?
    Servo1 = map(PS3_USB.getAnalogHat(LeftHatX), 0, 255, 0, 180);

  271. jonnys
    April 24th, 2016 at 23:42 | #273

    Ah, another thing Kristian,
    I’ve noticed that if i add a delay maybe 50ms and over in the loop, the controller seems can’t connect to the usb host shield till i change it at maximum to 10ms or remove it completely, it is normal?

  272. April 25th, 2016 at 19:20 | #274
  273. Johnson Nguyen
    April 28th, 2016 at 22:23 | #275

    @Kristian

    Thanks for the repy. But I’ve tried that and it only turns on the RGB LED for a split second before it shuts back off. I want to keep the LED on until it is shut off.

  274. April 28th, 2016 at 22:52 | #276

    @Johnson Nguyen
    Simply just remove:

    else {
        moveSetBulb(0, 0, 0);
    }

    And then just do:

    if (PS3.getButtonClick(PS)) {
        moveSetBulb(0, 0, 0);
        PS3.disconnect();
    }
  275. Ryan
    April 29th, 2016 at 02:04 | #277

    Hi Kristian,
    I am using the circuits@home USB shield, an arduino mega 2560, and an approved, tested dongle purchased from TKJ. I am using the example sketch PS3BT to attempt to connect, and have mixed results so far. I have had it connect a couple of times, but when I attempt to reconnect, it will not connect. When I push the ps button to reconnect, with the sketch running on a separate power supply, the lights on the controller just blink and it won’t connect. I have tried to upload the sketch with debug information turned on, but just get an error.

  276. Ryan
    April 29th, 2016 at 02:07 | #278

    @Ryan
    I forgot to mention that I have tried connecting with a PS4 controller as well, and it will not connect at all. The USB dongle does not show up as available if I scan with my phone, though I’m not sure if that matters.

  277. Bruno
    April 30th, 2016 at 20:45 | #279

    Hello Lauszus,

    Should it work with unofficial ps3 controllers? I tested two dongles, they get recognised but can’t connect to the controller. The four leds just keep blinking.

    thank you!

  278. May 6th, 2016 at 16:00 | #280

    @Ryan
    Please upload the code with debugging enabled again. There were a bug which I have now corrected.

    There is mixed results with unofficial controllers. I would recommend sticking with an official PS3 controller.

  279. Ryan
    June 6th, 2016 at 00:17 | #281

    I’ve been trying to get my PS3 controller to connect with my Arduino boards for a while now, and have had mixed success. My setup is an Arduino Mega 2560 with an official USB host shield and a tested Bluetooth dongle purchased from tkj electronics. The controllers that I am trying to connect are official Sony 6 axis controllers, though they are fairly old. I use an external power source to power the Arduino board while trying to connect, too. I have had the controllers connect 3 times total out of approximately 40 attempts. Each time it connected, it would never reconnect. I have finally been able to get debugging data, and I was hoping you might be able to help me figure out my problem. I have a program on my computer called Sixaxis pair tool that reads the Bluetooth address of the controller, and it verifies that the Arduino sketch is writing the address of the dongle to the controller, but it still won’t connect. I have included the debug data and the top part of the sketch. The rest of the sketch is unchanged, it came from the example library, it is the PS3BT example. So, here is the Bluetooth address part of the sketch, and the debug data is attached as a text file. Of course, as I am typing this email, I finally managed to get it to connect again, so I have included that inn the debug file, too.

    Thanks,
    Ryan

    /*
    Example sketch for the PS3 Bluetooth library – developed by Kristian Lauszus
    For more information visit my blog: http://blog.tkjelectronics.dk/ or
    send me an e-mail: kristianl@tkjelectronics.com
    */

    #include
    #include

    // Satisfy the IDE, which needs to see the include statment in the ino too.
    #ifdef dobogusinclude
    #include
    #include
    #endif

    USB Usb;
    //USBHub Hub1(&Usb); // Some dongles have a hub inside

    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    /* You can create the instance of the class in two ways */
    //PS3BT PS3(&Btd); // This will just create the instance
    PS3BT PS3(&Btd, 0x00, 0x11, 0x22, 0x98, 0x76, 0x54); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch

    Here’s the debug data-

    PS3 Bluetooth Library Started
    BTD ConfigureDevice
    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: 00
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    BTD ConfigureDevice
    BTD Init
    Addr: 01
    Dualshock 3 Controller Connected
    Bluetooth Address was set to: 00:11:22:98:76:54
    BTD ConfigureDevice
    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: 00
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    BTD ConfigureDevice
    BTD Init
    Addr: 01
    Dualshock 3 Controller Connected
    Bluetooth Address was set to: 00:11:22:98:76:54
    BTD ConfigureDevice
    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: 00
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    Gamepad is connecting
    Class of device: 00 05 08
    Incoming Connection Request
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10
    Connection Failed: 10

    Connection Failed: 10
    Connection Failed: 10
    Gamepad is connecting
    Class of device: 00 05 08
    Wait For Incoming Connection Request
    Connection Failed: 10
    Connection Failed: 10

    Here is a successful attempt.

    PS3 Bluetooth Library Started
    BTD ConfigureDevice
    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: 00
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:11:22:98:76:54
    Wait For Incoming Connection Request
    Gamepad is connecting
    Class of device: 00 05 08
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3 Controller
    Connection established
    Connected to Device: 00:21:4F:9B:B4:33
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    HID Control Incoming Connection Request
    Connection established
    HID Control Successfully Configured
    HID Interrupt Incoming Connection Request
    HID Interrupt Successfully Configured
    Wait For Incoming Connection Request
    Dualshock 3 Controller Enabled

    LeftHatX: 124 LeftHatY: 123 RightHatX: 140 RightHatY: 131
    LeftHatX: 124 LeftHatY: 123 RightHatX: 140 RightHatY: 132
    LeftHatX: 124 LeftHatY: 123 RightHatX: 140 RightHatY: 132
    LeftHatX: 124 LeftHatY: 123 RightHatX: 140 RightHatY: 132
    LeftHatX: 124 LeftHatY: 123 RightHatX: 140 RightHatY: 132
    LeftHatX: 124 LeftHatY: 123 RightHatX:

  280. June 22nd, 2016 at 13:53 | #282

    Hi Kristian,
    I have a problem when I connect ps3 dualshock controller to arduino mega 2560,In the serial monitor, I get stuck at ?PS3 Bluetooth Library Started?. & ps3 dualshock’s all leds start blinking it doesn’t connect.

  281. June 24th, 2016 at 09:05 | #283
  282. July 13th, 2016 at 22:31 | #284

    @Kristian Sloth Lauszus
    I’ve checked with Debugging enabled but it’s the same problem, it doesn’t connect with the Dual shock.

    It worked fine first but then when I re-programed it later it doesn’t connect and gave me error “OSC didn’t start”, then I searched for the solution which told to edit the macro in settings.h #define USE_UHS_MEGA_ADK from 0 to 1.

    It started working then and gave the output “PS3 Bluetooth Library Started” but it doesn’t connect with the Dual shock.

    Do you know why it doesn’t connect or any solution to the problem.

  283. July 13th, 2016 at 23:18 | #285

    @Usama
    What shield are you using?

  284. Nixx
    March 25th, 2017 at 12:31 | #286

    @Kristian Sloth Lauszus
    Hello Kristian,
    My PS3 controller cannot pair with BT dongle. The 4 LEDs were blinking for around 1 min and then all went off.

    Below are messages from serial monitor.

    PS3 Bluetooth Library Started
    BTD ConfigureDevice
    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: 00
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Bluetooth Dongle Initialized
    HCI Reset complete
    Write class of device
    Local Bluetooth Address: 00:15:83:0C:BF:EB
    Wait For Incoming Connection Request
    Keyboard is connecting
    Class of device: 00 05 40
    Incoming Connection Request
    Remote Name: PLAYSTATION(R)3Conteroller-PAN
    Connection established
    Connected to Device: 04:F2:78:70:63:25
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    //[continue very long]

    Wait For Incoming Connection Request
    HCI Disconnected from Device
    Wait For Incoming Connection Request

    Could you please advise?

  285. Zak
    March 28th, 2017 at 21:28 | #287

    @Kristian Sloth Lauszus

    I am trying to use this library with a Chipkit Max32 Board + Network Shield and a PS3 Controller with a Bluetooth Dongle, Will this library work without any modifications ? Please advise.

  286. tijl
    December 3rd, 2017 at 17:26 | #288

    @Lauszus

    I understand that 2 ps3 controllers can be connected with the use of one usb hub and two bluetooth dongles. Is that correct? Is it also possible to connect through one usb hub a normal usb cable connected ps3 controller and simultaneously a second ps3 controller via a bluetooth dongle?

    kind regards,

  287. tijl
    December 4th, 2017 at 18:24 | #289

    @Lauszus
    How can you prevent that BT dongle and ps3 controller are going in sleepmode when ps3 controller is not being used. I tried to loop led4 on and of to keep it going. Apparently the controller does not recognise this as activity and shutdown as well as the BT dongle.

  288. Jack
    July 5th, 2021 at 05:00 | #290

    Help!!!
    My ps3 gets disconnect if I use PS3.getbuttonPress(Triangle). It works for a while and gets disconnect automatically after few seconds

  289. Keona
    April 5th, 2022 at 18:34 | #291

    Is there any way to change the serial port it uses? It is conflicting with other libraries I have, and I think it is a timer issue.

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