Control servo motor from Raspberry Pi

Standard

IMG_20131009_110313

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:

wget http://abyz.co.uk/rpi/pigpio/pigpio.tar
tar -xvf pigpio.tar
cd pigpio
cp libpigpio.a-hard libpigpio.a
make
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!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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