Skip to content

Class 1 · Frame and one motor

Today the Ender 3 becomes a pile of parts, and the parts become a frame with four motors on it. You set up the electronics that drive the motors, make one motor move a belt a set distance, and measure how far it really went.

By the end of class

One motor, on the frame, moves a belt 100 mm when your code tells it to, and you have measured its steps per millimeter with a ruler.

New parts today

Part What it's for
Ender 3 (motors, cables, pulleys, idlers, supply, screws) Everything that moves
FRC 2×1 tube, 10-32 screws, nylon lock nuts The frame
Printed motor mounts (yours, from Onshape) Hold a motor at each corner
CNC Shield V3 + four A4988 drivers Drive the four motors from the Uno
GT2 pulleys, GT2 belt Turn motor rotation into belt length

Build it

Take the Ender apart

  1. Unplug the printer. Take photos of where every cable goes before you remove it.
  2. Keep: the four motors with their cables, the 24 V supply in its housing, the GT2 pulleys from the X and Y motors, the two idlers, and the screws. Bag the screws by size.
  3. The Z motor has a lead-screw coupler and the E motor has a drive gear. Loosen their set screws with a hex key and slide them off. Those two motors get the new 5 mm-bore pulleys.
  4. Leave the supply alone apart from unplugging its output leads from the mainboard. The cord, switch and wall side are Dr. Alvear's.

Build the frame

  1. Lay out the 2×1 tube in a rectangle a few centimeters bigger than the whiteboard on every side, so each motor sits just outside a corner of the board.
  2. Bolt the corners with 10-32 screws, washers and nylon lock nuts. Tighten until the joint doesn't rock; the nylon keeps the nut from backing off.
  3. Fix the whiteboard inside the frame so it can't shift. Stand the frame upright and make it stable (feet, a clamp to the table, or a lean against the wall you trust).
  4. Bolt a printed mount at each corner through the tube's holes, and screw a motor to each mount with M3 screws. Each pulley should sit a few millimeters in front of the board's surface, so the belt runs flat and close to the board.
  5. Measure the distance between the centers of the two top pulleys and write it in your build log. You need it in Class 2.

Set up the shield

Motors go to the corners like this. Keep it the same on every page from now on.

Motor Corner Shield socket Step pin Dir pin
1 Top left X 2 5
2 Top right Y 3 6
3 Bottom left Z 4 7
4 Bottom right A 12 13

All four drivers share one enable pin, pin 8. It's active LOW: LOW turns the drivers on, HIGH lets the motors go limp.

These pin numbers come from the GRBL pin map, which the CNC Shield V3 is wired for. The A socket is the exception: it has no pins of its own until you jumper it.

  1. A axis jumpers. Next to the A socket is a small block of jumper pins. You can use it to make A copy X, Y or Z (we don't want that) or to give A its own step and direction pins on 12 and 13. Read the labels printed on your board and set the two jumpers that connect A's step to D12 and A's direction to D13. If your board's labels don't make sense, show Dr. Alvear before you guess.
  2. Microstepping. Under each driver socket are three jumper pairs: MS1, MS2, MS3. Put a jumper on all three under every socket. On an A4988 that means 1/16 steps: 3200 steps per revolution instead of 200.
  3. Drivers. Press each A4988 into its socket so the pin marked EN on the driver lines up with EN on the shield. A driver in backwards dies the moment power goes on. Stick on the heatsinks.
  4. Press the shield onto the Uno.

Motor cables: check before you plug in

The Ender's cables were wired for the Ender's board, not this shield. Each motor has two coils, and each coil is a pair of wires. Unplug everything and set your multimeter to Ω. Measure between the pins of the cable's plug: two pins that read a few ohms are one coil; pins that read OL are on different coils. The shield's motor header is labeled 2B, 2A, 1A, 1B: one coil goes on the two "2" pins, the other on the two "1" pins. If a coil is split across the 1 and 2 pins, the motor buzzes and doesn't turn. Write down which pins pair up, for all four cables.

Power

From To
24 V supply, + output lead Shield screw terminal +
24 V supply, − output lead Shield screw terminal −
Laptop USB Uno

The shield connects the supply's − to the Uno's ground for you. Have Dr. Alvear check the polarity before you switch the supply on the first time. The A4988 can take up to 35 V on its motor input, so 24 V is fine.

Never plug or unplug a motor with the 24 V on

Switch off first, every time. A motor unplugged under power can destroy its driver.

Tool: setting a driver's current limit (Vref)

A stepper motor doesn't limit its own current. The A4988 does it for you, and a small screw (a potentiometer) on the driver sets how much. Too low and the motor skips; too high and the motor and driver overheat.

You can't measure the current directly, so you measure a voltage, Vref, that sets it:

I = Vref ÷ (8 × Rs), so Vref = 8 × Rs × I

Rs is the sense resistor on your driver board. Look for two small resistors near the chip and read the code printed on them: R100 is 0.100 Ω, R068 is 0.068 Ω, R050 is 0.050 Ω. Your board's value is the one that counts; different makers use different ones.

For I, read the current rating on the label of your motor and aim for about 70 % of it. That keeps the motor cool and gives you room.

Example with made-up numbers: a motor rated 1.0 A, a driver with R100. 70 % of 1.0 A is 0.70 A, so Vref = 8 × 0.100 Ω × 0.70 A = 0.56 V.

To measure: motors unplugged, USB and 24 V on. Black probe on the shield's ground (the − screw terminal), red probe on the metal top of the driver's potentiometer. Turn the screw in tiny steps with a small screwdriver and read again. Clockwise usually raises Vref.

Mission 1 · Set all four drivers

Read the label on your motors and the sense resistor on your drivers. Work out your target Vref in the build log, showing the formula with your numbers. Set every driver to it.

Done when

All four drivers read within 0.02 V of your target, and the four readings are in your build log.

The software

Make a new PlatformIO project for the Uno. Here is the full platformio.ini; you'll use the Servo library in Class 3.

[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 115200
lib_deps =
    waspinator/AccelStepper@^1.64
    arduino-libraries/Servo

AccelStepper drives a stepper through a driver like the A4988: it sends a pulse on the step pin for every step and sets the direction pin. It also includes MultiStepper, which you'll use next class.

Tool: AccelStepper

You create one AccelStepper object per motor, tell it the step and direction pins, then give it targets. This example is a photo turntable on the X socket: it turns a quarter turn, waits two seconds, and repeats.

#include <AccelStepper.h>

const int STEP_PIN = 2;
const int DIR_PIN = 5;
const int ENABLE_PIN = 8;

AccelStepper table(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);

void setup() {
  pinMode(ENABLE_PIN, OUTPUT);
  digitalWrite(ENABLE_PIN, LOW);   // LOW = drivers on
  table.setMaxSpeed(1600);         // steps per second
  table.setAcceleration(800);      // steps per second, per second
}

void loop() {
  table.move(800);                 // 800 steps from here: a quarter turn at 1/16
  table.runToPosition();           // waits until it gets there
  delay(2000);
}
  • move(n) sets a target n steps from where the motor is now. moveTo(n) sets a target at step n, counted from where the motor was when the program started (position 0).
  • runToPosition() waits until the motor arrives. Nothing else runs meanwhile.
  • currentPosition() tells you which step the motor is on.
  • Step counts get big. Store them in a long, not an int (an int on the Uno stops at 32,767).
  • If a motor turns the wrong way, setPinsInverted(true, false, false) flips its direction pin in code.

Mission 2 · One motor turns

Plug the top-left motor into the X socket (24 V off while you do it). Write a program that turns it one full revolution forward, waits, then turns back to where it started.

Done when

A piece of tape on the pulley ends exactly where it started, and the motor turned smoothly without buzzing or skipping.

Why should it be 80 steps per millimeter?

The motor takes 200 full steps per revolution. At 1/16 microstepping that's 200 × 16 = 3200 steps. A GT2 belt has a tooth every 2 mm, and the pulley has 20 teeth, so one revolution moves 20 × 2 mm = 40 mm of belt. 3200 steps ÷ 40 mm = 80 steps/mm.

Mission 3 · Measure steps per millimeter

Wrap a length of belt around the top-left pulley and hang a little weight on it (a few washers) so it stays on the teeth. Put a mark on the belt next to a fixed point. Command a move that should be 100 mm of belt, then measure how far the mark actually moved with a ruler. Work out your measured steps per millimeter: steps sent ÷ millimeters moved. Do it three times.

Done when

Your build log has the three measurements and your steps/mm, and it is within 1 % of 80 (or you've found out why not).

If you finish early

  • Mount the other three pulleys and run Mission 2 on each motor in its own socket. Socket A tests your jumpers.
  • Note which way each motor turns for a positive move. Next class you'll want "positive" to mean "belt gets longer" on every motor.
  • Try setMaxSpeed higher until the motor stalls, then back off. Write down the speed that still works with the 24 V supply.
  • Print the gondola.

Sign-off with Dr. Alvear

  • Frame bolted, whiteboard fixed, four motors mounted
  • Coil pairs checked on all four cables and written down
  • Vref target worked out and all four drivers set
  • One motor moves 100 mm of belt on command; steps/mm measured
  • Build log updated (photo + two sentences)