PC/CP320 Physical Computing

Raspberry Pi Servo Motors

Overview

Servo motors are common.

Objectives

  1. To introduce control of servo motors with the Raspberry Pi

Background

The Raspberry Pi has a PWM output built-in which can help with servo motor control.

Preparation

Introduction to Servos

Equipment

Procedure

  1. Datasheet Examination

    Look at the datasheet to determine the required supply voltage.
    Note: The Pi power pin may not provide enough power for the motor. If that is the case then use the bench supply, but make sure your bench ground and the Pi ground are connected.
    Will an optoisolator be required to control this from the Pi?

  2. Identify which wire has which function:
    • power
    • ground
    • control signal


  3. To drive the motors, a pulse width modulated signal must be sent periodically. The width of the pulse will indicate direction and speed:

    • pulse width of 0, i.e. no pulse -- the motor will stop
    • pulse width < some value -- the motor will rotate in one direction
    • pulse width = some value -- the motor is in the neutral position
    • pulse width > some value -- the motor will rotate in the other direction
    • the drive signal is proportional, so the farther it is from the neutral position, the greater the rotation
    • NOTE: specified neutral is approximate, you must calibrate to get precise control
    From the data sheet, what is the required period for the pulses?
    What frequency does that correspond to for your PWM signal?

    From the data sheet, what is the approximate pulse width for the neutral position?
    What duty cycle does that correspond to for your PWM signal?

    From the data sheet, what is the approximate pulse width for the limit in one direction?
    What duty cycle does that correspond to for your PWM signal?

    From the data sheet, what is the approximate pulse width for the limit in the other direction?
    What duty cycle does that correspond to for your PWM signal?

  4. Motor Calibration

    Write a program to control the servo using the PWM GPIO pin; this will make your life easier than doing it otherwise. Have it take an input value and adjust the duty cycle accordingly.
    First, use the program to find the duty cycle which keeps the servo motor in the neutral position; do not assume that the value in the datasheet is precise.
    Use the program to find the duty cycle which rotates the motor to the limit in one direction.
    Use the program to find the duty cycle which rotates the motor to the limit in the other direction.
    Determine the angular resolution limit of your program. In other words, how small a change in angle can you consistlently produce?
  5. Program Refinement

    Modify your program so that you input the desired angle of rotation in degrees.
    Modify your program so that, when you quit, the motor will be returned to the neutral position.

  6. Demonstrate your circuit and program to the lab supervisor.


Resources

To view pdf documents, you can download Adobe Acrobat Reader .
get Acrobat Reader
If you need to update a browser, you might try Firefox which is Get Firefox!
Since this page uses cascading style sheets for its layout, it will look best with a browser which supports the specifications as fully as possible.

If you are looking for an office package, with a word processor, spreadsheet, etc., you might try LibreOffice which is Get LibreOffice!

Go to the main page for the Department of Physics and Computer Science.

Valid XHTML 1.1

Valid CSS!

WCAG
2.0
(Level AA)

Wilfrid Laurier University