← About PHYS 351

PHYS 351 · Advanced Instrumentation

Lab 5 · Stepper & servo motor control

Submission Submit the completed lab report as a PDF on Gradescope.

Due: 2:00 p.m. on the next Wednesday or Thursday.

Policies and Instructions
  1. Report Format: Submit a formal, typed lab report in PDF format. Handwritten lab reports will not be accepted. Hand-drawn circuit diagrams will not be accepted; draw every schematic with software (see Software at the end of this manual). Include screenshots, code, and simulation or measurement results where specified.
  2. AI Policy: The use of any AI tool, including a large language model (LLM), to write, generate, debug, or modify code or any portion of the lab report is prohibited unless the course instructor grants explicit permission in advance. A teaching assistant (TA) cannot grant permission to use AI tools.

By signing below, I acknowledge that I have read and understood the policies and instructions above and agree to follow them.

Student Name (print):

Student Signature: Date:

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 pulse width at a fixed 50 Hz frame rate. 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.

  1. 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.
  2. 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.
  3. 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:
    1. turn the motor clockwise for at least two full rotations using both full-step and half-step sequences;
    2. turn the motor counterclockwise for at least two full rotations using both full-step and half-step sequences; and
    3. report the total runtime, number of revolutions, step period, step frequency, revolution period, rotation angle per step, and total number of steps. Compare the reported values with your observations.
Task approvalTasks 1–3 (Stepper Motor)

Course Instructor or TA Signature:

Date and Time:

  1. 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. Power the servo from its own regulated 5–6 V supply, and connect that supply's ground to the Pi's ground. Choose a zero angle and mark it, then write a program that moves the horn 30° from that mark. Check the angle with a protractor.
Task approvalTask 4 (Servo Motor)

Course Instructor or TA Signature:

Date and Time:

Extra Credit (up to +6 points)

Extra credit · up to +6 points · no help given

These tasks are optional and meant for students who finish the required tasks early. The course instructor and TAs will not provide any help with them: no hints, no debugging, and no checking of your design, wiring or code. Do them entirely by yourself.

Finish every required task and get it signed off first. A TA will sign off a finished extra-credit task only when it works. A TA will still stop any setup that could damage the equipment or the Raspberry Pi. Points count only for a task that is signed off and written up in your report, with an error analysis where it applies, as for every task.

  1. Servo calibration and input checking (+6 points). Modify your code so that the servo moves through the full range it can actually reach. Start near the center and move toward each end in small steps. Back off as soon as the horn stops moving or the servo starts to buzz or strain. 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 approvalTask 5 (Extra Credit: Servo Calibration)

Course Instructor or TA Signature:

Date and Time:

Hardware Reference

The lab motor's lead colors are not in either stepper datasheet; use the figure below, and confirm the coil pairs with a DMM before connecting anything. The Lecture 05 notes explain each part in detail.

Lab NEMA 17 pinout. Inside the motor, coil A connects the red and yellow leads and coil B connects the green and gray leads, each a few ohms. The leads leave in the order red A1, yellow A2, green B2, gray B1 and go to DRV8833 outputs AOUT1, AOUT2, BOUT2 and BOUT1.
Figure 1. Lab NEMA 17 stepper. Coil A: red (A1) and yellow (A2). Coil B: green (B2) and gray (B1). The leads arrive in the order red, yellow, green, gray, matching the DRV8833 breakout outputs AOUT1, AOUT2, BOUT2, BOUT1.
DRV8833 breakout board pinout. Top header, left to right: AIN1, AIN2, SLP, BIN2, BIN1, FLT, GND, VM, colored as logic inputs, sleep enable, fault output and power. Bottom header: AOUT1, AOUT2, BOUT2, BOUT1 coil outputs, taking the red, yellow, green and gray motor leads, then AS and BS current-sense nodes. Two 0.20 Ω sense resistors marked R20, labeled A and B, sit left of the chip, and a VMotor screw terminal sits on the right.
Figure 2. DRV8833 breakout. Top header: AIN1, AIN2, SLP, BIN2, BIN1, FLT, GND, VM. Bottom header: AOUT1, AOUT2, BOUT2, BOUT1, AS, BS. SLP must be high for the bridges to run.
MG996R servo pinout: orange carries a 50 Hz signal from a 3.3 V GPIO; red connects to a separate regulated 5–6 V bench supply; brown joins supply negative and Pi ground. Current figures shown are from the supplied reference sheet; verify the actual servo version.
Figure 3. MG996R servo. Orange: signal from a GPIO pin. Red: V+ from a separate regulated 5–6 V bench supply. Brown: ground, shared with the supply and the Pi.
PartLimitSource
DRV8833 motor supply VM2.7–10.8 VTI DRV8833 data sheet, §6.3
DRV8833 current per coilUp to 1.5 A RMS in the PWP and RTY packages, 0.5 A RMS in the PW; 2 A peak. The real limit depends on your board's package and cooling.TI DRV8833 data sheet, §1
DRV8833 logic inputs3.3 V GPIO is a valid high (≥ 2 V)TI DRV8833 data sheet, §6.5
MG996R supplyRegulated 5–6 V, from a supply that can deliver your servo's peak currentTower Pro lists 4.8–6.6 V; the reference sheet you were given says otherwise. See Lecture 5 §9.6.
MG996R signal50 Hz frame (20 ms period)Tower Pro MG996R data sheet

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, step period, step frequency, revolution period, rotation angle per step, and total number of steps for the stepper motor, compared with your observations.
  • An error analysis for every task where it applies, including extra-credit tasks: the uncertainty of each measured or calculated value, its main sources of error, and a comparison with the expected, simulated, or datasheet value.
  • A discussion of any challenges encountered and how you overcame them.
  • If you did the extra credit (Task 5): the measured angular range compared with the datasheet, the duty-cycle-vs-angle table for the servo, your fitting formula and an assessment of its accuracy, and the angle-input program.
Software for drawing and simulation

Draw every circuit diagram with software; hand-drawn circuit diagrams will not be accepted. We recommend the free draw.io; the course’s Drawing Circuit Diagrams page shows how to set it up. If a component has no symbol of its own, use the closest one and label it clearly.

Where a task asks for a simulation: the web version of Multisim is no longer available. If you have a Windows computer, you can install the offline (desktop) version of Multisim; ask a TA for the serial number to install it. Otherwise, feel free to use any SPICE-based simulation tool, such as LTspice or ngspice.

← All course materials