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