What is G28?
G28 sends the machine to its reference position (home) by triggering the homing sequence. On 3D printers it moves each axis until an endstop is triggered, then backs off. On CNC machines it moves to the machine reference zero.
Syntax
G28 [X] [Y] [Z]
Parameters
| Parameter | Description |
|---|---|
| X | Home only the X axis |
| Y | Home only the Y axis |
| Z | Home only the Z axis (always home X and Y first for safety) |
| (no args) | Home all axes in the firmware-defined safe order |
Examples
G28โ Home all axes (safe default โ always use this first)
G28 X Yโ Home only X and Y โ useful when only those axes were moved manually
G28 Zโ Home Z only โ used after manually adjusting bed height
Important Notes
- Always run G28 before any print or job โ without homing the machine has no known position.
- Marlin homes in the order Z (if Z_SAFE_HOMING is disabled), then X and Y. With Z_SAFE_HOMING, X and Y home first, then Z probes at center.
- After G28 the work coordinate system is set to the machine's defined home offset.
- On 3D printers, G28 must precede G29 (auto bed leveling). Never run G29 without G28 first.
- On CNC mills, G28 returns to machine zero โ not necessarily the work offset origin (G54โG59).
Common Mistakes
- โ Homing Z before X/Y โ nozzle or tool can crash into a print or clamp during the lateral move.
- โ Running G29 without G28 first โ printer position is undefined, causing incorrect probe results.
- โ Using G28 mid-print โ immediately stops the print and moves the nozzle, ruining the job.
Frequently Asked Questions
Q: Why does my printer home X and Y before Z?
Most Marlin configurations with Z_SAFE_HOMING home X and Y first so the Z probe is positioned at a known safe location (usually bed center) before probing Z. This prevents the probe from triggering on a clip or edge of the bed.
Q: What happens if an endstop isn't triggering during G28?
The axis will travel until it hits the hard mechanical limit (potentially damaging the machine) or Marlin's HOMING_FEEDRATE timeout stops it. Use M119 to check endstop states. If an endstop shows 'open' when it should be triggered, check wiring and physical position.
Q: Does G28 set position to zero?
G28 moves to the machine's homing position and resets internal position tracking. On 3D printers this is typically X0 Y0 Z0 at the front-left-bottom corner. On CNC mills G28 goes to machine zero โ you must then activate a work offset (G54) to set your part origin.
GCodex