1

I'm pretty new to electronics and wanted to build a camera with pan/tilt setup on my RPi. I would be using brackets like these:

https://www.sparkfun.com/products/10335

And perhaps servos like these:

https://www.pololu.com/product/1040

And the RPi camera. I have a couple of questions.

  1. Will the RPi be able to power both of those servos itself, without a battery or other power source? If it's absolutely impossible, what is the best way to do that? I would like to avoid power sources that can run out, like a battery, and do it as cheaply as possible. (you can assume nothing is connected to the pi except the servos, the camera and an ethernet cable)

  2. Will the RPi be able to control both of those? I've read that it only has one PWM output, but that you can do PWM output on other GPIO pins through software.

  3. Can those particular servos work with that pan/tilt bracket? I'm not even sure what parameters to look at here.

  • 1
    I'm voting to close this question as off-topic because it belongs on the Robotics Stack exchange. It has nothing to do with the Raspbvery Pi – Piotr Kula Aug 27 '15 at 7:58
  • How is it off-topic if it specifically asks questions about the Pi? If this is OT then what isn't? Shouldn't the Pi StackExchange obviously have some overlap with things like robotics, programming, OS administration, etc.? – ralh Aug 27 '15 at 8:09
  • 1
    I'd certainly lean to on topic (not only because it coincides with my interests). It touches on the limited Pi power supply and the ability of the Pi to produce servo suitable PWM. – joan Aug 27 '15 at 8:49
  • Possibly 1 of the issues relates to the Pi, but most do not, and show little evidence of research. It is difficult to see how this question will add value to other users of the site. Joan's answer reflects her knowledge, but this still doesn't make it on topic. – Milliways Aug 27 '15 at 10:01
  • Most resources on the internet talk about connecting servos with batteries and use RPi1. I could only find sites that had one micro servo connected, so I was wondering if two will fit. And that was the main question, and it does relate to the Pi. Though frankly, the discussion is pointless now, since the question was very well answered and I do think it can help some people in the future. – ralh Aug 27 '15 at 10:08
2

The Pi should be able to power a couple of those micro servos. They do not draw a great deal of current. Try to ensure that your power supply can supply at least the maximum 2 amps the Pi will accept through its microUSB polyfuse.

Recent Pis (the ones with the 40 pin expansion header) have 2 hardware PWM channels available (as well as a 2 amp rather than 1 amp polyfuse). Anyhow there are several packages like my pigpio which can generate hardware timed PWM on any GPIO on the expansion header. Hardware timed PWM is suitable for servos, LEDs, motor speed control etc. Software timed PWM is not suitable for servo control (the servos will twitch and wear out at a higher than normal rate) or LEDs (visible flicker and glitches). Software timed PWM is probably fine for DC motor speed control as the motor's inertia will smooth out the glitches.

Those servos should be fine for the pan tilt head. In fact you have to use a miniature servo for the tilt part of the mechanism as nothing else will fit. This rather assumes you are going to have a very light camera mounted on the pan-tilt head.


EDITED TO ADD

I have connected a pan-tilt head to an early Pi and it appears to work okay even with a standard servo for the pan mechanism. In this case it's even more important to have a solid power supply.

Video at http://abyz.me.uk/videos/pan_tilt_2.mp4 (you may need to download to view as not all browsers like my camera phone).

pan tilt head mechanism

Code used

#!/usr/bin/env python

# pan_tilt_2.py
# 2015-08-27
# Public Domain

import time
import sys

import pigpio # http://abyz.me.uk/rpi/pigpio/python.html

if sys.version > '3':
   buffer = memoryview

PAN=7 # Pan servo gpio.
TILT=8 # Tilt servo gpio.

PAN_MIN=1000.0
PAN_MAX=2000.0

TILT_MIN=1500.0
TILT_MAX=2200.0

RUNTIME=60.0

pan_pos=PAN_MIN
tilt_pos=TILT_MIN

pan_inc=20
tilt_inc=10

pi=pigpio.pi() # Connect to local Pi.

start_time = time.time()

while (time.time()-start_time) < RUNTIME:

   pi.set_servo_pulsewidth(PAN, pan_pos)
   pi.set_servo_pulsewidth(TILT, tilt_pos)

   pan_pos += pan_inc
   if pan_pos < PAN_MIN: pan_inc = - pan_inc
   if pan_pos > PAN_MAX: pan_inc = - pan_inc

   tilt_pos += tilt_inc
   if tilt_pos < TILT_MIN: tilt_inc = - tilt_inc
   if tilt_pos > TILT_MAX: tilt_inc = - tilt_inc

   time.sleep(0.05) # Nominal 20 updates per second.

pi.stop() # Disconnect from local Pi.
  • Thanks a lot for help. Do you think the RPi 1 B would also be able to power them? That's what I currently have, though I have been thinking about buying RPi2. – ralh Aug 27 '15 at 8:07
  • @ralh Probably. Give me half an hour and I'll fit a pan-tilt head to an early model and see what happens. – joan Aug 27 '15 at 8:10
  • Wow. Thanks for the ton of work you put into this. It really feels bad that I can only give you one upvote! – ralh Aug 27 '15 at 8:48
  • @ralh It happens to coincide with some of my interests and did not take much time. – joan Aug 27 '15 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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