Tower Pro MG 945 Servo

Does anyone know how to control Tower Pro MG945 Servo using arduino servo library?

In what way is an MG945 different from other servos ?

I presume you have tried the servo examples that come with the Arduino IDE ?

...R

No I tried. It's not working properly with the Sweep example.

bmthilina:
No I tried. It's not working properly with the Sweep example.

Now answer my other question and we might make some progress.

How are you powering the servo - do NOT use the Arduino 5v pin. Give the servo its own power supply and connect the servo GND to the Arduino GND.

...R

Done. But the problem is still there. I think the problem is the servo can't identify the angle we give. It keep rotating until it get stuck. Because of this problem the motor is damaged physically as well.

bmthilina:
Done. But the problem is still there. I think the problem is the servo can't identify the angle we give. It keep rotating until it get stuck. Because of this problem the motor is damaged physically as well.

Does "Done" mean that you have provided a separate power supply ? It is helpful to be precise.

Have you another servo to try. If that works it may suggest that the MG945 is broken.

Since you did not answer my question I am assuming that an MG945 control system is the same as any other servo.

...R

Basic servo test code for use with the serial monitor. Attached is a basic diagram of how to wire the servo to an external power source.

// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h> 
String readString; //String captured from serial port
Servo myservo;  // create servo object to control a servo 
int n; //value to write to servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
  Serial.println();
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 

      // attach or detach servo if desired
    if (readString == "d") { 
      while (digitalRead(7)) {} //delay loop until pin 7 is low
      myservo.detach(); //detach servo
      Serial.println("servo detached");
      goto bailout; //jump over writing to servo
    }
    if (readString == "a") {
      myservo.attach(7); //reattach servo to pin 7
      Serial.println("servo attached");
      goto bailout;
    }    

    n = readString.toInt();  //convert readString into a number

    // auto select appropriate value
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n); 
    }

bailout: //reenter code loop
    Serial.print("Last servo command position: ");    
    Serial.println(myservo.read());
    Serial.println();
    readString=""; //empty for next input
  }
}

servo-wire.jpg

Robin2:
Does “Done” mean that you have provided a separate power supply ? It is helpful to be precise.

Have you another servo to try. If that works it may suggest that the MG945 is broken.

Since you did not answer my question I am assuming that an MG945 control system is the same as any other servo.

…R

Yes, I supplied external power. Still it doesn’t work properly. I tried same sweep example with Tower Pro SG90 Servor. It works very well. My MG945 is also not broken because I tried with 2 same MG945 servos. Both of them gave me the same bad result. I think the problem is with the model.

I saw an online specification sheet says SG90 has an Analog modulation and MG945 has Digital modulation. Could it be the problem?

bmthilina:
I saw an online specification sheet says SG90 has an Analog modulation and MG945 has Digital modulation. Could it be the problem?

If you recall my first question to you in Reply #1 was
In what way is an MG945 different from other servos ?

Post a link to the datasheet for the MG945

...R

I found it from here.

bmthilina:
I found it from here.

I can't see anything in that link to suggest it requires a different control system from any other servo.

What happens if you write a short piece of code that just commands the servo to move to 100deg and stay there ? Just a simple myServo.write(100);

When it is disconnected from everything can you gently turn the servo arm with your fingers ? If so, how far can it turn between the end-stops?

...R

Before I code, It turned 180 degs. But when I put the sweep code, It was keep rotating towards 0 to 180 direction until it get stuck. Now the motor is stuck. I can't even rotate it with my fingers. This happened to both of my servos.

bmthilina:
Before I code, It turned 180 degs. But when I put the sweep code, It was keep rotating towards 0 to 180 direction until it get stuck. Now the motor is stuck. I can't even rotate it with my fingers. This happened to both of my servos.

Then stop using the sweep code, Poor or no ground connection between the servo ground and the arduino ground can cause erratic operation, possibly jamming the gearing against the internal hard stop. You probably need to unscrew the top of the servo to see what is jammed inside.

bmthilina:
Before I code, It turned 180 degs. But when I put the sweep code, It was keep rotating towards 0 to 180 direction until it get stuck. Now the motor is stuck. I can't even rotate it with my fingers. This happened to both of my servos.

Well why didn't you tell us that in your first post ?

It strongly suggests that the servo responds properly to the Servo library and that it probably cannot move through the full range 0 to 180 deg.

Do as @Zoomkat has suggested.

...R

I connected external power and common ground correctly. Fixed the jammed gears as well. But even I put myservo.write(10), It keeps rotating forward until it get jammed. Didn't you ever experienced this kind of error with MG945?

My code is working very well with SG90, which is also from TowePro.

bmthilina:
But even I put myservo.write(10), It keeps rotating forward until it get jammed.

It's just possible that it can't go as far as 10 deg. Try something in the middle like 90deg.

...R

I connected external power and common ground correctly. Fixed the jammed gears as well. But even I put myservo.write(10), It keeps rotating forward until it get jammed. Didn't you ever experienced this kind of error with MG945?

I still say you probably have poor ground wiring, which will cause disturbances on the servo control wire. Servos that get corrupt control pulses will turn in one direction until they hit the internal hard stop.

Hi,
Sounds like the internal servo controller has either no feedback from its feedback pot (broken?), or it is out of sync with the servo shaft position.

Tom… :slight_smile: