Problem with my new servo

Hello,

I recently bought a new continuous rotation servo from ebay:
http://cgi.ebay.com/15KG-Spring-RC-SM-S4315R-360-degree-Servo-SpringRC-360-/140423438269?cmd=ViewItem&pt=Radio_Control_Parts_Accessories&hash=item20b1e39fbd#ht_1943wt_923

I'm having a problem with it however. Whenever I plug in the red/positive wire if I have the black already plugged in (or if I plug in the black wire if I already have the red wire plugged in), it makes the tx/rx leds flash on my arduino board, and if I have serial monitor up and running, I get these messages in my main Arduino window (the black area with red text):

Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
      at gnu.io.RXTXPort.nativeavailable(Native Method)
      at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
      at processing.app.Serial.serialEvent(Serial.java:215)
      at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
      at gnu.io.RXTXPort.eventLoop(Native Method)
      at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)

(It just loops over and over)

Then, if I plug in my control wire to my arduino, it usually does nothing. If I keep unplugging it, and plugging it back in though, it will usually do something, but not what the code says usually. If I keep doing this, it seems to turn off randomly, change directions and speeds all randomly. I made a video of this and put it on YouTube:

(The first 1:30 seconds are of my working servo that I bought from Sparkfun, so you can skip to about there to see my new, ?bad? one)

I'm pretty sure I have everything plugged in correctly, because as you see in the video, I can get my other servo that I bought from Sparkfun to work just fine:

And if you click on the datasheet for it, you'll see that the new one I bought from eBay is almost exactly the same as the one from Sparkfun. (I bought the one from ebay because I need a lot more torque than the one from Sparkfun).

Oh, here's my code:

// Controlling a full rotational servo

// Attach red wire of servo to +5V on Arduino
// Attach black wire of servo to GND on Arduino
// Attach control wire of servo to pin 9 on Arduino

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 

void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 

void loop() 
{  
  

  //for (int i=1; i <= 3; i=i+1)
    // {
     // myservo.write(i);
        //Serial.print("Running motor at: ");
        //Serial.println(i, DEC);
     // delay(1000);
    //  }
      

  
  //myservo.writeMicroseconds(1500); //stay idle
  
  myservo.writeMicroseconds(2500); //
  Serial.print("Running motor at: ");
  
 
  
}

So I'm just wondering if I'm correct in thinking that the servo is bad, because I need to return it within 7 days. I just can't figure out how a servo can be bad in a way that causes my Arduino to act all weird like it does (flashing those tx/rx lights and giving the error messages).

Thanks.

Ok, my bad.
When I say 'plug in', I mean taking a hookup wire and connecting it from my servo to my Arduino board (Duemialnove btw).
Yes, I'm supplying power to the servo from my Arduino: I have the 5v on my Arduino connecting to the red wire on my servo, and the GND on my Arduino connecting to the black wire on my servo, and pin PWM 9 on my Arduino connecting to the white wire on my servo.
(Actually, a lot of this can be seen in the YouTube video I posted, but I guess I should've posted it here too to make it easier, huh?

Thanks.

That's a pretty large servo - it should -not- be connected to the power from the Arduino's regulator; instead, it should have its own separate supply. Your problems you may be seeing could be caused by the servo drawing more current from the supply than it can handle, potentially causing the Arduino to reset or other issues to occur. Put it on its own power supply, and tie the ground together to the Arduino's ground.

No way you can power that servo from your arduino!

Ok, thanks everyone so far for your help. I'm sorry I didn't answer the how much current question earlier - no, I do not know how much current it needs - the datasheet does not provide that info. I thought that it would be ok to hook it up to the Arduino for power because the datasheet for it gives specs for both 4.8v and 6v, and since both servos are practically identical, I didn't think I'd have a problem.

But you're the experts...I will figure out how to power it separately, test, and report back.

Well, I connected my servo directly to a 5vdc power supply (Wall Adapter Power Supply - 5VDC, 2A (Barrel Jack) - TOL-15312 - SparkFun Electronics), but still no go. More specifically, I connected the positive of the adapter to the red wire on the servo, the negative to the black wire on the servo and also to one of the GND pins on my Arduino, and then I had my PWM pin 9 going to the white wire of the servo, same problem. :frowning:

I know its probably a stupid comment, but you never mentioned plugging the adapter into the wall socket! ;D

Is the problem exactly the same as originally?

Hehe, yeah, I understand you have to ask that question to a newbie - yes, I did plug it into the wall (actually my power strip)...and the adapter has a little red led to show that it's got power, and that was lit...besides - the servo would never spin if it didn't have power, right?
(I also checked the voltage coming from the ac adapter, and it was getting 5.15 volts, so that's sufficient, right?)

It may not have been exactly as before - it probably turned on a little more often (because remember - I have to actually connect and disconnect the PIN 9 going to the control/signal wire (white) on the servo several times before the servo would actually rotate) than it did originally (plugged directly into the Arduino), but it still did not turn on most of the time, and it was still unpredictable as far as what speed and direction it would go...and the only way to get it to stop once it was started was to unplug the red or black wire, just like before.

Ok, I received my new servo a while back, and running some tests, it seems to work fine.

However, now I'm having a problem trying to use it in a little more complicated way. What I'm trying to do is have a pushbutton that toggles the servo to spin, and stop. I took the (modified) example straight from:

and just added a few of my 'own' lines of code to actually control the servo along with the LED.

So here's my code so far:

// Controlling a full rotational servo

// Attach red wire of servo to TO SEPARATE POWER SUPPLY
// Attach black wire of servo to GND on Arduino
// Attach control wire of servo to pin 9 on Arduino





// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin =  13;     // the number of the LED pin

// Variables will change:
int ledState = LOW;         // the current state of the output pin
int lastButtonState = LOW;  // the previous debounced button state
int lastReading= LOW;       // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the input pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers



int servoState = 1500; // the current state of the servo

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 



void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
} 

void loop() 
{  

  
  //myservo.writeMicroseconds(1500); //stay idle
  
  //myservo.writeMicroseconds(1500); //
  //Serial.print("Running motor at: ");
  
  
  
  
  
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH),  and you've waited
  // long enough since the last press to ignore any noise:  

  // If the switch changed, due to noise or pressing:
  if (reading != lastReading) {
    // reset the debouncing timer
    lastDebounceTime = millis();
    // save the reading.  Next time through the loop,
    // it'll be lastReading:
    lastReading = reading;
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so accept the button changed state:
  
    // toggle the LED if the state of the button changes from LOW to HIGH:
    if (lastButtonState == LOW && reading == HIGH) {
      if (ledState == HIGH) {
        ledState = LOW;
        servoState = 1500;
        //myservo.writeMicroseconds(1500);
      } else {
        ledState = HIGH;
        servoState = 3000;
        //myservo.writeMicroseconds(500);
      }
      digitalWrite(ledPin, ledState);
      myservo.writeMicroseconds(servoState);
    }
    lastButtonState = reading;
  }
  
  
  
 
  
}

My first problem is that when I power up the servo (plug the wall wart in that's supplying separate power), the servo starts spinning even though the LED on the Arduino Duemilanove board is off (I can live with this problem though). Then I push my momentary pushbutton, and this turns on the LED as expected, and my servo keeps turning. Then I push the pushbutton again, and it turns off the LED and the servo (I know it doesn't actually turn it off, it sets the microseconds to 1500, which is idle). So far, so good.

Now, my problem: I push the pushbutton again to turn on the LED and servo, and the LED turns on, but the servo doesn't spin. And I keep pushing the button to turn the LED on and off all I want, but the servo acts kind of 'dead' - it not only doesn't spin, but when I pick it up, I don't feel those tiny vibrations that I normally feel when it's spinning or idling properly.

To get it working again, I have to unplug the power to my servo, and push the reset button on my Arduino board, plug back in the power for the servo, but the same thing happens again. It spins, I push the button, it keeps spinning, push again and it stops, push again and nothing as far as the servo goes.

Is something wrong with my code?

Ok, I'm sorry guys, I just had an idea to hook up my identical, but lower-torque servo and see if the same thing happens - it doesn't.

It works exactly as expected, so I guess my newer higher-torque one isn't exactly a 100% good, working one after all. :frowning:

Now I don't know what to do.

Perhaps the "newer higher-torque one " is a digital servo instead of an analog servo.

Oh. I guess I'll have to look up what the difference between analog and digital servos are and how to use them with my Arduino.

Thanks everyone thus so far.