Need help with PS3 Controller & USB Host Shield controlling a Robotic Arm

Hi all, sorry if I'm doing this wrong, first time posting here in the forums and still somewhat new to the Arduino environment.

I'm currently creating a Robotics Arm project with 4 MG90S 180 degree servos (all four connected to a sensor shield v5), hoping to control it using a PS3 controller with the USB host shield and a USB bluetooth receiver. (So total of 2 shields, sensor shield and USB shield) Currently using a 6V (4AA) power supply to power all 4 servos but I can replace that with 2 18650 batteries to increase the voltage to 7.4v.

So far connecting the controller with the Arduino has no issues, tested fine with 1 servo using the joystick, I was able to map analog values from the joystick 0-255 to the servo 0-180. But when I start adding the rest of other 3 servo codes, the controller (also serial monitor) starts slowing down to the point where it no longer controls the servos' movements (not even the 1st servo that was tested ok)

Can anyone give me some ideas with where my code might be causing issues? Why is it slowing down?

I used this Arduino page as a reference for 1 servo project. The USB host shield library should be okay as I could not find any similar problems from other people.

Thanks in advance!


My code:

#include <SPI.h>
#include <PS3BT.h>
#include <Servo.h>

USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);

Servo claw;
Servo bigarm;
Servo smallarm;
Servo base;

void setup() {

   Serial.begin(115200);

   if (Usb.Init() == -1) 
   {
   Serial.print(F("\r\nOSC did not start"));
   while (1); //halt
   }

  Serial.print(F("\r\nPS3 Bluetooth Library Started"));

  bigarm.attach(9);
  smallarm.attach(10); 
  base.attach(11); 
  claw.attach(6); 
}

void loop()
{

  Usb.Task();
  
  if (PS3.PS3Connected || PS3.PS3NavigationConnected) 
    {
    bigarm.write(map(PS3.getAnalogHat(RightHatX), 0, 255, 0, 180));
    smallarm.write(map(PS3.getAnalogHat(RightHatY), 0, 255, 180, 0));
    base.write(map(PS3.getAnalogHat(LeftHatX), 0, 255, 0, 180));
    claw.write(map(PS3.getAnalogHat(LeftHatY), 0, 255, 0, 180));
    }

}

Code compiled fine and serial monitor was able to connect my PS3 controller with the Arduino, but as soon as I start moving the joystick around, it gets stuck and becomes "stupid".

How are the servos powered?

Which servo worked initially?

You are aware of which pins the USB Host shield uses, right?

You know that servos do not have to be connected to PWM pins, right?

If I were troubleshooting this, I would want to take out the servos and just test the PS3.

So, instead of

bigarm.write(blahblah);

try

Serial.print(blahblah)

Or to put all in a slightly more readable format:

Serial.print(PS3.getAnalogHat(RightHatX));
Serial.print("\t");    // prints a tab
Serial.print(PS3.getAnalogHat(RightHatY));
Serial.print("\t");
Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print("\t");
Serial.println(PS3.getAnalogHat(LeftHatY));
Serial.println("");      // prints a carriage return

That is untested code but put it in and see what happens.
Comment out the lines that write to the servo and use these Serial prints instead.

Do you get the values you expect?
Does the program show the slowdown?

If that works, go back to your 1 servo working example. (maybe even post it here)
Then just add 1 additional servo and see what happens.

Got it figured out! Code works fine, it's the 4AA batteries, guess it's not providing enough voltage. Now I'm using 2 18650 batteries so it's getting a lot more juice, thanks for the assistance guys!