← All course materialsLecture 05 · Stepper & servo motorsReading notes →

Lecture 05: Stepper and Servo Position Control

1 / 30
PHYS 351 · Lecture 0501

Lecture 05

Stepper and Servo Position Control

Part 1 · the stepper and its DRV8833 driver

Part 2 · the servo

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0502

What turns, and what stays still

Which part turns. Brushed DC motor: fixed north and south magnets form the stator, the coil on the shaft is the rotor, and brushes on a commutator switch its current as it turns. Stepper motor: four fixed coil poles A, B, A-bar and B-bar form the stator, a bar magnet is the rotor, and the external driver switches the coils.

Every motor turns because a magnetic field pulls on the rotor. The difference is who switches that field: brushes inside a DC motor, your driver for a stepper.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0503

The simplest stepper: four steps per turn

The simplest stepper in four states. A+: the A poles are energized and the rotor magnet's north end points to 0°. B+: the B poles are energized and it points to 90°. A−: to 180°. B−: to 270°. Four states, 90° each, four steps per revolution.

A permanent-magnet stepper. Energize a pair of poles: the magnet lines up and holds. Switch to the next pair: it follows. 90° per step is far too coarse.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0504

A common 1.8° hybrid stepper

Hybrid stepper cutaway: toothed stator poles surround a 50-tooth permanent-magnet rotor. Offset north and south rotor cups enable 200 steps per revolution, or 1.8 degrees per step. © W. G. Marshall 2024.
An opened NEMA 17: rotor, eight poles, two coils

Hybrid = magnet + toothed iron.

Rotor: a magnet between two 50-tooth cups, N and S, ½ tooth apart.

Stator: 8 poles × 6 teeth.

Teeth set the step; the magnet adds torque.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0505

Each pole sits a quarter tooth off the last

Unrolled tooth alignment: each stator pole has six teeth at 7.2 degrees pitch, with pole positions separated by 45 degrees. The rotor tooth pitch is also 7.2 degrees. Successive poles are offset by 0, 1.8, 3.6 and 5.4 degrees relative to the rotor, giving quarter-tooth alignment changes.

Rotor teeth every 7.2°, poles every 45° = 6 × 7.2° + 1.8°. So the next pole is 1.8° out of line. NEMA 17 is only the frame size: check your motor's step angle.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0506

Why 1.8° and 200 steps

Opened stepper motor exposing the rotor and surrounding copper stator windings connected to colored leads.
θtooth=360∘50=7.2∘\theta_{\mathrm{tooth}}=\frac{360^\circ}{50}=7.2^\circ

Four coil states move one tooth:

θstep=7.2∘4=1.8∘,S=200\theta_{\mathrm{step}}=\frac{7.2^\circ}{4}=1.8^\circ,\quad S=200

Half step: 0.9∘0.9^\circ, S=400S=400.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0507

Eight poles, two coils, four wires

Eight stator poles around a 50-tooth rotor, alternately belonging to coil A (A, A-bar, A, A-bar) and coil B (B, B-bar, B, B-bar), 48 stator teeth in all. Coil A is its four poles wound in series between leads A1 (red) and A2 (yellow); coil B is its four poles in series between B2 (green) and B1 (gray). Two coils with two ends each give four wires.

A and Ā are wound in opposite senses, so one current makes N and S poles at the same time.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0508

Each coil: plus, minus or off

Vector sum of the two coil fields: coil A alone points along 0°, coil B alone along 90°, and both together point along 45° with a magnitude 1.41 times either one.
xIN1xIN2Coil
10+ (OUT1 → OUT2)
01− (OUT2 → OUT1)
00off

Two driver inputs per coil. The field is the vector sum of A and B.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0509

Full step: four states, two coils on

#AIN1AIN2BIN1BIN2Field
0101045°
10110135°
20101225°
31001315°

Each row: field +90°, rotor +1.8°.

Four full-step states in a two-by-two grid with both coils energized. Coil A poles lie left and right, coil B poles top and bottom; the field arrow points along a diagonal: state 0 A+ B+ inputs 1 0 1 0 at 45°, state 1 A− B+ 0 1 1 0 at 135°, state 2 A− B− 0 1 0 1 at 225°, state 3 A+ B− 1 0 0 1 at 315°.
© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0510

Half step: eight states

#AIN1AIN2BIN1BIN2Field
010000°
1101045°
2001090°
30110135°
40100180°
50101225°
60001270°
71001315°
Eight half-step states, the field arrow advancing 45° each time: 0 A+ 1 0 0 0; 1 A+ B+ 1 0 1 0; 2 B+ 0 0 1 0; 3 A− B+ 0 1 1 0; 4 A− 0 1 0 0; 5 A− B− 0 1 0 1; 6 B− 0 0 0 1; 7 A+ B− 1 0 0 1. Inputs are in the order AIN1 AIN2 BIN1 BIN2.

One coil, two coils, alternating: 0.9° per row.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0511

The two coils run a quarter cycle apart

Coil current direction against state index over two electrical cycles. Full step: coil A and coil B are square waves of plus and minus, B lagging A by one state, a quarter cycle. Half step: each coil steps plus, zero, minus, zero in a staircase, B again a quarter cycle behind A.

Walk the table up for one direction, down for the other. Wrong way? Reverse the index or swap one coil's two leads.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0512

From step delay to RPM

RPM=60S td  ⇒  td=60S⋅RPM\mathrm{RPM}=\frac{60}{S\,t_d}\;\Rightarrow\;t_d=\frac{60}{S\cdot\mathrm{RPM}}

60 RPM:

full: 60200×60=5 ms\text{full: }\frac{60}{200\times60}=5\mshalf: 60400×60=2.5 ms\text{half: }\frac{60}{400\times60}=2.5\ms
Shaft speed against step delay from RPM = 60 / (S t_d). The full-step curve with S = 200 crosses 60 RPM at 5 ms; the half-step curve with S = 400 crosses 60 RPM at 2.5 ms. Both fall as the delay grows.
© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0513

Loop overhead makes the motor slower

Timeline of the stepping loop: each state begins with a short overhead block for the GPIO writes and loop bookkeeping, t_oh, followed by a long sleep t_d, so the real step period is t_d plus t_oh.

800 half steps at 2.5 ms: 2.0 s predicted. Measured 2.08 s means toh=2.08 s/800−2.5 ms=0.1 mst_{oh}=2.08\,\mathrm{s}/800-2.5\ms=0.1\ms, so 57.7 RPM. Sleep 2.4 ms for 60 RPM.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0514

How fast can it step?

Coil current rising toward its final value with time constant L/R of about 1.5 ms for 2.8 mH and 1.86 Ω: it reaches 49 % of final current after 1 ms and 96 % after 5 ms.
Illustration of missed steps. The software count rises one step every period to 360°. The actual shaft follows until a loaded or too-fast stretch where it stays still for two periods, then keeps stepping two steps behind, ending 72° short with nothing to detect the error.

τ=L/R≈1.5 ms\tau=L/R\approx1.5\ms: step faster than a few τ\tau and the current, and so the torque, never builds. Then steps slip and nothing notices.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0515

Sample code 1: pins and settings

import time
import RPi.GPIO as GPIO

# DRV8833 input pins (BCM numbers).
# Example wiring: change to match yours.
AIN1 = 19
AIN2 = 26
BIN1 = 20
BIN2 = 21

GPIO.setmode(GPIO.BCM)
GPIO.setup(AIN1, GPIO.OUT, initial=0)
GPIO.setup(AIN2, GPIO.OUT, initial=0)
GPIO.setup(BIN1, GPIO.OUT, initial=0)
GPIO.setup(BIN2, GPIO.OUT, initial=0)

Example only. Do not copy this code as it is: read it, learn from it, then write your own.

# Send one row of the table to the driver.
def set_coils(a1, a2, b1, b2):
    GPIO.output(AIN1, a1)
    GPIO.output(AIN2, a2)
    GPIO.output(BIN1, b1)
    GPIO.output(BIN2, b2)

# Settings
steps_per_rev = 200  # 1.8° full steps
turns = 2            # turns to make
rpm = 30             # target speed
direction = 1        # 1 forward, -1 back

# Delay per step in seconds, Eq. (5)
delay = 60 / (steps_per_rev * rpm)
total_steps = turns * steps_per_rev

Example only. Do not copy this code as it is: read it, learn from it, then write your own.

© Ran Yang, Ph.D.Example code only: learn from it, then write your ownAdvanced Instrumentation
PHYS 351 · Lecture 0516

Sample code 2: the full-step loop

# Align first; this initial movement is not a counted step.
state = 0
try:
    set_coils(1, 0, 1, 0)
    time.sleep(0.2)  # allow alignment at this starting state
    start = time.perf_counter()
    for step in range(total_steps):
        state = (state + direction) % 4
        if state == 0:
            set_coils(1, 0, 1, 0)  # A+ B+
        elif state == 1:
            set_coils(0, 1, 1, 0)  # A- B+
        elif state == 2:
            set_coils(0, 1, 0, 1)  # A- B-

Example only. Do not copy this code as it is: read it, learn from it, then write your own.

        else:
            set_coils(1, 0, 0, 1)  # A+ B-
        time.sleep(delay)

    elapsed = time.perf_counter() - start
    print(f"Time: {elapsed:.2f} s")
    print(f"Average RPM: {turns * 60 / elapsed:.1f}")
finally:
    set_coils(0, 0, 0, 0)  # release coils even after Ctrl-C
    GPIO.cleanup()

Example only. Do not copy this code as it is: read it, learn from it, then write your own.

© Ran Yang, Ph.D.Example code only: learn from it, then write your ownAdvanced Instrumentation
PHYS 351 · Lecture 0517

The lab motor's pinout

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.

Coil A: red–yellow.

Coil B: green–gray.

DMM, power off: a few Ω within a pair, OL across.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0518

Datasheets use other colors

17HS4401S datasheet connection diagram: one winding between the black and green leads, the other between the red and blue leads, beside the rotor.
17HS4401S: black–green, red–blue
Step angle1.8°
Rated current1.7 A per phase
Resistance1.5 Ω
Inductance2.8 mH
Holding torque43 N·cm
Leads4, two coils

Trust the DMM, not the colors.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0519

The DRV8833: two H-bridges in one chip

DRV8833 datasheet functional block diagram: logic inputs AIN1, AIN2, BIN1, BIN2 and nSLEEP with pulldown resistors feed control logic, which drives two four-transistor H-bridges through gate drivers with overcurrent protection. Bridge A drives AOUT1 and AOUT2, bridge B drives BOUT1 and BOUT2, each returning through a sense resistor on AISEN or BISEN; a charge pump, internal regulator, over-temperature monitor and nFAULT output are also shown.

VM: 2.7–10.8 V.

1.5 A RMS (PWP/RTY packages) or 0.5 A RMS (PW); 2 A peak. Keep it cool.

Inputs: 3.3 V logic, 16 µA, pulled down.

Built in: overcurrent and thermal shutdown.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0520

One bridge, four input states

Four input states of one DRV8833 H-bridge. IN1 1, IN2 0: high-side switch 1 and low-side switch 2 on, current flows from VM through the coil from OUT1 to OUT2 to ground. IN1 0, IN2 1: the other diagonal, current from OUT2 to OUT1. IN1 0, IN2 0: all four switches off, outputs high impedance, coast. IN1 1, IN2 1: both low-side switches on, the coil is shorted and its current circulates, brake.

Stepping uses 10, 01 and 00. Brake (11) shorts the coil and drags on the rotor.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0521

The breakout board pinout

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.

xIN: active high.

SLP (nSLEEP): 0 V sleeps, 3.3 V runs. Tie it to 3.3 V.

FLT (nFAULT): drops to 0 V on a fault. Optional.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0522

Current limit and protection

DRV8833 datasheet motor control circuitry: xIN1 and xIN2 enter a PWM block and predriver that switch four transistors between VM and the xISEN pin; a comparator compares the voltage across the optional sense resistor with a 200 mV reference and feeds back to the PWM block.
Ichop=0.2 VRsense=0.2 V0.20 Ω=1.0 AI_{\mathrm{chop}}=\frac{0.2\,\mathrm{V}}{R_{\mathrm{sense}}}=\frac{0.2\,\mathrm{V}}{0.20\,\Omega}=1.0\,\mathrm{A}

Board resistors: R20 = 0.20 Ω.

No limit: 5/1.86=2.7 A5/1.86=2.7\,\mathrm{A}. The overcurrent trip (2 A min, 3.3 A typical) is a last resort, not a way to set the current.

Too hot (≈150 °C): shuts down, FLT goes low.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0523

Wiring in blocks

Block wiring for the stepper. Four Raspberry Pi GPIO outputs at 3.3 V drive AIN1, AIN2, BIN1 and BIN2. Bridge A drives coil A through the red and yellow leads; bridge B drives coil B through the green and gray leads. A separate motor supply feeds VM, and the Pi ground, the DRV8833 ground and the supply negative are joined.

Your Task 1 schematic adds GPIO numbers, the supply voltage, SLP and the 10 µF bypass capacitor.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0524

Part 2 · A servo is a DC motor that knows its angle

Opened hobby servo showing a DC motor, reduction gears, position potentiometer, and a small control circuit.
Pulse in, angle out: everything else is inside

Ordinary DC motor.

Gears: slow and strong.

Potentiometer on the output shaft.

A controller chip.

Together: a feedback loop.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0525

The circuit inside the case

Inside a servo. The signal wire's pulse width is converted to a target voltage and fed to the plus input of an error amplifier. A potentiometer between V+ and ground turns with the output shaft; its wiper voltage goes to the minus input. The error drives an H-bridge powered from V+, which drives the DC motor, gears and horn, and the horn turns the potentiometer, closing the loop.

Pulse width → target. Potentiometer → actual. The error drives the motor toward the target. (This shows the idea; the MG996R does it with a small digital controller.)

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0526

Not a stepper at all

Open versus closed loop. Stepper: the Pi's step sequence goes to the DRV8833, the coils, the rotor and the shaft angle, with no path back, so software assumes every step happened. Servo: the Pi's pulse width goes to a controller, motor and gears, and shaft angle, and a potentiometer on the shaft feeds the angle back to the controller.

No steps, no coil tables: a servo measures its own angle and corrects. A stepper only counts.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0527

DC motor, stepper or servo?

DC motorStepperServo
You controlspeedposition, by countingangle, by feedback
Motioncontinuous, fastany number of turnslimited arc
Holds positionnoyes, while poweredyes, corrects loads
Feedbacknonenone: counts stepspotentiometer
Driverone switch or H-bridgetwo H-bridges, a tablebuilt in
Use it forfans, wheels, pumpsprinters, stages, pumpsarms, flaps, pointers

Lab 4 was the DC motor. Lab 5 is the other two.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0528

PWM sets a target, not the power

Pulse width sets the target angle. A 1 ms pulse, 5 % duty, sets the horn to −60°; 1.5 ms, 7.5 % duty, to the center; 2 ms, 10 % duty, to +60°. The mapping is nominal and must be calibrated for each servo.

Power comes from the red wire; the pulse only says where to go.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0529

Three pins: what goes where

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.

Orange to a GPIO pin. Red to its own regulated 5–6 V bench supply. Brown to that supply's − and to Pi GND.

© Ran Yang, Ph.D.Advanced Instrumentation
PHYS 351 · Lecture 0530

Calibrate against what you measure

Illustrative servo calibration: measured angle against measured pulse width from 0.8 to 2.2 ms, rising from about 0 to 180°, with a straight-line fit. A residual panel below shows scatter within about ±5° with a slight systematic curve.

Approach each end slowly; back off at the first buzz.

Record duty, scope pulse width and angle, both directions.

Fit, check residuals, reject angles outside your range.

© Ran Yang, Ph.D.Advanced Instrumentation

Use ← → to move, Home / End to jump, and F for fullscreen.

Figure descriptions

Slide 2 · What turns, and what stays still

Which part turns. Brushed DC motor: fixed north and south magnets form the stator, the coil on the shaft is the rotor, and brushes on a commutator switch its current as it turns. Stepper motor: four fixed coil poles A, B, A-bar and B-bar form the stator, a bar magnet is the rotor, and the external driver switches the coils.

Slide 3 · The simplest stepper: four steps per turn

The simplest stepper in four states. A+: the A poles are energized and the rotor magnet's north end points to 0°. B+: the B poles are energized and it points to 90°. A−: to 180°. B−: to 270°. Four states, 90° each, four steps per revolution.

Slide 4 · A common 1.8° hybrid stepper

Hybrid stepper cutaway: toothed stator poles surround a 50-tooth permanent-magnet rotor. Offset north and south rotor cups enable 200 steps per revolution, or 1.8 degrees per step. © W. G. Marshall 2024.

Slide 5 · Each pole sits a quarter tooth off the last

Unrolled tooth alignment: each stator pole has six teeth at 7.2 degrees pitch, with pole positions separated by 45 degrees. The rotor tooth pitch is also 7.2 degrees. Successive poles are offset by 0, 1.8, 3.6 and 5.4 degrees relative to the rotor, giving quarter-tooth alignment changes.

Slide 6 · Why 1.8° and 200 steps

Opened stepper motor exposing the rotor and surrounding copper stator windings connected to colored leads.

Slide 7 · Eight poles, two coils, four wires

Eight stator poles around a 50-tooth rotor, alternately belonging to coil A (A, A-bar, A, A-bar) and coil B (B, B-bar, B, B-bar), 48 stator teeth in all. Coil A is its four poles wound in series between leads A1 (red) and A2 (yellow); coil B is its four poles in series between B2 (green) and B1 (gray). Two coils with two ends each give four wires.

Slide 8 · Each coil: plus, minus or off

Vector sum of the two coil fields: coil A alone points along 0°, coil B alone along 90°, and both together point along 45° with a magnitude 1.41 times either one.

Slide 9 · Full step: four states, two coils on

Four full-step states in a two-by-two grid with both coils energized. Coil A poles lie left and right, coil B poles top and bottom; the field arrow points along a diagonal: state 0 A+ B+ inputs 1 0 1 0 at 45°, state 1 A− B+ 0 1 1 0 at 135°, state 2 A− B− 0 1 0 1 at 225°, state 3 A+ B− 1 0 0 1 at 315°.

Slide 10 · Half step: eight states

Eight half-step states, the field arrow advancing 45° each time: 0 A+ 1 0 0 0; 1 A+ B+ 1 0 1 0; 2 B+ 0 0 1 0; 3 A− B+ 0 1 1 0; 4 A− 0 1 0 0; 5 A− B− 0 1 0 1; 6 B− 0 0 0 1; 7 A+ B− 1 0 0 1. Inputs are in the order AIN1 AIN2 BIN1 BIN2.

Slide 11 · The two coils run a quarter cycle apart

Coil current direction against state index over two electrical cycles. Full step: coil A and coil B are square waves of plus and minus, B lagging A by one state, a quarter cycle. Half step: each coil steps plus, zero, minus, zero in a staircase, B again a quarter cycle behind A.

Slide 12 · From step delay to RPM

Shaft speed against step delay from RPM = 60 / (S t_d). The full-step curve with S = 200 crosses 60 RPM at 5 ms; the half-step curve with S = 400 crosses 60 RPM at 2.5 ms. Both fall as the delay grows.

Slide 13 · Loop overhead makes the motor slower

Timeline of the stepping loop: each state begins with a short overhead block for the GPIO writes and loop bookkeeping, t_oh, followed by a long sleep t_d, so the real step period is t_d plus t_oh.

Slide 14 · How fast can it step?

Coil current rising toward its final value with time constant L/R of about 1.5 ms for 2.8 mH and 1.86 Ω: it reaches 49 % of final current after 1 ms and 96 % after 5 ms.

Illustration of missed steps. The software count rises one step every period to 360°. The actual shaft follows until a loaded or too-fast stretch where it stays still for two periods, then keeps stepping two steps behind, ending 72° short with nothing to detect the error.

Slide 17 · The lab motor's pinout

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.

Slide 18 · Datasheets use other colors

17HS4401S datasheet connection diagram: one winding between the black and green leads, the other between the red and blue leads, beside the rotor.

Slide 19 · The DRV8833: two H-bridges in one chip

DRV8833 datasheet functional block diagram: logic inputs AIN1, AIN2, BIN1, BIN2 and nSLEEP with pulldown resistors feed control logic, which drives two four-transistor H-bridges through gate drivers with overcurrent protection. Bridge A drives AOUT1 and AOUT2, bridge B drives BOUT1 and BOUT2, each returning through a sense resistor on AISEN or BISEN; a charge pump, internal regulator, over-temperature monitor and nFAULT output are also shown.

Slide 20 · One bridge, four input states

Four input states of one DRV8833 H-bridge. IN1 1, IN2 0: high-side switch 1 and low-side switch 2 on, current flows from VM through the coil from OUT1 to OUT2 to ground. IN1 0, IN2 1: the other diagonal, current from OUT2 to OUT1. IN1 0, IN2 0: all four switches off, outputs high impedance, coast. IN1 1, IN2 1: both low-side switches on, the coil is shorted and its current circulates, brake.

Slide 21 · The breakout board pinout

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.

Slide 22 · Current limit and protection

DRV8833 datasheet motor control circuitry: xIN1 and xIN2 enter a PWM block and predriver that switch four transistors between VM and the xISEN pin; a comparator compares the voltage across the optional sense resistor with a 200 mV reference and feeds back to the PWM block.

Slide 23 · Wiring in blocks

Block wiring for the stepper. Four Raspberry Pi GPIO outputs at 3.3 V drive AIN1, AIN2, BIN1 and BIN2. Bridge A drives coil A through the red and yellow leads; bridge B drives coil B through the green and gray leads. A separate motor supply feeds VM, and the Pi ground, the DRV8833 ground and the supply negative are joined.

Slide 24 · Part 2 · A servo is a DC motor that knows its angle

Opened hobby servo showing a DC motor, reduction gears, position potentiometer, and a small control circuit.

Slide 25 · The circuit inside the case

Inside a servo. The signal wire's pulse width is converted to a target voltage and fed to the plus input of an error amplifier. A potentiometer between V+ and ground turns with the output shaft; its wiper voltage goes to the minus input. The error drives an H-bridge powered from V+, which drives the DC motor, gears and horn, and the horn turns the potentiometer, closing the loop.

Slide 26 · Not a stepper at all

Open versus closed loop. Stepper: the Pi's step sequence goes to the DRV8833, the coils, the rotor and the shaft angle, with no path back, so software assumes every step happened. Servo: the Pi's pulse width goes to a controller, motor and gears, and shaft angle, and a potentiometer on the shaft feeds the angle back to the controller.

Slide 28 · PWM sets a target, not the power

Pulse width sets the target angle. A 1 ms pulse, 5 % duty, sets the horn to −60°; 1.5 ms, 7.5 % duty, to the center; 2 ms, 10 % duty, to +60°. The mapping is nominal and must be calibrated for each servo.

Slide 29 · Three pins: what goes where

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.

Slide 30 · Calibrate against what you measure

Illustrative servo calibration: measured angle against measured pulse width from 0.8 to 2.2 ms, rising from about 0 to 180°, with a straight-line fit. A residual panel below shows scatter within about ±5° with a slight systematic curve.