PHYS 351 LAB 5
Stepper and Servo Motor Control
© Ran Yang, Ph.D.
SUBMISSION
Submit the completed lab report as a PDF on Gradescope.
Due: 2:00 p.m. next Monday.
Tasks
You have used simple logic sequences to control LEDs and pulse-width modulation (PWM) to control a DC motor. In this lab, you will control the direction and speed of a stepper motor by changing the polarities of its coil sets in a defined sequence. You will also control a servo motor by varying the PWM duty cycle. Include relevant screenshots, photographs, and videos in your report, and add descriptive comments to your programs. Use the terminal to create a directory for your lab files.
- Read the datasheets for the NEMA 17 stepper motor and motor-driver chip. Identify the motor-driver pins and the stepper motor’s four colored wires. Draw a schematic showing how you plan to connect the driver, motor, Raspberry Pi, and power supply. Show your design to the course instructor or a TA.
- Create full-step and half-step logic tables for both clockwise and counterclockwise rotation. Show the logic tables to the course instructor or a TA.
- Construct the circuit you designed to run the stepper motor. Obtain approval from the course instructor or a TA before applying power. Your code must be able to:
- turn the motor clockwise for at least two full rotations using both full-step and half-step sequences;
- turn the motor counterclockwise for at least two full rotations using both full-step and half-step sequences; and
- report the total runtime, number of revolutions, period, frequency, rotation angle per step, and total number of steps. Compare the reported values with your observations.
TASK APPROVAL
Tasks 1–3 (Stepper Motor)
Course Instructor or TA Signature:
Date and Time:
- Connect the MG996R servo motor to the Raspberry Pi. Attach the two-pronged servo horn to the output gear. Do not rotate it by force; forced rotation can damage the servo. To change the horn orientation, remove it and reinstall it at the desired angle. Write a program that rotates the servo to 30°, and verify the angle with a protractor.
- Modify your code so that the servo rotates through its full range. Measure the angular range and compare it with the datasheet. Create a table of duty cycle versus rotation angle, determine a fitting formula that predicts angle from duty cycle, and evaluate its accuracy. Finally, modify your code to accept a valid angle as input and reject values outside the permitted range.
TASK APPROVAL
Tasks 4–5 (Servo Motor)
Course Instructor or TA Signature:
Date and Time:
Submission Reminder
- Your stepper-motor connection schematic and the full-step/half-step logic tables.
- Your complete, commented Python scripts for both the stepper and servo motors.
- The reported runtime, number of revolutions, period, frequency, rotation angle per step, and total number of steps for the stepper motor, compared with your observations.
- The duty-cycle-vs-angle table for the servo, your fitting formula, and an assessment of its accuracy.
- A discussion of any challenges encountered and how you overcame them.