Roll Your Own Servo Tester

So you want to test the range of your servos.  Who needs a servo tester/driver?  If you have a MCU, a POT and some wire, you can make one.

Servo Tester Recipe:

  1. Fez MCU (code written for NETMF)
  2. POT or TrimPot
  3. Some jumper wire
  4. Servo to test
  5. Breadboard
  6. 5v-7v battery to power servo.

Hook your pot, servo and wires up as shown.  Pick a free PWM port on your FEZ.  Also pick a free Analog port.  We will use the analog port to read relative pot level.  We will scale the AIn port reading to match the Ms (microsecond) range we want to see for the 0-180 deg range of the servo.  Now just add the following code:

public static void ServoTester()
{
    // Config pin and scale for reading POT voltage.
    AnalogIn ai = new AnalogIn(AnalogIn.Pin.Ain5);
    FEZ_Components.Button but = new FEZ_Components.Button(FEZ_Pin.Digital.LDR);

    // Initially, set your scale a bit beyond servo limits.
    // Kick range numbers down till buzzing stops at each end.
    uint FREQ = 20 * 1000 * 1000; // 20ms Freq.
    int lower = 690 * 1000;
    int upper = 2422 * 1000;
    int neutral = (upper - lower) / 2;
    Debug.Print("Lower: " + lower + " Upper: " + upper + " Neutral: " + neutral);
    ai.SetLinearScale(lower, upper);

    // Set servo line pwm.
    PWM servo = new PWM(PWM.Pin.PWM5);

    uint min = uint.MaxValue;
    uint max = 0;
    while (but.GetState() != FEZ_Components.Button.ButtonState.Pressed)
    {
        // Read pot and set servo.
        uint newPos = (uint)ai.Read();
        if (newPos < min)
        {
            min = newPos;
            Debug.Print("Min: " + min + " Max: " + max);
        }
        if (newPos > max)
        {
            max = newPos;
            Debug.Print("Min: " + min + " Max: " + max);
        }
        servo.SetPulse(FREQ, newPos);
    }
}

Turn everything on.  As you turn the POT back and forth, the value will be converted to a scaled High-Time that we use for SetPulse().  The servo should turn CCW or CW to the value.  Set your linear scale to be a bit outside the edges of your servo’s limits at first.  Get limits from its’ datasheet.  Many common servos are in 1-2ms range with neutral at 1.5ms.  However, I am testing a Medium sized servo from SparkFun.  It is a DGServo from China, so it seems to have different limits.  However, using this simple test rig, I found the limits are around .69-2.43ms.  You know you hit the servos’ edge when it starts buzzing.  It should be able to hold max positions without buzzing.  After you find the values, you may want to back them off a little more to add a small margin.  Going past the limits will drain more current and heat up servo needlessly.

That’s it.  Hope that may be useful.

This entry was posted in .Net Micro Framework, C#, FEZ, Motors, Servo and tagged , , , . Bookmark the permalink.

4 Responses to Roll Your Own Servo Tester

  1. staceyw1 says:

    I think mine was below.
    servo.LowRange = 690;
    servo.HighRange = 2400;

    However, yours can still be different. Hense the need to test drive them to ful left and right range to find the exact spots.

    • gdesmitarch says:

      You have been very helpful. With your starting values I was able to use trial and error to find the range that I needed to control my device.

      I’m an Graduate student working on my Masters in Architecture at Ball State University in Muncie, IN, and was wondering if you might be willing to help or point us in the direction of a good resource to help us out. Unfortunately our group is a little over our heads with this current project.

      We are using a servo, connected to a photoresistor to control a movable sun shade device. We have written the basic code using Basic Micro Studio but are having trouble taking the next step. We need to code in an array so that it compares new values to the old ones and only updates the servo’s position if the averaged change over a 10-15sec period is > 10% give or take. We have no idea what we are doing and have gotten no help from the comp. science dept at this University!! Have you used Basic Micro Studio or know how to code what we are describing? Thanks in advance!!!

      Geoff

      • staceyw1 says:

        I use FEZ MCU boards. http://tinyclr.com
        They use .Net and C# which makes this kind of stuff super easy. If you used c# I could help (along with many others folks over there) on the forum. It would probably be just reading (in a loop) the scaled volt values on an analog pin and doing the right thing in code . Sounds like a fun project.

  2. gdesmitarch says:

    Stacy,

    I’m been working with a different servo for some time and we had a datasheet that had the min and max con range listed. We just bought the same servo from sparkfun that you are testing and alas, no datasheet. I dont have the setup that you have as we are just getting into basic things. Have you found the min and max range values for that particular servo?

    Thanks!

Comments are closed.