NEW servos not working at ALL!!!

hi everyone :slight_smile:

i just got 2 new hitec servos, and i’m having too many problems to count!
ok, i went to the playground here, and installed ALL THE LIBRARIES
i tried sketches, all of them, and when i sent information to my servo through the serial port ( like i sent s90, and i sent w90, and i tried everything!) and the servo did nada.
so i tried to use processing client instead of arduino, and look at that, the mouse example worked!
so i go back and try my sketches again, and alter them with my own code, and some stuff happened when i typed in this code:

#include <Servo.h>  
 
Servo myservo;  
 
void setup() {  
  myservo.attach(2);  // attaches a servo connected to pin 2  
}  
 
void loop() {  
  myservo.write(90);  // position the servo angle at 90 degrees  
  delay(500);
myservo.write(40);
delay(500);



servo:refresh();
}

the servo only spun in one direction every .5 seconds.

so i go back to processing and tyr the mouse thing again, and it still doesent work! ( even though it worked before! )

and i tried to potentiometer test, and the code is here:

/*
  Single hitec servo control via a analog input
  Author: Brett Forsyth
  Create: Nov. 3 / 2007
  
  This sketch will allow you to control a hitec servo with an analog input.
  
  Original code and setup tutorial by Tom Igoe - http://itp.nyu.edu/physcomp/Labs/Servo
  
 
 */

int servoPin = 2;     // Control pin for servo motor
int minPulse = 900;   // Minimum servo position
int maxPulse = 2100;  // Maximum servo position
int pulse = 0;        // Amount to pulse the servo

int refreshTime = 20; // the time needed in between pulses

int analogValue = 0;  // the value returned from the analog sensor
int analogPin = 0;    // the analog pin that the sensor's on

void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pulse = minPulse;           // Set the motor position value to the minimum
}

void loop() {
  analogValue = analogRead(analogPin);      // read the analog input
  pulse = (((float)analogValue / (float)1023)*1200) + 900; 

    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    delay(refreshTime);
}

and EVERYTHING is connected to the right place, i quad droopled million checked, red is in 5v, black is in gnd, and white is in pin 2, while the pot is in pin 0 ( analog )

and i even tried to send the serial info of the pot, and it was correct and fine.

the servo is obviously working becuase it spun with the mouse example, but now it doesent.

just as a not, i did install the processing firmware through arduino, and im pretty sure that the firmware goes away after you write over it a new sketch, but im not sure, if somebody could answer that too, that would help!

so to be clear:
-i have all servo libraires.
-the mouse servo control example in processing worked, but now it doesent
-no servo sketch that was pre written works ( non do at all )
-my self made sketch works, but very crapily
-i get some error messages before the size and info about the sketch, but even though there are error messages, it still sends it to the arduino ( for refrence, this is whats written in red above the sketch info in the black serial screen:
ServoTimer1.cpp: In static member function ‚Äėstatic void ServoTimer1::seizeTimer1()‚Äô:
ServoTimer1.cpp:43: error: ‚ÄėTICIE1‚Äô was not declared in this scope)

please help, ive been sitting here for 3 hours trying to figure why this doesent work, and please ANYBODY answer me as soon as you can, even if you think you know, andy help matters!
ill keep trying to work it till i get some help from u guys, thanks in advacne for any help

-big93

I found that a servo drew a little more current then my board could provide and only got reliable operation with the servo powered from a separate supply. I connected the red and black wires from the servo to a 4 cell battery pack. The black wire also connects to the arduino gnd pin and the servo signal wire (white on most Hitec servos) to the arduino output pin.
but first, try modifying your myservo code so that it is something like:

myservo.write(90); // Tell the servo class that we want to position the servo angle at 90
for(int i=0; I < 20; i++)
servo:refresh(); // I am assuming that this will write a pulse to the servo and wait for 20 milliseconds

myservo.write(40);
for(int i=0; I < 20; i++)
servo:refresh();

Also, in your second sketch, try sending the value of pulse to the serial port in the loop
Serial.println(pulse,DEC); to verify that it changes between 900 and 2100 as the pot rotates.

oh yes, thats what i meant, i put in the printin thing so it will tell me if my pot is working, and it was, it's just the darn servo, and since the servo drains alot of power, shudent it work atleats some of the time? and whats with the errors i get when compiling a pre made skit, that error that i put before is still there...

thnks for the quick reply, im tryng the seprate power source as we speak

and whats with all the "for i = nt 0 stuff after the 90 degree command? and also, how do i make it turn in the other direction? it seems to be stuck trying to push it's way into a turn that's past its capability, and i've tried everything to make it go the other direction, but it wont budge

I think they way that library works is that the calls to refresh() send out the servo pulses. The actual pulse width on a pin is determined by the parameter passed on the most recent call to MyServo.write for that pin. But it's the calls to refresh() that generate the pulses and the servo needs lots of them to move.

A typical servo can take a few tenths of a second to move from end to end. Each call to refresh() takes 20 milliseconds so this function needs to be called 10 or 20 times (really depends on how fast the servo and how big a swing you are asking for). The example code should send 20 pulses representing 90 degrees for 0.4 seconds (20 ms * 20) and then 20 pulses representing 40 degrees.

I have never used this library so my comments are based on reading the documentation, perhaps someone else that has direct experience with it can verify.

but how do i make it go the oppisite direction, its stuck just trying to go to one side, just going and going, and going, also can you maybe reccomend a library that you use or prefer? ( one you know well so if i get problems, you'll know whats up..)

thnks

I posted my recommendation in response to your other post here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1179784551/15#15

I use my own library, it is much more complicated than the one in servo.zip so I suggest you stick with that. Did you try the for loops? If you post your latest code I may be able to help.

and i still get this:

ServoTimer1.cpp: In static member function ‚Äėstatic void ServoTimer1::seizeTimer1()‚Äô:
ServoTimer1.cpp:43: error: ‚ÄėTICIE1‚Äô was not declared in this scope

but the code works, that is just listed ontop of all the info

and also, ‚Äúready‚ÄĚ does not come up in the serial input screen, just some jumbled up charecters, most of which are boxes.

and the code is:

#include <Servo.h>

Servo servo1; Servo servo2;

void setup() {

  pinMode(1,OUTPUT);
  servo1.attach(14);
  servo1.setMaximumPulse(2200);
  servo2.attach(15);
  Serial.begin(19200);
  Serial.print("Ready");

}

void loop() {

  static int v = 0;

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

    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
      case 'w':
        servo2.write(v);
        v = 0;
        break;
      case 'd':
        servo2.detach();
        break;
      case 'a':
        servo2.attach(15);
        break;
    }
  }

  Servo::refresh();

}

no changes to the original

Do you have #include <servotimer1.h> in servo.h? if so , remove it.

Check the baud rate set in setup() is the same as on your serial terminal

sorry, musta posted while u were postin, the exact code i’m usin is in my last post

I edited my post while you were editing yours ;)

Your error messge relates to servotimer1, so somewhere there must be a reference to it, did you copy it to the same directory as your test sketch (i.e. does servotimer1 appear on a tab in the IDE?)

lol!

ok, i fixed the baud rate, but now when i type "80s" or anything else i just hear my motor turning in a directuion it ran out of degrees, how do i make it turn the other direction

It looks like you press a digit 0 followed by the s key for one extreme and 9 followed by the s key for the other

what do you mean, i dont get what to write... sry noobish i know lol

Not your fault, that code is not easy to follow. I think the following is clearer, add the lines below into the case statment

      case 'x':
        servo1.write(0);   // letter x sends pulses for 0 degrees
        break;
      case 'y':             // letter y sends pulses for 90 degrees                   
        servo1.write(90);
        break;
      case 'z':            // letter z sends pulses for 180 degrees
        servo1.write(180);
        break;

edit: removed a few unnecessary lines

wow, im starting to understand how this works, but the servo is still trying to push in a direction that it cant, its just pushing against whatever is stoping it, i need to reverse the way it goes, and negating things doesent seem to be the answer

edit: lol sorry for the multi thread chat, but the servo is still pushing the wrong way, and i dont want to hand turn the lever, i heard that thats a bad idea

OK, lets try reducing the throw. Replace the 0, 90, 180 values in the three servo1.write statements with 60,90,120 and see what happens

no, it seems to be doing the same thing, and i'm not sure you understand what i'm saying:

i know, that you know all this, but bear with me: the servo has a capability to go 180 degrees.

let's say we started with 0 degrees, and through trying to get it working, the servo ended up at 180 degrees. now what were doing here is trying to push it past 180 degrees, but it cant turn anymore! it's not that it's stuck, it's just that it's turn capabilities are reached, and i need to reverse the way it spins, or find a way to put it back to 0 degrees without hand turning it.

you get what i'm saying? i dont know how well i'm explaining this lol so just try to get me...

Lets see if I understand the problem.

servo1.write(0) [pressing the letter x] should rotate it in one direction.

servo1.write(180) [pressing the letter z] should rotate it something like 180 degrees (actually a little less in my experience).

Is the issue that servo is rotating in the expected directions but not quite 180 degrees? If so, then that is what I would expect to happen with a Hitec servo.

ok, z and x make it spin in the same direction, all the letters make it spin in the same direction, but let me try to explain better:

the servo is not spinning AT ALL
it’s trying to spin, i can hear to motor straining, but its spinning in a direction it was laready spun in, it CANT turn any more in that direction, but it’s still trying.

it thinks it’s at 0 degrees, but it’s actually at 180 degrees, so when it tries to spin, it’s pushing against the 180 degree stopping point, and thus it doesent turn, becuase it’s reached it’s maximum turn capability in that direction

will hand turning it back to 0 degrees break or ruin the gears?

edit:
even though i shouldent have, i hand cranked it back to 0 degrees, but it only spins in one direction, it doesent turn back to the other direction once it reached its maximum, heres the code i have so far:

#include <Servo.h>

Servo servo1; Servo servo2;

void setup() {

  pinMode(1,OUTPUT);
  servo1.attach(14);
  servo1.setMaximumPulse(2200);
  servo2.attach(15);
  Serial.begin(9600);
  Serial.print("Ready");

}

void loop() {

  static int v = 0;

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

    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
      case 'w':
        servo2.write(v);
        v = 0;
        break;
      case 'd':
        servo2.detach();
        break;
      case 'a':
        servo2.attach(15);
        break;
      case 'x':
        servo1.write(60);   // letter x sends pulses for 0 degrees
        break;
      case 'y':             // letter y sends pulses for 90 degrees                   
        servo1.write(90);
        break;
      case 'z':            // letter z sends pulses for 180 degrees
        servo1.write(120);
        break; 
  
}
  }

  Servo::refresh();

}

I would expect that to happen if the pulses were not of the correct width.
I am not sure why that is the case but its very late where I am so I am off to bed. I will think on it an come back tomorrow