Skip to content

PoEPi Servo Moving servo motors with only the PoEPi board

julien8 edited this page Feb 18, 2016 · 2 revisions

Controlling Servos from the Raspberry Pi with the PoEPi Board

There are many guides on how to control Servo motors from the Raspberry Pi. Almost all of them will work the the PoEPi board as long as you are using the correct pins. The pin definitions can be found below or in the hardware design files. This board has 4 servo outputs that can be connected to any type of servo that runs of a single cell battery or 5 volts.

To use the PoEPi you will not have to install any additional packages. All of the required Python libraries are included in most Raspberry Pi images (Noobs, Rasbians, etc...). If you want to get the info right from the docs you can go here to start developing.

The following commands can be run straight from the terminal so you can experiment with them real time.

from RPIO import PWM #imports the PWM library, GPIO can also be imported if needed
servo = PWM.Servo() #init the servo object
servo.set_servo(17, 1000) #set the servo at zero degrees

Writing code for the PoEPi board

If we want to make development a bit easier we need to define some functions and pins before hand. These will need to be defined based on the design of the PoEPi board. All of the code below is written in reference to the design of this board. Some considerations and assumptions:

  • Servo pulse is 1000us to 2000us, covering 0 - 180 degrees
  • Servos are connected to pins 1,2,3,4 (see schematic)
  • Separate function used to calculate angle
from RPIO import PWM

#define each pin the servos are attached to
srv0 = 1
srv1 = 3
srv2 = 4
srv3 = 5

servo = PWM.Servo()

# sets the servo by angle
def set_angle(servo_obj, servo_num, angle):
    pulse = round((2000/180) * angle, -1)
    servo_obj.set_servo(servo_num, pulse)

# set the angle of the servo to 78 degrees, or a pulse of 860us
set_angle(servo, srv0, 78)