Control servo motor from Raspberry Pi



Today I managed to use a little sevo with my Raspberry Pi (RPi).

There are different ways to do this but, in my opinion, python is too slow and you will need a fast pwm in order to properly drive the servos. I found this project which is written in C and looks fast enough. Let’s see how to use it.

Get a shell on your RPi and type:

tar -xvf pigpio.tar
cd pigpio
cp libpigpio.a-hard libpigpio.a
sudo make install
sudo pigpiod

I wrote a script in python to use the c library:

from subprocess import call

for pos in range(530,2300):
	call(["pigs","S","18",pos ]) #S is for servo, 18 is the gpio and pos is the position
	print "position:"+str(pos)

Happy moving!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s