Page 1 of 1
PIGPIO multiple servos
Posted: Tue May 10, 2016 12:32 pm
by vwok
Hi there
I'm using the PIGPIO library to control my servos. It's working great for controlling one servo, but when I'm using multiple, they're acting crazy. They move by themselves to random positions continuously and they react verrrryy slowly and badly to my pulse signals.
Code: Select all
...
GPIO.setmode(GPIO.BCM)
pinLeft= 6
pinMiddle=5
pinRight = 4
pinServos = [pinRight, pinMiddle, pinLeft]
pi = pigpio.pi()
for x in pinServos:
pi.set_mode(x, pigpio.OUTPUT)
pi.set_PWM_frequency(x, 33)
pi.set_servo_pulsewidth(x, 0)
pi.set_servo_pulsewidth(pinPoortL, 1000)
pi.set_servo_pulsewidth(pinPoortR, 1000)
pi.set_servo_pulsewidth(pinPoortM, 1000)
Re: PIGPIO multiple servos
Posted: Tue May 10, 2016 1:31 pm
by PiGraham
It should work OK. I've use pigpio to control several servos at once, although not recently.
Check your power supply to the servos. Try the same program running with just one servo connected. Does it behave correctly? If it does you probably have a hardware problem. If it doesn't it may be a software issue.
Re: PIGPIO multiple servos
Posted: Tue May 10, 2016 1:41 pm
by joan
Could you post the full code?
By the way
pi.set_servo_pulsewidth(x, 0)
does the same as
pi.set_mode(x, pigpio.OUTPUT)
pi.set_PWM_frequency(x, 33)
pi.set_servo_pulsewidth(x, 0)
Servo mode forces output mode and servo mode forces a PWM frequency of 50 Hz.
Re: PIGPIO multiple servos
Posted: Tue May 10, 2016 1:50 pm
by darkbibble
I would check your power line to your servo's, in r/c applications (cars/planes/helicopters) servos are usually allowed 3A on the power line with a max draw of 5a if stalled.
Re: PIGPIO multiple servos
Posted: Tue May 10, 2016 3:52 pm
by timrowledge
To reiterate darkbibble's point - I hope you have separate power for the servos. Connect the gnd from the Pi to the gnd of the servo power and only connect the servo 5v to the other psu. Trying to actually power servos from the Pi can cause release of the magic smoke.
Re: PIGPIO multiple servos
Posted: Wed May 11, 2016 6:14 am
by vwok
Ok here are some pictures of my project. I'm trying to control the doors of a fisher-price house with my cellphone.

- IMG_20160511_075854.jpg (47.26 KiB) Viewed 3139 times

- IMG_20160511_080004.jpg (39.08 KiB) Viewed 3139 times
Full code:
Code: Select all
def main():
#SETUP GPIO PARAMETERS
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#12 and 16 are used for LED's
pinGroen = 12
pinRood = 16
pinPoortR = 6
pinPoortM = 5
pinPoortL = 4
pinServos = [pinPoortR, pinPoortM, pinPoortL]
GPIO.setup([pinGroen,pinRood], GPIO.OUT, initial = GPIO.LOW)
#SETUP PIGPIO
pi = pigpio.pi() #Special PWM module
for x in pinServos:
pi.set_mode(x, pigpio.OUTPUT)
pi.set_PWM_frequency(x, 33)
pi.set_servo_pulsewidth(x, 0)
poortLinksToe = 2000
poortLinksOpen = 1000
poortRechtsToe = 500
poortRechtsOpen = 1500
def servoControle():
#get checkbox values from HTML form
servoLinks = request.forms.get('poortLinks')
servoRechts = request.forms.get('poortenRechts')
#Gate left open or close
valueLinks = poortLinksOpen if servoLinks else poortLinksToe
pi.set_servo_pulsewidth(pinPoortL, valueLinks)
#Gates right open or close
valueRechts = poortRechtsOpen if servoRechts else poortRechtsToe
pi.set_servo_pulsewidth(pinPoortR, valueRechts)
pi.set_servo_pulsewidth(pinPoortM, valueRechts)
print(pi.get_servo_pulsewidth(pinPoortR))
#Return HTML template and call Servo function
@route("/")
def toon():
stylesheets('button.css')
lampControle()
servoControle()
#function to return template:
return showTemp()
Re: PIGPIO multiple servos
Posted: Wed May 11, 2016 6:51 am
by Major Tom
Your power supply is only rated at 300mA. It seems a little small for 3 servos. Are you powering the Pi from the same supply?
What you could do is change your code so that there is a delay between moving each servo to a new position. Servos will draw more power when moving, than when they are staying in one position, especially when lightly loaded. So, you could move servo 1 to a new position, wait one second, then move servo 2, and so on. It may help you get round the power limitation of your PSU.
Re: PIGPIO multiple servos
Posted: Wed May 11, 2016 8:21 am
by joan
They look like standard size servos. Each one by itself might draw an amp or so if acting against a force. At the moment it does seem very likely that the glitches are caused by lack of power.
Re: PIGPIO multiple servos
Posted: Wed May 11, 2016 7:50 pm
by vwok
Thanks for the thoughts.
I tried to add a delay of 1 second after each servo movement, but it doens't really help. When I move the left servo, the others are moving as well and vice versa.
I will try to connect a higher Amp supply one of the days.