Servo in the Experimenter's Kit

The Experimenters Kit includes an "Eleven" Arduino-compatible board, plus a range of parts and a guide to make it easy to get started with Arduino projects. [Product Page]
gth
Posts: 3
Joined: Tue Apr 30, 2013 5:51 am

Servo in the Experimenter's Kit

Post by gth » Tue Apr 30, 2013 7:25 am

Not sure if I have an error in my code, my wiring or the servo I got, but I'm seeing the following issues:
  • If I write values 64 or less to the servo's PWM pin it spins straight to what seems to be its lower limit, and sits there making noise until I write a value of 65 or higher.
  • The teeth on the servo seem to get momentarily stuck when passing the position linked to writing a value of 180. This glitching is momentary and happens when passing this point in either direction.
  • Writing a value over 245 causes the servo to get totally confused - it tries to rotate in the incorrect direction (I'm guessing, a position more likely to be '300') and hovers randomly in that area making noises, until I reset the board.
This is the servo bundled with my experimenter's kit. Wiring is exactly as shown for "Project 6" at the PDF URL below. Power is from my PC's USB port, of which I've tried others without any change in the behaviour.
http://cdn.shopify.com/s/files/1/0045/8 ... e-v1_1.pdf

Code:

Code: Select all

int servoPin = 11;
int servoPosition;
int lowerbound = 65;
int upperbound = 245;
int stepcount = 1;
int delayTime = 10;

void setup() {
  pinMode(servoPin, OUTPUT);
}

void loop() {
  for (int servoPosition = lowerbound; servoPosition <= upperbound; servoPosition = servoPosition + stepcount) {
    analogWrite(servoPin, servoPosition);
    delay(delayTime);
  }
  
  delay(delayTime*100);
  
  for (servoPosition = upperbound; servoPosition >= lowerbound; servoPosition = servoPosition - stepcount) {
    analogWrite(servoPin, servoPosition);
    delay(delayTime);
  }
  
  delay(delayTime*100);  // [b]
}
PS: To be clear: very happy with the kit and all the projects up to this point, by the way. :)

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Servo in the Experimenter's Kit

Post by angusgr » Tue Apr 30, 2013 11:45 pm

Hi gth,

Sorry to hear the servo is acting up on you.

I realise the Experiment's Kit documentation doesn't make mention of this, but can you try the Arduino Servo library and see if that helps? The Servo library is built into Arduino, there are erven a couple of examples built in - you can load one by going to File menu -> Examples -> Servo -> Sweep.

The reason this might work better is that Arduino analogWrite() outputs PWM (pulse width modulated) signals at a frequency of about 500Hz, whereas most RC hobby servos expect 50-100Hz. This might be why some servos are getting confused and twitchy at the extreme ends, even though some others (even the same model) might work perfectly.

Another thing to try may be connecting external power (either a DC plug pack or a USB phone charger can work well.) Servos can be a bit power hungry.

Please let me know how you go.

Cheers,

Angus

gth
Posts: 3
Joined: Tue Apr 30, 2013 5:51 am

Re: Servo in the Experimenter's Kit

Post by gth » Sat May 11, 2013 2:45 pm

Thanks for the response.

Using the library calls, the servo is now reliably responding to position values 0 to 180. There's still an ugly snag as it passes position 90 from either direction, but I think that's a manufacturing defect with the plastic gears inside the servo, rather than the Arduino code/signalling.

In contrast to the PDF manual's analogWrite/PWM method was able to achieve movement beyond these limits, but it was erratic and occasionally got stuck.

For reference, the code -

Code: Select all

#include <Servo.h>

Servo myServo;
int   servoPin = 9;

void setup() { 
  Serial.begin(38400);
  myServo.attach(servoPin);
} 

void loop() {
  int lowerbound = 0;
  int upperbound = 180;
  int stepcount = 5;
  int delayTime = 100;
  int servoPosition;

  for (servoPosition = lowerbound; servoPosition <= upperbound; servoPosition = servoPosition + stepcount) {
    myServo.write(servoPosition);  // set servo to mid-point
    Serial.print("Forward sequence: ");
    Serial.println(servoPosition, DEC);
    delay(delayTime);
  }
  delay(delayTime*10);
  
  for (servoPosition = upperbound; servoPosition >= lowerbound; servoPosition = servoPosition - stepcount) {
    myServo.write(servoPosition);  // set servo to mid-point
    Serial.print("Reverse sequence: ");
    Serial.println(servoPosition, DEC);
    delay(delayTime);
  }
  delay(delayTime*10);  
}

Namphibian
Posts: 1
Joined: Sun Nov 24, 2013 9:15 pm

Re: Servo in the Experimenter's Kit

Post by Namphibian » Mon Nov 25, 2013 2:21 am

I had a similar issue with the servo in my experimenters starter pack. This post resolved it for me.

SirJefferE
Posts: 9
Joined: Fri Dec 27, 2013 7:52 am

Re: Servo in the Experimenter's Kit

Post by SirJefferE » Wed Jan 08, 2014 8:56 am

I just want to add a note here. I recently started using the servo supplied in the kit recently (I decided it would be a nice output for a speedometer experiment I'm trying out with a magnetic hall sensor attached to my stroller) and my code so far uses the timer1 library to check my speed.

Because the servo library also uses timer1, I've been looking into ways to control servos without it, but so far every source I can find says *don't* use pwm or analogWrite to control servos, and that it can damage your servo.

I'm still pretty new to servos, so don't take my word for it entirely, but I thought it was important to make a note, as the project guide advises you to use the same analogWrite script you use to pulse an LED.

Hope this helps.


From the below sources:

"You should not use the arduino analogWrite PWM function to drive a hobby servo. They do not use PWM and could damage a servo or speed controller. Its confusing because many references do incorrectly use the term PWM in articles about servos. But hobby servos and speed controllers expect different pulse timings from that provided by analogWrite."

"The analogWrite pwm output just produces a square wave with a duty cycle that can be controlled between 0% and 100%. This is not the sort of signal that a servo needs, so trying to control a servo using analogWrite is basically not going to work. You need to produce a pulse in the range of around 1ms to 2ms repeating at about every 20ms"

Sources: http://forum.arduino.cc/index.php/topic,5701.0.html
http://forum.arduino.cc/index.php/topic,193386.0.html

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Servo in the Experimenter's Kit

Post by andrew » Thu Jan 09, 2014 10:31 pm

The manual for the EXP: kit has been updated:
http://cdn.shopify.com/s/files/1/0045/8 ... ide1.4.pdf

SirJefferE
Posts: 9
Joined: Fri Dec 27, 2013 7:52 am

Re: Servo in the Experimenter's Kit

Post by SirJefferE » Fri Jan 10, 2014 2:43 am

Awesome, looks good.


In response to GTH:
Using the library calls, the servo is now reliably responding to position values 0 to 180. There's still an ugly snag as it passes position 90 from either direction, but I think that's a manufacturing defect with the plastic gears inside the servo, rather than the Arduino code/signalling.
I'm probably months late with this comment, but my servo had the same little snag at around 90 degrees. I opened the top part up and had a look at the gears; the top gear on the middle peg had one tooth bent over. I used a pocketknife to pry it back up and reduced the snag a lot, but there's still some there. Going to have another look at it later and see if I can fix it up better with a bit of glue and carving.

They are pretty tiny and fiddly things, so your results may vary. Just make sure you get a good idea of what order the gears go on the pegs, and maybe take a picture before pulling them off. Took me a few minutes to put it back together!

Edit: Got two new servos in the mail today, both of them work perfectly.

You guys are sneaky, and I like it!

DaveJ
Posts: 9
Joined: Fri Jul 26, 2013 10:03 am

Re: Servo in the Experimenter's Kit

Post by DaveJ » Sun Apr 13, 2014 4:46 am

G'day All, Was wondering if Freetronics could supply me with extra servos as found in the experimenters kit? They are the smallest I have seen and will fit a project I have in mind quite well.
Regards,
Dave J

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Servo in the Experimenter's Kit

Post by andrew » Sun Apr 13, 2014 7:32 am

DaveJ wrote:G'day All, Was wondering if Freetronics could supply me with extra servos as found in the experimenters kit? They are the smallest I have seen and will fit a project I have in mind quite well.
Regards,
Dave J
Email support@freetronics.com

DaveJ
Posts: 9
Joined: Fri Jul 26, 2013 10:03 am

Re: Servo in the Experimenter's Kit

Post by DaveJ » Sat May 24, 2014 10:42 am

G'day Johnb and everyone else.
The email bounced with the following message

Code: Select all

Your message did not reach some or all of the intended recipients.

      Subject:	New servos as found in freetronics experimenters kit
      Sent:	24/05/2014 9:41 AM

The following recipient(s) cannot be reached:

      'support@freetronics.com' on 24/05/2014 9:41 AM
            550 #5.1.0 Address rejected.
thiught you might like to know :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest