Whillikers
Posts: 4
Joined: Sat Jan 10, 2015 8:40 pm

Controlling both Motors and Servos

Sat Jan 10, 2015 8:53 pm

Sorry for posting what's probably an extremely simple question, but, though I have some robotics experience, this is my first time using the Pi.

I've got a project that requires controlling two DC motors and one servo. I plan to use http://store.ryanteck.uk/collections/fr ... =741358763 for my motor controller, but I've read that only GPIO pin 18 can send the PWM signals required to control servos, and the controller takes up pins 1-26. However, it looks like the controller has its own GPIO pins that might act like extensions of the pins it takes up, allowing me to control a servo from the extended pin 18, or even attach another board that's a dedicated servo controller. Is this the case?

My backup plan is http://www.mikronauts.com/raspberry-pi/robopi/, which looks like it has both motor and servo controllers. However, at $50 for the board + ICs, it's quite a bit more expensive.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 12:37 am

Whillikers wrote:Sorry for posting what's probably an extremely simple question, but, though I have some robotics experience, this is my first time using the Pi.

I've got a project that requires controlling two DC motors and one servo. I plan to use http://store.ryanteck.uk/collections/fr ... =741358763 for my motor controller, but I've read that only GPIO pin 18 can send the PWM signals required to control servos, and the controller takes up pins 1-26. However, it looks like the controller has its own GPIO pins that might act like extensions of the pins it takes up, allowing me to control a servo from the extended pin 18, or even attach another board that's a dedicated servo controller. Is this the case?

My backup plan is http://www.mikronauts.com/raspberry-pi/robopi/, which looks like it has both motor and servo controllers. However, at $50 for the board + ICs, it's quite a bit more expensive.
You might be able to use Pi-Blaster, which uses some software trickery to get PWM on normal GPIO pins without using much CPU.

Whillikers
Posts: 4
Joined: Sat Jan 10, 2015 8:40 pm

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 1:00 am

Pi-blaster seems great. Thanks!

Does that mean that the pins on the motor controller do not extend the GPIO, though? At this point it's pretty irrelevant to the project since Pi-blaster should fix my issues, but it'd be good to know for future stuff.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 1:03 am

There's also servoblaster and pigpio. All will do servo PWM in software on any pin (and several pins at the same time).

Although you state you will use two dc motors and one servo, have you considered using modified continuous-rotation servos instead of the two dc motors? It really depends on exactly what you are using them for I suppose, but the advantage is that the control interface for continuous-rotation servos is the same as for a regular servo, plus you don't need a driver board.

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 1:08 am

Whillikers wrote:Pi-blaster seems great. Thanks!

Does that mean that the pins on the motor controller do not extend the GPIO, though? At this point it's pretty irrelevant to the project since Pi-blaster should fix my issues, but it'd be good to know for future stuff.
As far as I can tell, the Ryantek board uses GPIO pins 17, 18, 22, and 23, but passes the rest through to the header.

Whillikers
Posts: 4
Joined: Sat Jan 10, 2015 8:40 pm

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 1:34 am

Would continuous-rotation servos work as well as DC motors for a drive? It's a fairly simple one, so I guess I could see that working. I'm currently thinking of http://www.ebay.co.uk/itm/360-TowerPro- ... 2c94252730 , but I've never used continuous-rotation servos before and I'm not sure what kind of performance I need to have on them for a drive.

Also, I could go the other way completely and get a 4-motor board and use a stepper motor in place of the servo, right?

User avatar
joan
Posts: 14990
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 9:24 am

I'd stick to DC motors for continuous rotation. Geared ones preferably (something less than 200 RPM is probably sensible). Whether steppers or servos serve a purpose would depend on what you are trying to do.

How powerful do your motors need to be? You can pick up motor driver boards such as the L9110S based ones for a few pounds, e.g. http://www.ebay.co.uk/itm/261648975778, a L298N based board would be better for more powerful motors, e.g. http://www.ebay.co.uk/itm//291272112778

As already said the Pi can provide PWM on all gpios on the expansion header (suitable for servos and DC motors).

Not the sort of motor you want but PWM for an L298N board controlling a DC motor. http://www.raspberrypi.org/forums/viewt ... wm#p632413

PiGraham
Posts: 4019
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 10:06 am

I think most, if not all, common Pi GPIO libraries support servo/PWM on any output.
There are options for command line / bash script, c code, python and probably others.

RPI.GPIO
WiringPi
PIGPIO
Servoblaster
PiBlaster

It seems there are most examples in Python using RPI.GPIO, and it's in Raspbian already so that might the best place to start.
I have used PIGPIO library from c and it works very well.

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 11:09 am

RPi.GPIO is software PWM so may not be fit for purpose depending on the resolution / accuracy you need.
Hardware PWM is available from RPIO http://pythonhosted.org/RPIO/ but you have to install it manually - it's not included in the standard distribution
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

User avatar
joan
Posts: 14990
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 11:17 am

Hove wrote:RPi.GPIO is software PWM so may not be fit for purpose depending on the resolution / accuracy you need.
Hardware PWM is available from RPIO http://pythonhosted.org/RPIO/ but you have to install it manually - it's not included in the standard distribution
In addition to RPIO.GPIO hardware timed PWM is also available from piblaster, pigpio, and servoblaster.

Whillikers
Posts: 4
Joined: Sat Jan 10, 2015 8:40 pm

Re: Controlling both Motors and Servos

Sun Jan 11, 2015 7:59 pm

Right now I'm looking at a L9233D H-Bridge (http://www.adafruit.com/product/807) to drive the two motors and Pi-Blaster to control the servo straight from the breadboard.

Return to “General discussion”