Adafruit pca9685 motor shield and control servo motor

Hello guys I am trying to connect two servo motors (sg-90) and control pan/tilt via pca9685 with arduino uno using a GUI (Java application). I was not able to find examples here or on google. Also i dont want to connect my servos direct to uno because i will connect more sensors and servos (motors will be connect to motor shield) later. Finally i am trying to figure out how to set each click of the button will be a degree more or less. any guidance will be helful.

Which part of the extensive Adafruit advice are you having trouble with?

And, just to be clear, this is not the best place to look for advice on Java programming, if that is what you are having trouble with.


Robin2 I hope you are joking with the "extensive Adafruit advise". Maybe i have problem searching around for examples. Please help me if you know any topics or pages. All i want is to control my two servos from my java UI. like a smooth motion of the servo from 0 - 180 and 180 - 0 with two buttons up and down. Also i look few examples with connection of 2 servos straight to uno and it was very simple but not with pca9685 motor shield.

i am new in arduino not in java 8)

I went to the Adafruit product page and there was a link to a tutorial including Arduino examples. I have not read the tutorial page - that's your job :)

Have you studied the tutorial and tried the examples? If there is something you don't understand post a link to the page and tell us exactly what you don't understand.

I presume, as a separate exercise, you have a working Arduino program that can receive the necessary data from your Java program. Don't try to treat the whole project as a single item.


Thanks for the tutorial, i found something that will help me with the motion of the servos (map function).
But still i am trying to figure out about the control. for example the Servo Library

#include <Servo.h>

Servo servo1; Servo servo2; 

void setup() {

  servo1.attach(14); //analog pin 0

  servo2.attach(15); //analog pin 1


void loop() {

  static int v = 0;

  if ( Serial.available()) {
    char ch =;

    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
      case 's':
        v = 0;
      case 'w':
        v = 0;
      case 'd':
      case 'a':



In my case i have the Adafruit PWM servo library.
something like pointing the servo first :
pwm.setPWM(0, 0, pulse);//using map() instead pulse
But how i will “write” my degrees from the console?

ficis82: But how i will "write" my degrees from the console?

That suggests to me that you did not read the final paragraph of my Reply #3. You certainly did not respond to it.

If you have the servos working put all that to one side for a while and just write a Java program and a corresponding Arduino program to send messages to the Arduino. This Python - Arduino demo should provide a suitable template. Also look at Serial Input Basics which was written more recently.


Happy New Year 1.No i didnt read the last paragraph. :-[ 2.These days i managed to secure communication between the arduino and the gui. 3.I moved only the x-axis servo with ~2 degrees step using the map function and a button from gui. 4.Next step is getting values from couple sensors to the gui. 5.I need some guidance about a design problem. My main idea is making a gimbal but with motion left-right and updown. I think this is kind tricky because when you try to move it up and down it will interfere with the stabilisation mechanism. That means i have to change the pitch value and transform it to degrees in the gimbal mechanism. Any suggestions will be helpfull.

ficis82: Any suggestions will be helpfull.

You are not giving us much to go on.

As far as I can figure you can now reliably send data from your GUI to the Arduino.

But you have told us nothing about what data you plan to send or how you expect the Arduino to respond to it. Give some examples of the data you intend to send and what you want the Arduino to do.

And I'm not sure if you have yet managed to get the Arduino to send data to the PC for display in the GUI.


This guy trying to move his gimbal with his joystick but as far i can see the movement while he is doing it is not stabilized. My idea is closed to him, but i want to move my camera with stabilization too from the GUI. At this point i am able to move the camera from GUI successfully. I think the most suitable sensor doing this think is the gy-80. I managed to send and receive data from arduino to gui. I want my camera be installed on a boat, absorbes the motions (pitch roll yaw) of the boat but also be able to controlled from my GUI.

I find it almost impossible to help when I ask questions and then your next Reply introduces a bunch of additional stuff but makes no effort to answer the questions and move the project onwards in a logical sequence.

Developing and debugging a program requires a systematic and logical step-by-step approach. Not a scattergun.


:astonished: Look i am not the best kind of guy that will give you understand what is inside my head and having also as obstacle the language (i am from Greece). I didnt want to tell about my secondary sensors (temperature, pressure etc) because i think i find a solution quick and also i appreciate all the help from your posts. In my last Reply#8 i thought i gave you a good and general idea what is my little head with the first link :D .

Here is a sample of my progress at this moment: Java serial input manipulation

 public synchronized void serialEvent(SerialPortEvent oEvent) {
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            try {
                 inputLine = input.readLine(); //string from com
      String[] datadht11 = SerialClass.inputLine.split(",");
      String temp=datadht11[2];
      String hum=datadht11[1];
      hum_text.setText(hum + " %");
      temp_text.setText(temp + " °C");
            } catch (IOException e) {
               // System.err.println(e.toString());


And the arduino code:

if (Serial.available() > 0) {
                // read the incoming byte:
                income =;
                int pulse=map(45, 0, 180, SERVOMIN, SERVOMAX);
                //double pulse=45;
              case 01:
              x_axis +=2;
              pulse = map( x_axis, 0, 180, SERVOMIN, SERVOMAX );
              Serial.println("Servo #1 +2");
              case 02:
              x_axis -=2;
              pulse =  map( x_axis, 0, 180, SERVOMIN, SERVOMAX );
              Serial.println("Servo #1 -2");
              case 11:
              y_axis -=2;
              pulse = map( y_axis, 0, 180, SERVOMIN, SERVOMAX );
              Serial.println("Servo #2 -2");
              case 12:
              y_axis +=2;
              pulse =  map( y_axis, 0, 180, SERVOMIN, SERVOMAX );
              Serial.println("Servo #2 +2");
                // say what you got:
                Serial.print("I received: ");
        // DISPLAY temp humidity DATA
        int chk = DHT.read11(DHT11_PIN);
        Serial.print(DHT.humidity, 1);
        Serial.println(DHT.temperature, 1);

Thanks again