Raspberry Pi: Servo Motor Control

The servo motor is often used in robotics when precision is needed for the control of angular motion. The servo motor takes only three connections signal, ground, and power. For this application we have ditched the arduino and instead employed a RPi to take care of the GPIO control of the servo motors. Therefore, we must use an alternative to the arduino IDE, in this case python will suffice.

While python can achieve suitable PWM, there is not great reliability in its builtin delay. For this reason we have tied in Servoblaster to take care of the PWM. The servoBlaster program receives the servo signal pin and the desired angle to send the correct pulse duration to the servo motor. Once in postition there is quite a strong amount of holding torque for the motors.

Assemble your servo motors with the RPi as shown below.

While using the power supply is recommended it was not necesary in our case as we were able to tap into the RPi 5V power supply to facilitate the movement of the servos. If using more than one servo follow the ServoBlaster connection chart below.

 

Servo mapping:

0 on P1-7 GPIO-4

1 on P1-11 GPIO-17

2 on P1-12 GPIO-18

3 on P1-13 GPIO-27

4 on P1-15 GPIO-22

5 on P1-16 GPIO-23

6 on P1-18 GPIO-24

7 on P1-22 GPIO-25

 

After making the necessary connections you can use the code linked here. This code will take input from the joystick thumbs and take care of the pan and tilt operations. The pan and tilt send commands to the desired position and alter that causing the ServoBlaster program to shift the angular position of the servos.

 

You will need to install servoBlaster by cloning this repository and running

“sudo make servod”

inside the ServoBlaster/user directory.

Then before beggining the python program run

“sudo ./servod.c”

Now you should be ready to go assuming you have the same joystick as me. If not use the pygame GUI to map the correct input and change the fields in the python program.