AforAlex
Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Would like to control some motors, but where to start? Help

Thu May 31, 2012 8:36 pm

Hi, not 100% sure if this is the correct place to post, so please let me know if would be better posting else where.

I would like to connect my Pi up to a remote control car, either by driving the servo's directly, or by connecting it up and controlling the radio signal, but I am absolutely clueless where to start but very keen to learn. I was wondering whether someone is able and willing to point me in the direction to start? A good book, or a website of where someone has done something similar that I can use as a template/example/to instruct me.

My background is software engineering, at Uni I did something similar using pic controllers and a Technic Lego car but that was 10 years ago and I never really got involved in the electronic side of things as I concentrated mostly on the software to control it all. My electronic skills are very basic, done a bit of soldering and that's about it but its something I've always wanted to get into and try and understand.

Many thanks

Alex

User avatar
mkopack
Posts: 242
Joined: Mon Nov 07, 2011 8:46 pm

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 1:03 am

ok, driving the motors directly from the Pi without any additional components isn't going to happen - the pi can't put out anywhere near enough power on the pins to directly power a motor. You'll need to read up on motor controllers for doing that, and just use the Pi to send control signals to the motor controller chip to tell it how fast to go and what direction.

Servos work a bit differently... And those MIGHT be doable (I haven't messed with them in a while and don't remember off the top of my head.

Look at some of the Arduino stuff out there about motors and servos. Most of it will apply to the Pi's GPIO pins as well, but I believe you'll need them to work as Pulse Width Modulation (PWM) output to do what you want.

Hope this helps!

catmaker
Posts: 50
Joined: Thu May 24, 2012 8:32 am

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 4:43 am

I would like to connect my Pi up to a remote control car, either by driving the servo's directly, or by connecting it up and controlling the radio signal
Hi,
It'd be nice if you could take a picture of the internals of your intended RC car and attach it, so us forum browsers can have a feel of the current electronics/mechanicals within. There are many classes of RC models, and some types may/may not be suitable for easy modding.

AforAlex
Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 1:00 pm

Hi, thanks for both of your responses, I shall definitely be investigating and reading up about the Arduino stuff.

Regarding the car hardware, this has not yet been decided on, I was thinking of a standard kit RC car available from any normal model shop. The only thing that i would be looking for would be something with some decent gearing, basically so that it can be geared to go slowly .... not quite sure I need anything to go 40mph around my living room :-)

In my stumbling around the forums and internet I've found what looks to be a brilliant article for an absolute electronics beginner like myself in Issue 2 of the MagPi (Raspberry Pi Magazine) - HERE : http://www.themagpi.com/ . It looks like it gives a brilliant introduction to how to get a bit of IO going with the Pi so going to start with that and then build up to controlling a motor.

I won't be stopping till I've finished, so if anyone else has any great advice then it would always be appreciated.

funnel
Posts: 48
Joined: Sat May 05, 2012 8:00 am

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 2:17 pm

My suggestion would be to use a standard hobby servo and modify it to rotate 360 degrees, then use arduino to generate the servo PWM signals to drive the motor. You would need another unmodified servo for steering.
RaspberryPi would be useful to connect it to the programmed arduino with serial communication to drive the car through WIFI. I personally would attach a webcam on it to drive it in first person view to have more fun.

mr.molez
Posts: 3
Joined: Tue Apr 10, 2012 12:17 pm

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 2:22 pm

This is a very good question

It would be nice if any electronics guys could post some schematics/ pictures of controlling servos/motors/switches and higher amp/load devices from the pi.

I personally only bought the pi for the GPIO's... it's worthless to me if i can't control servos and motors and use it as a switch..


AforAlex
Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 4:08 pm

The gert board certainly looks like it could offer a solution doesn't it ... has it got a release date? The best I could find was an outline of a release plan which would involve having it available as a pre printed board, list of components to buy and instruction manual ... has anyone heard of a release date?

domesday
Posts: 258
Joined: Fri Oct 21, 2011 5:53 pm
Location: UK

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 4:53 pm

The Gertboard is just a collection of useful components put together on a single board, the part doing the motor control is a L6203 DMOS Full Bridge Driver. You don't really need any of the other parts of the Gertboard if all you want to do is control a motor with PWM, just a L6203.

User avatar
mkopack
Posts: 242
Joined: Mon Nov 07, 2011 8:46 pm

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 5:03 pm

If you're getting excited about the Gertboard, but have a problem with just using the GPIO to control a motor driver, I have news for you, that's EXACTLY what the Gertboard has on it! It contains a motor controller chip and you hook one of the GPIO pins on the Pi to the motor controller on the Gertboard so it can control the motor you attach to it.

YOu have to understand, the GPIO pins on the Pi only put out something like 50ma. That's NOT much power to drive motors. You need to instead use something like a motor driver chip - which takes high input power, and based on the signals it gets from the GPIO pins on the PI, controls the power going to the motor, both in direction and speed. The motor driver is designed specifically for this purpose and can handle the high amp loads needed for motors.

And this is EXACTLY how it's done on Arduino as well so don't think you are getting screwed or anything like that.

Servos work a little bit differently than straight motors. You use the GPIO pin connected to one of the lines on the servo to send a pulse of a certain duration which makes the servo go to a specific position. With the Arduinos, you have dedicated pins that are PWM pins, and so you just send a command with a 0-255 value on that pin and it uses that 0-255 value to figure out how long of a pulse to fire onto the servo which the servo interprets as a position to turn to.

As long as you can configure the GPIO on the Pi to produce PWM then you should be ok for Servos (as long as they are relatively low power load servos, otherwise you might need to power them off a different power supply than the Pi's 5V GPIO pin..)

Make sense?

Like I said, dig around through the various Arduino resources. There's a LOT of good beginner info in there, and much of it will be the same on the Pi, with the exception of analog input (Pi doesn't have that), and the programming is a bit different. But the circuitry used to hook things up should generally be the same.

User avatar
mkopack
Posts: 242
Joined: Mon Nov 07, 2011 8:46 pm

Re: Would like to control some motors, but where to start? H

Fri Jun 01, 2012 5:06 pm

domesday wrote:The Gertboard is just a collection of useful components put together on a single board, the part doing the motor control is a L6203 DMOS Full Bridge Driver. You don't really need any of the other parts of the Gertboard if all you want to do is control a motor with PWM, just a L6203.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What he said....

Spend a little time learning about some basic circuitry first so you'll better understand what's possible and what's needed before you start making plans!

User avatar
Grumpy Mike
Posts: 931
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: Would like to control some motors, but where to start? H

Sun Jun 03, 2012 6:52 pm

mkopack wrote:IYOu have to understand, the GPIO pins on the Pi only put out something like 50ma. That's NOT much power to drive motors.
Well it is closer to 15mA actually and at 3V3 at that.

The Pi is definitely not the right platform to use to control a RC car. It is way too slow and the basic unit takes about 30 seconds to boot up and draws between 500 - 700mA from the motor's supply plus any current needed for the motors.
When I say it is too slow I mean that the Linux operating system gets in the way of always being able to read a sensor or change a control when you want it to. You get blanked off for random periods of time, up to 10mS from my measurements. OK that might not be a problem for you but the other stuff is.

Compare that to the arduino's 2 second start up, 40mA current draw, and instant response to commands.

catmaker
Posts: 50
Joined: Thu May 24, 2012 8:32 am

Re: Would like to control some motors, but where to start? H

Mon Jun 04, 2012 1:56 am

Grumpy Mike wrote:When I say it is too slow I mean that the Linux operating system gets in the way of always being able to read a sensor or change a control when you want it to. You get blanked off for random periods of time, up to 10mS from my measurements. OK that might not be a problem for you but the other stuff is.
I think most robots people would agree: use an Arduino or a low-level microcontroller plus suitable power-electronics to drive your motors/servos, and acquire inputs like bump sensors, etc. for the low-latency jobs. But you can use your Pi for higher-order 'thinking' functions like mapping, navigation, telepresence, and (more ambitiously) vision, speech and intelligence.

I guess some rough steps to take are:
a. take pictures or make diagrams of your intended locomotion platform.
b. choose suitable microcontroller-based motor electronics with easy connectivity to your Pi, or desktop PC, to drive motors/servos. Some criteria here: number & type of motors/servos, number & type of sensors, physical size of this add-on, ease-of-connectivity to your Pi/desktop, power type & consumption, etc.
c. Make car. (For me, this is the hard part oops: )
d. Spin wheels through programming...

jdj
Posts: 7
Joined: Mon Dec 26, 2011 3:15 pm

Re: Would like to control some motors, but where to start? H

Wed Jun 06, 2012 10:43 am

Hi

Just my $0.02; I have a similar project in mind - and similar experience

I bought a "Graupner Punisher Rock crawler" for this purpose;
1 - It was on sale :)
2 - It has electronic motor control; the whole car is controlled by servo signals only - no mechanical throttle parts.
3 - When I take off the (silly) "chassi-cover", it has a good aluminium frame where I can attach a platform for all of the electronics. I thought I'll go for a large plywood or thick plastic sheet that I attach to the chassi-pins.
4 - Since I'll make a detachable platform for all the electronics, I can easily convert it back to a car and play with it :) I don't need to do anything to the base car (just unplug the receiver's servo cables and plug in my own).

There are tons of servo controllers out there, I just need to figure out which ones I can get hold of. Then I thought I'd add some Sharp IR distance sensors, an accelerometer, an multi input ADC etc. etc. I probably need to add another battery too... :)

I just got my Pi yesterday :D , so the project has gained a little more momentum now!

Cheers!
/ Daniel

P.S I can recommend the book "Robot Builder's Bonanza" - got tons of useful info.

User avatar
mkopack
Posts: 242
Joined: Mon Nov 07, 2011 8:46 pm

Re: Would like to control some motors, but where to start? H

Wed Jun 06, 2012 1:29 pm

Yes, agreed, very good book. One of the guys in the local robotics club brought a copy of that in to one of the meetings and I flipped through it. Lots of great info in there. I need to get a copy for myself, I just don't know when the heck I'd have time to read it!

(grumbles about stupid grad school on top of work on top of home responsibilities...)

AforAlex
Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Re: Would like to control some motors, but where to start? H

Sat Jun 09, 2012 6:00 pm

Hi, so over the past week I have been tinkering about with the GPIO stuff, I haven't quite got to controlling motors, am still playing around with LED's for now, but I have attached to a webcam and have a control on a php page to switch it on and off, very early proof of concept stuff, but thought I would post what I've done in case its of use to anyone else out there

http://thingswatihavedonewithmyraspberr ... pot.co.uk/

My next step is still looking at connecting up and driving motors from the Raspberry Pi, I agree there might be more technically suitable products out there to drive motors, but me and the Pi are becoming good friends and i would like to find out what its limits are before ditch it in favour of something else.

Thanks guys, keep the help and comments comming

Michael Meissner
Posts: 48
Joined: Tue Jan 17, 2012 1:42 pm
Contact: Website

Possibly use Pololu USB servo control

Wed Jun 13, 2012 1:10 pm

I've been experimenting with Arduino for a little while now, and while I recently got the email to order the Raspberry PI, I haven't actually gotten mine yet. However, I thought I would start reading the R-PI groups.

I was browsing over at pololu.com to get some connectors, and I noticed they have a servo controller that works on USB. Here is the url: http://www.pololu.com/catalog/category/12.

You could use one of these to control up to 24 servos from a single USB or serial connection. With the 18 and 24 servo controllers, you can also read the digital inputs via USB, so if you are thinking you need a lot more inputs than the R-PI gpio pins, this would be a way to do it.

I haven't yet ordered anything from Pololu yet, but I thought I might pass it along. 8-)

User avatar
Clanzer
Posts: 27
Joined: Wed Jun 13, 2012 1:42 pm
Location: UK
Contact: Website

Re: Would like to control some motors, but where to start? H

Wed Jun 13, 2012 1:59 pm

The Raspberry pi I/O lines are just like any other circuits I/O lines.
People have been interfacing with embedded controllers for years such as the Microchip Pic Chips and Atmel processors, including the Arduino board. There is a mass of information and example isolation circuits out there, that are all very simple to implement.

I think using some Opto-Isolators will be the bext route for outputs so you isolate your external circuit from the Raspberry pi and then simple mosfets or SSR's (Solid State Relay) off the back of these for switching your heavy loads such as motors etc.

There are some sweet SSR's around now that already have the Opto-Isolators built in and very simply to wire in.

I think we are going to see some exciting projects come out of this and a lot of fun !

Cheers

Sean.
******************************
http://www.pthat.com
******************************

AforAlex
Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Re: Would like to control some motors, but where to start? H

Wed Jun 13, 2012 5:46 pm

Cheers guys, everyone's comments and thoughts have been really helpful. My biggest problem as i think i have already stated is that I don't know what i don't know, and the thing that I don't know is electronics.

Clanzer, you said
There is a mass of information and example isolation circuits out there, that are all very simple to implement.
Would it be extremely cheeky of my to ask if you know of any good examples that I could follow as a tutorial and ultimately would lead to me being able to control a motor. Could you post the URLs?

I have been looking through other forums, and other website, and there seems to be an incredibly steep learning curve out there ... if anyone is able to point me at a web page (or a few) and tell me to read then I will, at the moment I am finding myself reading stuff with no clue as to whether its useful or usable, more often or not I find that I am not reading at the right level.

Once again many thanks

User avatar
Clanzer
Posts: 27
Joined: Wed Jun 13, 2012 1:42 pm
Location: UK
Contact: Website

Re: Would like to control some motors, but where to start? H

Wed Jun 13, 2012 6:51 pm

Hi Alex

I think the first thing you need to decide is if you are planning to make a motor driver yourself from the ground upwards or if you are going to use a 3rd party interface.

I take it you are wanting to control a DC motor or a Servo from your first post, rather than a stepper motor.

So the first decision you have to make, is do I use a 3rd party interface for the Servo/DC motor control or do I do the bit banging myself.
This decision will make a huge difference to the interface/electronics and also set the standard for your learning curve.

If you use a 3rd party interface then you will find that the control of the motor or servo is taken care of for you and you simply need to either send serial commands out of the Raspberry Pi or bit/byte commands and the third party interface will do the rest.
With most of these interfaces you simply have to connect a common Gnd between the Raspberry Pi interface and a couple of I/O pins to send serial data back and forth to the controller. All the timing and switching routines are taken care by the 3rd party interface, as well as the Mosfets to switch the current your motors/Servos need. Along with sensible isolation also.
This is the easy route and the least work involved.

Now if you do do not want to go for the 3rd party interface and want to control the motor or servo yourself, you first have to read up on the data sheet for the servo/motor you want to control.
Next you have to spec up your switching control, for example we could create a H-Bridge circuit using 4 mosfets for a DC motor which would allow us to run it in forward/reverse mode. We would then work out a PWM (Pulse Width Modulation) routine where we send pulses out on the Raspberry Pi I/O lines to control the motor and also we would have to use some of the I/O on the Raspberry Pi for inputs from say a positioning encoder attached to the motor.

So first thing is first, do you plan on using a 3rd party interface attached to the Raspberry Pi or want to send raw bit/bang information out to control the motor switching/pulse circuit yourself ?

Cheers

Sean.
******************************
http://www.pthat.com
******************************

AforAlex
Posts: 85
Joined: Thu May 31, 2012 7:56 pm

Re: Would like to control some motors, but where to start? H

Fri Oct 26, 2012 12:36 am

After many months I've finally managed to do the simple task of using the Raspberry Pi to control a couple of motors. Just to finish off this now rather old forum post I made many months ago and help anyone else who is stuck, I've written a blog article about my solution: http://thingswatihavedonewithmyraspberr ... th-my.html


Return to “Automation, sensing and robotics”