2

I am looking for some advice on how to properly get my servo working correctly. I have wired it up and it appears to be working correctly. The problem I have is with the signalling causing a twitching. The servo a TowerPro MG995 brushless. I noticed that the GPIO.PWM takes a second argument for frequency and have tried other frequencies and it only gets worse. Any suggestions would be greatly appreciated.

I am using the tutorial found here

from Tkinter import *
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 100)
pwm.start(5)

class App:

    def __init__(self, master):
        frame = Frame(master)
        frame.pack()
        scale = Scale(frame, from_=0, to=180,
              orient=HORIZONTAL, command=self.update)
        scale.grid(row=0)


    def update(self, angle):
        duty = float(angle) / 10.0 + 2.5
        pwm.ChangeDutyCycle(duty)

root = Tk()
root.wm_title('Servo Control')
app = App(root)
root.geometry("200x50+0+0")
root.mainloop()

1 Answer 1

3

Servos require accurate and regular pulses. More accurate than software timing will provide.

If you want your servo to stop twitching you have several choices.

  • use some add-on hardware to generate the pulses
  • find some software which can generate the needed pulses on gpio18
    (which can use special PWM hardware). This will only be good for one servo.
  • use one of the many modules which can provide hardware timed PWM on
    any of the gpios, e.g. my own pigpio which can be used from C, Python, or servoblaster, or pi-blaster, or RPIO.GPIO etc. etc.
1
  • Thanks I found your article earlier and the pigpio. I am learning electronics but having a hell of a lot of fun. I think I am starting to understand how the servo works. Commented Oct 8, 2014 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.