Servo Calibrator GUI

Introduction: Servo Calibrator GUI

For my projects I use several standard servos which are controlled by the ADAFRUIT PWM SERVO DRIVER which in turn is controlled by a python script running on Raspberry Pi.

Each time I re/assemble a horn on a servo I need to re-adjust the 'zero angle'. If I replace a servo, it may have different conversion of PWM to angle position. It took so much of my time to adjust those parameters with each change I decided to write simple Tkinter GUI which would allow to set, verify, and save:

* PWM value for the 'zero angle' (pwm0)

* conversion of rotation angle in degree to PWM change (factor)

* upper/lower limits on the angle to protect hardware from damage (pwmHigh, pwmLow)

* channel ID 0-15 of PWM generator to which servo is connected

The formula converting the set angle (A) to PWM value issued to servo is as follows:

pwm= A * factor + pwm0
if pwm < pwmLow :
elif pwm > pwmHigh:

The movie shows how one can use this GUI to experimentally determine : pwm0, factor, pwmLow, pwmHigh. In this movie I wanted the black arrow to point at the red '0' when I set the angle A at 0 deg on the scale and the arrow should never exceed the angular range marked by black 'X' and 'Y'. After servo named 'futuba-S3003' is calibrated the parameters are saved in a python pickle.

Then, one can use those settings as shown in this short program:

armConfName ="./servo.futuba-S3003.conf
armConf=pickle.load( open(armConfName, "r" ) ) print 'loaded arm conf ',armConfName arm = ServoDriver() arm.setupController(armConf['freq']) arm.config(armConf) for ang in [10., 20., -20, -10.]: arm.setAngleDeg(ang) print 'set armAngDeg=%s, status=%s '%(ang,arm.status) time.sleep(2.) print "servos STOP & RELAX" arm.fullStop()

This code is accessible from bitbucket GIT repo as:

git clone

It is expected you have already installed on your R-Pi (and tested) the Adafruit library , as described here

With all code is in place just launch servo calibrator as 'gksu' (otherwise graphics may not tunnel). Also make sure your servo is plugged in to the PWM channel displayed on the GUI

$ gksu ./

After you have saved calibration in to pickle, use it to move the servo with just few lines of python

$ sudo ./

Good luck


Be the First to Share


    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Cold Challenge

      Cold Challenge
    • Baking Contest

      Baking Contest