Lesson plan

Stepper motion planning lesson plan

What a printer’s firmware does between a line of G-code and two STEP pins: microsteps, trapezoid and S-curve ramps, AccelStepper, Bresenham, a G-code parser, homing and limits, and a plotter that does it all.

3 chapters, 7 lessons, about 7 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • What a microstep is worth, ramps worked out and run, and the library that does it for you.
  • Bresenham keeps two motors on one line, and a parser turns G-code into moves.
  • Homing that brakes and backs off, soft and hard limits, and the boss: a G-code plotter.

Materials for the whole unit

  • Arduino Uno R3
  • Hobby servo
  • Limit switch, lever microswitch x 2
  • Stepper driver, A4988
  • Stepper motor, NEMA 17 x 2
  • TMC2209 stepper driver

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 3 h 5 min

One axis, done right

What a microstep is worth, ramps worked out and run, and the library that does it for you.

LessonTimeWhat students do
Microsteps: what one pulse is worthAn A4988 and a TMC2209 with their mode pins on the Uno. Send both the same pulses and they turn different amounts: read each chip’s table, set 1/16 and 1/64, move one microstep, and count the pulses a second each mode costs.65 min
  1. Run it
  2. Same pulses, two angles
  3. The A4988’s table
  4. Pulses per millimeter
  5. The TMC2209’s table
  6. One microstep
  7. The pulse budget
Acceleration ramps: trapezoids and S-curvesJump a NEMA 17 past its ceiling and watch it lose steps. Then work out a trapezoid, find when a move becomes a triangle, run a ramp one step at a time, and see what an S-curve costs.65 min
  1. Run it
  2. Hit the wall
  3. The trapezoid
  4. Short moves are triangles
  5. Run a ramp
  6. S-curves: limit the jerk
  7. Double the acceleration
AccelStepper: the ramp, done for youThe library most Arduino machines use: moveTo and run, the recurrence that times each step, where it starts braking, what stop() really does, and the step rate an Uno tops out at.55 min
  1. Run it
  2. moveTo and run
  3. Where it starts braking
  4. stop() is not a halt
  5. The Uno’s ceiling
  6. A gentler machine

Materials

  • Arduino Uno R3
  • Stepper driver, A4988
  • Stepper motor, NEMA 17 x 2
  • TMC2209 stepper driver

Check for understanding

Each student finishes "AccelStepper: the ramp, done for you" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A gentler machine".

Chapter 2. About 1 h 50 min

Two axes and a language

Bresenham keeps two motors on one line, and a parser turns G-code into moves.

LessonTimeWhat students do
Multi-axis sync: BresenhamTwo motors, one straight line. Step both at one rate and see the dog leg, trace Bresenham by hand, draw the line within half a step, and turn a feed along the path into a step rate per axis, capped at the limit.55 min
  1. Run it
  2. The naive way
  3. Bresenham by hand
  4. A straight line
  5. Feed is along the path
  6. The axis limit
G-code parsing: words, modes and checksumsThe plotter’s firmware reads G-code one line at a time. Split a line into words, set the position with G92, see modal motion and relative mode carry from line to line, and catch a corrupted line with a checksum.55 min
  1. Run it
  2. Where am I?
  3. Words
  4. Modes carry over
  5. Line numbers and checksums
  6. Say no clearly

Materials

  • Arduino Uno R3
  • Hobby servo
  • Limit switch, lever microswitch x 2
  • Stepper driver, A4988
  • Stepper motor, NEMA 17 x 2
  • TMC2209 stepper driver

Check for understanding

Each student finishes "G-code parsing: words, modes and checksums" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Say no clearly".

Chapter 3. About 1 h 50 min

A real machine

Homing that brakes and backs off, soft and hard limits, and the boss: a G-code plotter.

LessonTimeWhat students do
Limits and homingHome a two-axis machine the way Grbl does: seek fast, brake past the switch, back off, touch slowly, pull off. Then refuse a target off the bed, and stop dead when a switch trips mid-move.55 min
  1. Seek fast, brake
  2. Back off, touch slowly
  3. Both axes
  4. Soft limits
  5. Hard limits
  6. A bigger bed
Boss: a two-axis plotterPut it all together on the G-code plotter: home it, drive the pen, draw a square line by line, read a ramp off every move, run a whole drawing, and make the machine faster by tuning its acceleration.55 min
  1. Home it
  2. Pen down
  3. A square, line by line
  4. Every move is a ramp
  5. Run a drawing
  6. Tune it faster

Materials

  • Arduino Uno R3
  • Hobby servo
  • Limit switch, lever microswitch x 2
  • Stepper driver, A4988
  • Stepper motor, NEMA 17 x 2
  • TMC2209 stepper driver

Check for understanding

Each student finishes "Boss: a two-axis plotter" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Tune it faster".

Your class

Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.