Calculating Z-axis

There's also an on-line tool: ShapeOko Grbl settings calculator

cvoinescu explained how to do this in a forum post.

The leadscrew: it's plain old M8 allthread, which advances 1.25mm per turn.

The coupling between the motor and the leadscrew: it's direct, so 1:1.

The motor: it can be either 200 full steps per revolution (1.8 degree per step), or 400 steps (0.9 degree per step).

The driver: usually 2x, which means two microsteps per step, but it can also be set to 1x, 4x, 8x, 16x (A4988), 32x (DRV8825), 10x (Gecko).

We need to compute microsteps per mm of movement. Let's take a 200-step motor and 2x microstepping:

(2 microsteps/step) x (200 steps/motor_rev) x (1 motor_rev/screw_turn) / (1.25 mm/screw_turn) = 320 microsteps/mm

If you got it right, all units but two will cancel each other out and you'll end up with microsteps/mm. Spelling out the units really helps check that you're multiplying when you mean to multiply, and dividing when you mean to divide. Just start from one unit you need (microsteps) and think through the system all the way to the other unit you want (mm).

Common settings, all assuming M8 thread:
 * 200-step-per-rev motor, full stepping: 160 microsteps/mm
 * 200-step-per-rev motor, half stepping: 320 microsteps/mm
 * 200-step-per-rev motor, 8x microstepping: 1280 microsteps/mm
 * 200-step-per-rev motor, 16x microstepping: 2560 microsteps/mm
 * 400-step-per-rev motor, full stepping: 320 microsteps/mm
 * 400-step-per-rev motor, half stepping: 640 microsteps/mm
 * 400-step-per-rev motor, 8x microstepping: 2560 microsteps/mm
 * 400-step-per-rev motor, 16x microstepping: 5120 microsteps/mm