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()
{
Serial.begin(115200);
//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.attach(m1p);
motor2.attach(m2p);
motor3.attach(m3p);
motor4.attach(m4p);
motor1.writeMicroseconds(0); //make sure throttle is at zero
motor2.writeMicroseconds(0);
motor3.writeMicroseconds(0);
motor4.writeMicroseconds(0);
delay(200);
void loop() {
Usb.Task();
#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));
}
#endif
else
{
motor1.write(40);
motor3.write(40);
motor2.write(40);
motor4.write(40);
}
}
**Note:
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.