Guide · 3D printing

3D Printer Start G-code Explained Line by Line (Marlin and Klipper)

What every line of a good start code does, the four mistakes that ruin first layers, and how to move the start sequence into a Klipper PRINT_START macro.

By cnccode · Updated
On this page
  1. A good Marlin start code
  2. Why this order
  3. The four classic mistakes
  4. The Klipper way: PRINT_START
  5. More guides
  6. Frequently asked questions

The start code runs before the first layer and decides whether the print starts well. Most problems with the first layer come from a start code copied from another printer.

A good Marlin start code

Marlin
G21                 ; millimetres
G90                 ; absolute positions
M83                 ; relative extrusion
M140 S{bed}         ; start heating the bed
M104 S150           ; nozzle warm, but not oozing
G28                 ; home all axes
M190 S{bed}         ; wait for the bed
G29                 ; probe the mesh (or M420 S1 to load a saved one)
M109 S{nozzle}      ; wait for the nozzle
G92 E0
G1 Z0.3 F1200
G1 X5 Y20 F6000     ; prime line start
G1 Y120 E12 F1200   ; prime line
G1 X5.4 F6000
G1 Y20 E12 F1200
G92 E0

Why this order

  • Heat the bed first, the nozzle only to 150 °C: probing with a hot, oozing nozzle puts a blob under the probe point and changes the Z height.
  • G28 before G29: the mesh needs a known position.
  • Mesh after the bed is hot: beds bend when they heat.
  • M109 before the first extrusion: M104 alone does not wait, and the extruder grinds or the firmware refuses with "cold extrusion prevented".
  • G92 E0 after the prime line in absolute E mode; with M83 it is harmless and keeps the code portable.

The four classic mistakes

  1. M104 instead of M109, so the print starts cold.
  2. Moves outside the bed in the purge or park position of another printer.
  3. A mix of M82 in the start code and relative E in the slicer.
  4. G28 after G29 on Marlin builds where homing turns the mesh off, without M420 S1 afterwards.

Paste your start code into the 3D printer simulator: it reports all four.

The Klipper way: PRINT_START

In Klipper the slicer start code shrinks to one line, PRINT_START BED=60 EXTRUDER=210, and the sequence lives in a macro in printer.cfg. The macro can use the temperatures as variables, run an adaptive mesh only where the part is, and is the same for every slicer. A complete macro is in the program library.

Frequently asked questions

Should the prime line be long?
Long enough to fill the nozzle and to see that the flow is even, typically 100–200 mm. On textured plates a short blob also works.
Was this page helpful?