Bluetooth PS3 Controller consistently unresponsive over USBHost

Hello forum, I have a question that I can't seem to find answers to anywhere, so I finally figured I'd ask someone here. I started on a robot recently that (in the end) I want to do automated surveillance on my apartment. I've finally gotten it built, and I started programming about ~2ish months ago. I finished a lot of the trickier parts, but I decided I would also add manual control for my own fun and enjoyment. To that end, I bought a USB Host Shield for my arduino mega, and have been trying to pair my PS3 controller. I have gotten it to successfully pair with the bluetooth dongle, so I don't believe the dongle is the issue (I've also tried two different dongles). Running PS3BT.ino (from the USBHost library examples) shows my ps3 controller connecting, and shows all the outputs from pushing buttons, moving the joysticks, pressing the triggers, etc, just as I would expect.

Now the problem: I pretty much stole the code right out of PS3BT.ino, just as a way to begin, so I wouldn't mess up the code part, but somehow I have still managed to make an error somewhere. I've posted a brief test code below for those interested, but in the end, the main problem is that my controller will not connect to the dongle, and if it does, there is an obscene amount of 'lag' between commands (where the only command is to press the right trigger to accelerate the motors). For example, if the controller connects (which takes about 15 minutes and pressing reset about 10 times), pressing R2 causes the motors to spin up, but releasing R2 has no effect. Furthermore, I have seen a few different, very simple, PS3 controller implementations on motor functions, but none of them seem to address this. Any help on this would be very appreciated.

void setup() 
  //bool controlleron = 0;
  while (!Serial); 
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  Serial.print(F("\r\nPS3 Bluetooth Library Started"));

  // while(controlleron == 0)
  // {
  // 	Serial.print("\r\nNo controller atm");
  // 	if(PS3.PS3Connected == true)
  // 	{
  // 		controlleron = 1;
  // 		Serial.print("\r\nA wild controller has appeared");
  // 	}
  // 	delay(200);
  // }

  motor1.writeMicroseconds(0); //make sure throttle is at zero

void loop() {
#if 1
    if(PS3.PS3Connected == true) 
    motor1.write(map(PS3.getAnalogButton(R2), 0, 255, 45, 150));
    motor2.write(map(PS3.getAnalogButton(R2), 0, 255, 45, 150));
    motor3.write(map(PS3.getAnalogButton(R2), 0, 255, 45, 150));
    motor4.write(map(PS3.getAnalogButton(R2), 0, 255, 45, 150));

I have commented out a section that forced the program to wait for the ps3 controller to connect, which I believe I implemented correctly. The controller and dongle exhibit absolutely no communication with this enabled. I am terrified that the problem may be voltage related (I've put 9V on Vin directly from a voltage regulator), however this problem persists even when the arduino and robot have their own separate power supplies.

Really sorry about this, but I think I may have just found a solution to my problem. I finally found an article that talked about the USB Host library. In the article, the author mentioned that the newest revision of the library made debugging a lot harder since the resulting file was 'too big' for arduino. He left a link to an older version that he used in his robot where the debugging feature (a simple serial output for what's happening) is actually displayed. Here is the link the old library that he posted, and a link to the original article if anyone else reads this and is interested:

Using the older version, everything works perfectly, and is communicated really well through simple serial monitor messages. Interestingly, my controller still takes longer to connect to my program than PS3BT (even though my program is, by a large margin, much smaller), but it does work, and there is longer an odd 'lag' associated with a button/trigger press. Not sure why this is the case, but it is a workaround for now. One note to make is that I do not believe the PS4 controller is supported in the old library, so you may have to figure something else out if you use that.

Thanks all


Thanks for that; this solved a problem that I was having.

When I ran the board_qc and the USB_desc sketches then my BT dongle was recognised, but when I ran the PS3BT sketch it would halt on "PS3 Bluetooth Library Started". I triple checked all of my soldering on the host shield, swapped arduinos, tried 4 different dongles and scoured the forums.

I have now rolled back from USB_Host_Shield_20 to USB_Host_Shield_Library and it read it in straight away. I diffed the two sketches and there are too many differences to list here. It would be interesting to know which one caused the issue...