Leadscrew Drive with GRBL and G-Code

Many DIY CNC machines and 3D printers use leadscrews along with the open-source GRBL firmware as their drive system. A series of configurations must be performed to accurately control the motion system. This article will describe the steps to configure the GRBL controller using G-code commands.
The following components are involved:

  • Stepper Motor. Typically 1.8° per step → 200 steps/rev
  • Leadscrew
  • Stepper motor driver.
  • (Software Option). Universal G-Code Sender (UGS)

Stepper Motor
Typically, the stepper motor is 1.8° per step → 200 steps/rev, which means 200 steps to rotate 1 full revolution.
Leadscrew
The thread lead of a leadscrew is a major factor that affects the drive system. Lead refers to the distance (in millimeters) the nut moves per one full revolution of the screw. For example, a T8 leadscrew with a 4 mm lead is commonly used in CNC machines, while a T8 leadscrew with an 8 mm lead is typically used in 3D printers.
Stepper motor driver
The micro-stepping is the major factor that affects the drive system. The common value of micro-stepping is 1/8,1/16 and 1/32.. which means:

  • 1/8 micro-stepping: Each full step is divided into 8 microsteps
  • 1/16 micro-stepping: Each full step is divided into 16 microsteps
  • 1/32 micro-stepping: Each full step is divided into 32 microsteps

For example, for the regular 200 steps/rev stepper motor:

  • At full steps (no micro-stepping): 200 steps/rev
  • At 1/8 micro-stepping: 200 x 8 = 1600 steps/rev
  • At 1/16 micro-stepping: 200 x 16 = 3200 steps/rev
  • At 1/32 micro-stepping: 200 x 32 = 6400 steps/rev

The higher the micro-stepping the smoother and the more precis the movement (but potentially less torque).  Normally the micro-stepping can be step up via jumpers or DIP switches on stepper motor driver controller.

1, Calculate Steps per mm
GRBL firmware (some other firmware is similar) is using ‘Steps per mm’ to control the movement, the formula is:
Steps/mm = (Motor steps per rev × Micro-steps) / Leadscrew lead (mm/rev)
2, Set it in GRBL
Example, assuming assuming 1.8° motor and 1/16 micro-stepping and T8 4mm lead for X, Y and Z axis:
Steps/mm = (200 x 16 ) / 4 = 3200 / 4= 800.  The GRBL is $100, $101 and $102 to control X, Y and Z  steps/mm, so the following G-code command:
$100=800 ; x-axis steps/mm
$100=800 ; x-axis steps/mm
$100=800 ; x-axis steps/mm
3, Configure the Max Travel and Feed rate
For most stepper motors, an excessively high feed rate can cause missed steps or lead to irregular T8 leadscrew movement. Below is an example of how to configure $100, $120, and $130 for the X-axis:
$110=3000 ; X max rate (mm/min)
$120=40 ; X acceleration (mm/sec^2)
$130=300 ; X max travel (mm)

Same configuration should be done for Y and Z axis as well.

Save and verify in the G-code sender, for example UGS.

 

Leave a Comment