Robotic arm control

Hi guys. I need help.

I built a robotic arm and I want to control it through android app on my phone.

Servos are all hooked to PCA9685 16 channel servo driver.

I wrote the app so that it sends an upper case character to start the motion of a designated servo and a lower case character to stop the motion. I managed to print the recieved characters and they show in decimal form in Serial monitor.

So for example when I want the base servo to move I hold the 'base servo button' down which sends the character ''A'', that shows up as ''65'' in Serial monitor, this should start the motion of the base servo. When I let go of the button the app sends ''a'' which shows up as ''97'' in serial, this should stop the motion of the base servo.

However none of that happens. The characters either don't show up in serial monitor or the servos don't move at all even though the characters show up.

So my question is: How would you approach this? All I need is an example code for one servo.

Klingatch:
How would you approach this?

I would post my code here so that the forum members who enjoy helping out can work with your to resolve the problems.

Post your code. Use code tags.

You say

The characters either don't show up in serial monitor or the servos don't move at all even though the characters show up.

I think you need to break down the project and get individual pieces working.
If some times the characters do not show up, you have a problem in the communication between your android and the arduino. No amount of servo debugging with fix that. Resolve the communications first.

Yeah here is the code, sorry.

I just wanted to see how someone else would write the code. I figured that the problem would be communication just don't know where exactly.

#include<SoftwareSerial.h>
#include<Wire.h>
#include<Adafruit_PWMServoDriver.h>                         //Knižnice

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver ();   //Adresa Servo Driver
SoftwareSerial mySerial(10,11);                             //Softwarova linka Arduina ,definovanie RX,TX

#define TRUE 1
#define FALSE 0

#define Base_Rot_L_GO          65             //Command na zapocatie rotacie zakladne vlavo
#define Base_Rot_L_STOP        97             //Command ma ukoncenie rotacie zakladne vlavo
#define Base_Rot_R_GO          66
#define Base_Rot_R_STOP        98
#define Base_U_GO              67
#define Base_U_STOP            99
#define Base_D_GO              68
#define Base_D_STOP            100
#define Elbow_U_GO             69
#define Elbow_U_STOP           101
#define Elbow_D_GO             70                           //Definovanie znakov úkonov v decimalnom tvare
#define Elbow_D_STOP           102
#define Gripper_U_GO           71
#define Gripper_U_STOP         103
#define Gripper_D_GO           72
#define Gripper_D_STOP         104
#define Gripper_Rot_L_GO       73
#define Gripper_Rot_L_STOP     105   
#define Gripper_Rot_R_GO       74 
#define Gripper_Rot_R_STOP     106
#define Grip_GO                75
#define Grip_STOP              107
#define Release_GO             76
#define Release_STOP           108

int BaseRAngle=320;                                       //Inicializacne uhly
int BaseEAngle=320;
int ElbowAngle=215;
int GripperEAngle=435;
int GripperRAngle=350;
int GripperOpen=120;

struct Servo{                                             //Vytvorenie struktury 'Servo'
  int Pin;
  int Angle;
  int MovementUp;
  int MovementDown;
  int InitAngle;
  int BoundMAX;                                         //Atributy struktury
  int BoundMIN;
  int CommandUpStart;
  int CommandUpStop;
  int CommandDownStart;
  int CommandDownStop; 

  void pin(){                                       //Funkcia pre pociatocne nastavenie ramena
    pwm.setPWM(this->Pin,0,this->InitAngle);          //Nastavi PWM na danom pine na inicializacny uhol serva  
    delay(1000);                                      //Caka na dokoncenie pohybu
  }

  void moveUP(){                                      //Funkcia pre zvacsovanie uhlu
    if(this->MovementUp == TRUE){
      this->Angle++;
      if(this->Angle >= this->BoundMAX){              //Ak nadobudne svoju maximalnu vychylku---zastav
        this->Angle = this->BoundMAX;
      }
    }
  }

  void moveDOWN(){                                    //Funkcia pre zmensovanie uhlu
    if(this->MovementDown == TRUE){
      this->Angle--;
      if(this->Angle <= this->BoundMIN){              //Ak nadobudne svoju minimalnu vychylku---zastav
        this->Angle = this->BoundMIN;
      }
    }
  }

  void react(int Command){                                //Rozpoznavac prikazov(commandov)
    if(Command == this->CommandUpStart){                  //Ak je prijaty prikaz na zvacsenie uhlu
      this->MovementUp=TRUE;                              //registruj pohyb serva
    }   
        else if(Command == this->CommandUpStop){          //Ak je prijaty prikaz na ukoncenie zvacsovania uhlu
        this->MovementUp=FALSE;                           //registruj ukoncenie pohybu serva
        }
        else if(Command == this->CommandDownStart){
        this->MovementDown=TRUE;
        }
         else if(Command == this->CommandDownStart){
        this->MovementDown=FALSE;
        }
  }

  void move(){                                            //Funkcia samotneho pohybu
    if(this->MovementUp=TRUE){                            //Ak je registrovane zvacsovanie uhlu
      moveUP();                                           //zvacsuj uhol
    }
      else if(this->MovementDown=TRUE){
        moveDOWN();
      }

    pwm.setPWM(this-Pin,0,this->Angle);                   //Vysli PWM signal
  }
 };

Servo* BaseServo1;                                        //Definovanie instancii struktur pre jednotlive serva
Servo* BaseServo2;                  
Servo* ElbowServo;
Servo* GripperServo1;
Servo* GripperServo2;
Servo* GripperServo3;


void setup() {
  
  Serial.begin(9600);
  mySerial.begin(9600);                        //Zapnutie seriovych liniek
  pwm.begin();                                 //Zapnutie vysielania PWM signalu
  pwm.setPWMFreq(60);                          //Nastavenie frekvencie PWM signalu  (analogove serva okolo 60Hz)
 

BaseServo1 = new Servo{0,BaseRAngle,FALSE,FALSE,BaseRAngle,600,100,Base_Rot_L_GO,Base_Rot_L_STOP,Base_Rot_R_GO,Base_Rot_R_STOP};                              //Specifikovanie premennych jednotlivych instancii pre konkretne serva
BaseServo1->pin();

BaseServo2 = new Servo{1,BaseEAngle,FALSE,FALSE,BaseEAngle,600,100,Base_U_GO,Base_U_STOP,Base_D_GO,Base_D_STOP};                  //NAZOV = JEDNA SA O NOVU INSTANCIU STRUKTURY SERVO{PIN,POCIATOCNY UHOL, POCIATOCNY POHYB,,INICIALIZACNY UHOL,MAX,MIN,PRIKAZY}
BaseServo2->pin();                                                                                                               //Vykonaj funkciu pin--pohni sa do svojej inicializacnej polohy

ElbowServo = new Servo{2,ElbowAngle,FALSE,FALSE,ElbowAngle,560,100,Elbow_U_GO,Elbow_U_STOP,Elbow_D_GO,Elbow_D_STOP};
ElbowServo->pin();

GripperServo1 = new Servo{3,GripperEAngle,FALSE,FALSE,GripperEAngle,540,180,Gripper_U_GO,Gripper_U_STOP,Gripper_D_GO,Gripper_D_STOP};
GripperServo1->pin();

GripperServo2 = new Servo{4,GripperRAngle,FALSE,FALSE,GripperRAngle,530,170,Gripper_Rot_L_GO,Gripper_Rot_L_STOP,Gripper_Rot_R_GO,Gripper_Rot_R_STOP};
GripperServo2->pin();

GripperServo3 = new Servo{5,GripperOpen,FALSE,FALSE,GripperOpen,510,120,Grip_GO,Grip_STOP,Release_GO,Release_STOP};
GripperServo3->pin();


Serial.println("Connected");
}


void loop() {

  int Command = mySerial.read();
delay(10);
  //Serial.println("Connected");

  if(mySerial.available()){
    Serial.println(mySerial.read());
  }

BaseServo1->react(Command);                                                                                         //Ked prijmes prikaz pre zakladove servo, reaguj podla funkcie react
BaseServo1->move();                                                                                                 //pohni servom na zaklade typu prikazu

BaseServo2->react(Command);
BaseServo2->move();

ElbowServo->react(Command);
ElbowServo->move();

GripperServo1->react(Command);
GripperServo1->move();

GripperServo2->react(Command);
GripperServo2->move();

GripperServo3->react(Command);
GripperServo3->move();
}

Show the proper sketch. Above code contains errors, should not compile at all.
Split your program into basic parts.
Verify that your commands are decoded properly. You can use some LEDs to show which command is active. If this does not work, fix the errors in the input part.
Verify that the servos move. Use switches for the activation of the command functions. If this doesn't work as expected, fix the errors in the output part.

How may many DOF is there