Question about using raspberry pi to drive two servos, laser


9 posts
by wolftiger » Thu Jun 13, 2013 9:55 am
I'm building a laser toy for the cat using two servos and a laser pointer. This video actually shows a similar project, but this guy is driving the control of his with a watch: http://www.youtube.com/watch?v=zxGUVHHPsik.

Anyways, this tutorial on a facetracking webcam will help me set up the servos: http://mitchtech.net/raspberry-pi-servo-face-tracker/

But my question is how to connect the laser pointer to the raspberry pi. Do I just plug it straight into the gpio? What pins?

I'm planning on using servoblaster (viewtopic.php?f=37&t=15011) to control the servos and would like the ability to turn the laser on and off through the pi. This is the laser I purchased: http://www.adafruit.com/product/1054.

I'm a bit of a newb on robotics. I'm afraid to fry the laser or the pi just by plugging things in. Any help you can offer would be appreciated.

Thanks!
Posts: 2
Joined: Thu Jun 13, 2013 9:26 am
by MangoKid » Thu Jun 13, 2013 1:36 pm
I hate to say it but its never that easy. You cant plug the laser into the GPIO for many reasons, the most important being that the voltage levels are probably different.

Your best bet would be to use a basic relay module. Something like this

http://compare.ebay.com/like/160831617523?var=lv&ltyp=AllFixedPriceItemTypes&var=sbar

A relay is a switch that is powered by a lower voltage/lower current source, in this case the Pi. When the pi GPIO turns on or off the relay will do the same. Wire the ground of the battery/power supply to the laser. The take the power (probably the red wire) and wire both (laser and power supply) into either side of the relay.

This way your Pi is safe! :)
Posts: 47
Joined: Tue Apr 02, 2013 12:24 pm
by toxibunny » Thu Jun 13, 2013 2:00 pm
Yep, relay would be easiest.
note: I may or may not know what I'm talking about...
Posts: 1142
Joined: Thu Aug 18, 2011 9:21 pm
by joan » Thu Jun 13, 2013 2:13 pm
You can only power a small hobby servo through the Pi (circa 150 mA).

You can control as many as you want (21 directly with the rev. 2 Pi).

http://www.youtube.com/watch?v=Jse3cziVyeg
User avatar
Posts: 5987
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by joan » Thu Jun 13, 2013 2:19 pm
There is a laser pointer in this video.

https://www.youtube.com/watch?v=2vq0Q4dD6KE
Last edited by joan on Fri Dec 20, 2013 9:28 am, edited 1 time in total.
User avatar
Posts: 5987
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by PiGraham » Thu Jun 13, 2013 2:46 pm
According to the specifications for your laser module:
2.8 - 5.2V DC voltage input
25mA max current draw

You can run it from 3.3V, but any one GPIO pin can supply a max of 16mA (see here), so you could not drive the laser at full power from a GPIO. If your servo control outputs don't draw too much power you could drive the laser at reduced power (use an appropriate series resistor to limit the current to < 16mA).

It is best to drive the laser with a transistor. No need for a relay, which will take at least as much power to energise the coil as you need for the laser. Something like these will do for this and many other power switching tasks. You could also use a MOSFET.

For the NPN darlington connect the base to the GPIO output through a resistor (100R to 10K will do), connect the cathode (-ve) of the laser to the collector and the emitter to 0V. Connect the anode (+ve) of the laser to 3.3V or 5V supply via a resistor. When the GPIO is high the transistor will turn on and allow current to flow through the laser.

It isn't clear on Adafruit is the module has inbuilt current limiter. They say "It's a diode with integrated driver". You may not need a series resistor if your power circuit can supply 25mA, but go carefully or you may blow the diode.

Check if the module has a current limiter in it.

You could cheat and use two GPIO outputs commoned via two diodes. DO NOT connect GPIO pins together directly.
Posts: 1039
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville
by mikerr » Thu Jun 13, 2013 3:09 pm
joan wrote:You can only power a small hobby servo through the Pi (circa 150 mA).

You can control as many as you want (21 directly with the rev. 2 Pi)


21 ? I thought servoblaster was only 8 ?
Is 21 with your pigpio lib ?

My biped is using up all eight and needs more....
Got a Pi Camera? View it in my android app - Raspicam Remote ! No software required on the pi
User avatar
Posts: 1257
Joined: Thu Jan 12, 2012 12:46 pm
Location: NorthWest, UK
by MangoKid » Thu Jun 13, 2013 3:18 pm
Are you wiring multiple servos on 1 channel? i know some people have done this for hexa pods, because some legs make the same motions.

I dont think it works for quadrapeds though...
Posts: 47
Joined: Tue Apr 02, 2013 12:24 pm
by wolftiger » Thu Jun 13, 2013 5:03 pm
Wow. Thank you all for the help!
Posts: 2
Joined: Thu Jun 13, 2013 9:26 am