G29 measures the print bed and switches on compensation for its shape.
Marlin is built with one of five levelling systems, and the parameters of
G29 depend on which. Three keep a mesh of heights (mesh, bilinear and
unified levelling); two fit a plane and rotate coordinates to match the bed’s tilt
(linear and three-point). Moves in general are on the
Marlin motion page.
With an automatic system, home with G28 first. G28 by default
switches levelling off; M420 S switches it on again, unless the firmware
was built with ENABLE_LEVELING_AFTER_G28 or
RESTORE_LEVELING_AFTER_G28. A saved result can be reused by writing
M420 S1 in place of G29 after storing it with
M500. On a machine with extra rotary axes and no inverse kinematics,
levelling gives wrong results unless the toolhead is upright, and should be turned off
with M420 S0.
G29 with mesh bed levelling
Needs MESH_BED_LEVELING. The user sets the nozzle height by hand at each
point of a grid of GRID_MAX_POINTS_X by GRID_MAX_POINTS_Y,
so no probe is needed.
| Form | Meaning |
|---|---|
G29 S0 | Report the mesh |
G29 S1 | Start: move to the first point |
G29 S2 | Store the height and move to the next point |
G29 S3 I J Z | Set one point: I and J are its indices from 0 (since 2.0.0), Z the new value. Up to 2.0.0 the point was given as X and Y counting from 1 |
G29 S4 | Set an offset for the whole mesh; positive is away from the bed. The documentation names no parameter letter for the value |
G29 S5 | Reset and disable the mesh |
G29 S1 ; first point; adjust Z until paper just passes
G29 S2 ; store, go on; repeat to the end
M500 ; save
G29 with automatic levelling: bilinear, linear and three-point
Bilinear levelling (AUTO_BED_LEVELING_BILINEAR) probes a grid and keeps
it as a mesh. Linear levelling (AUTO_BED_LEVELING_LINEAR) probes a grid
and fits a plane by least squares. Three-point levelling
(AUTO_BED_LEVELING_3POINT) probes three points and fits their plane.
Without a probe, PROBE_MANUALLY turns G29 into a series of
steps: repeat the command until the procedure ends. Anything left out takes the
configured value.
| Parameter | Meaning | Systems |
|---|---|---|
A | Abort a procedure in progress (PROBE_MANUALLY) | All three |
Q | Report the levelling state (PROBE_MANUALLY or DEBUG_LEVELING_FEATURE) | All three |
C | Make up points for testing (DEBUG_LEVELING_FEATURE) | All three |
O | Leave at once if levelling is already on. Since 1.1.9 | All three |
D | Dry run: probe without changing the levelling data | All three |
E | Deploy and stow the probe at every sample instead of once; no effect with a fixed probe | All three |
J | Discard the data in RAM and turn compensation off; EEPROM is untouched. In bilinear levelling this is the meaning without W | All three |
V 0–4 | Verbosity. In linear levelling 2 and above also act as T | All three |
L, R, F, B pos | Left, right, front and back limits of the probed area | Bilinear, linear |
H size | Width and height of a square area to probe | Bilinear, linear |
S rate | XY travel speed between points | Bilinear, linear |
X, Y count | Number of columns and rows to probe | Linear |
P count | Probe a square grid of P by P | Linear |
T | Report the bed topology | Linear |
W | Write one mesh point instead of probing | Bilinear |
I, J index | With W, the point by index | Bilinear |
X, Y pos | With W or manual probing, the point by logical position | Bilinear |
Z value | With W, the height to store; if left out, the current raw Z | Bilinear |
On SCARA machines bilinear levelling probes the bed less
PROBING_MARGIN by default, and every grid point must be reachable;
otherwise it reports (L,R,F,B) out of bounds and a smaller area has to
be given.
G29 P5 ; linear: 5 x 5 grid
G29 X4 Y8 L50 R150 F50 B150 T V4
G29 L50 R150 F50 B150 V4 ; bilinear: configured grid in this area
G29 with unified bed levelling
Needs AUTO_BED_LEVELING_UBL. Unified levelling builds a mesh in phases,
may leave parts of it unfilled, and stores several meshes in numbered EEPROM slots,
apart from the other settings. Without EEPROM support it is limited to
three-point or grid levelling (G29 P0 T or G29 P0 G, as
the documentation writes them) and cannot save a mesh. Where no position is given, it
works on the points nearest the nozzle.
Phases
| Form | Meaning and options |
|---|---|
G29 P0 | Zero the mesh and turn mesh compensation off |
G29 P1 | Invalidate the mesh and probe automatically, in a spiral from the centre. C keeps what is there and probes only the missing points; X Y say where to start; E stows after each point; T reports. Holding the controller button suspends it |
G29 P2 | Measure by hand the points the probe cannot reach; needs a controller with a screen. H sets the height the nozzle rises between points (otherwise Z_CLEARANCE_BETWEEN_PROBES; it may be negative where the mesh dips); B uses a shim, measuring its thickness if none is given; C searches from the current position; X Y move the search origin; T maps progress. Holding the button ends it |
G29 P3 | Fill unmeasured points. With C value, fill the nearest ones with that constant, R of them; without it, extrapolate from the edges inward using neighbouring points (“smart fill”). The results are not measured values |
G29 P4 | Fine tune by hand with the controller: go to the nearest point or to X Y, stop H above the mesh, and save the height the user sets on click. R limits the number of points (otherwise all). With a shim give its thickness as H; it is subtracted. Holding the button ends early. Without a controller use G42 and M421 |
G29 P5 | Find the mean height and standard deviation. With C, shift the mesh to a mean of zero, running P6 |
G29 P6 Cvalue | Shift the whole mesh by the value |
Other parameters
| Parameter | Meaning |
|---|---|
A | Activate unified levelling, as M420 S1 |
D | Disable it, as M420 S0 |
B [thickness] | Shim (“business card”) mode of P2 |
C [value] | Continue, current position or constant, by phase as above. The documentation also mentions G29 Z C to use the current location, but lists no Z parameter |
E | Stow the probe after each point (P1 only) |
F [height] | Fade compensation out up to this height; 10 mm if no number is given. Other systems use M420 Z |
H height | Raise or offset height for P2 and P4 |
I [count] | Invalidate this many points (default 1) nearest the nozzle or X Y |
J [size] | Tilt the stored mesh to the bed: probe three points, or with a number a grid of that many squared |
K slot | Subtract the stored mesh in this slot from the active one; not for printing. Needs UBL_DEVEL_DEBUGGING |
L [slot] | Load a mesh; without a number the last used slot. The slot then serves later loads and saves |
Q index | Load a built-in test pattern, for developers |
R count | Repeat count for P3 and P4; default is all points. P1 ignores it |
S [slot] | Save the mesh and the on or off state to a slot, by default the last one. S-1 prints it as G-code that restores it |
T [0 or 1] | Include a map in the output: 0, the default, readable; 1 delimited for a spreadsheet. Works alone or with most other parameters |
U | Probe only the outer edge, to help level the bed mechanically; used as G29 P1 T U |
V 0–4 | Verbosity |
W | Show internal data. Needs UBL_DEVEL_DEBUGGING |
X, Y pos | Position used by the phases and commands; default the current one |
G28 ; home
G29 P1 ; probe
G29 P3 ; fill the rest; repeat until full
G29 S0 ; save to slot 0
G29 F10.0 ; fade out by 10 mm
G29 A ; activate
M500 ; keep the state
M420: levelling state
Sets or reports levelling; alone, it reports. Switching levelling may change the reported current position.
| Parameter | Meaning |
|---|---|
S 0 or 1 | Disable or enable; enabling needs a valid mesh or matrix. With MARLIN_DEV_MODE, S2 makes a random mesh and enables it |
V | Print the stored mesh or matrix |
Z height | Fade height; 0 switches fading off. Needs ENABLE_LEVELING_FADE_HEIGHT |
C [offset] | Re-centre a valid mesh, then subtract the offset (default 0). Unified levelling centres on the mean, the others on the middle of the range, unless built to use the mean (M420_C_USE_MEAN) |
L [slot] | Load a unified mesh from EEPROM. Needs AUTO_BED_LEVELING_UBL and EEPROM_SETTINGS |
T format | Map format with L or V in unified levelling: 0 readable, 1 CSV, 2 screen style, 4 compact |
M421: set a mesh value
For mesh, bilinear and unified levelling. The forms are M421 I J Z,
M421 X Y Z (mesh levelling only) and M421 C Z (unified
only).
| Parameter | Meaning |
|---|---|
I, J index | X and Y index in the mesh |
X, Y pos | Position, very close to a grid line |
C | The point nearest the nozzle |
Z value | New height |
Q value | Amount to add to the old height |
N | Mark the point as undefined (unified only) |
M422: Z stepper positions
Since 2.0.4; needs Z_STEPPER_AUTO_ALIGN. Stores where
G34 should probe for each Z motor, or where the motor is. Give
S or W together with X and Y.
| Parameter | Meaning |
|---|---|
S 1… | Z motor whose probing point is set |
W 1… | Z motor whose known position is set; needs Z_STEPPER_ALIGN_STEPPER_XY |
X, Y pos | The position |
R | Reset both sets of points to the defaults, as M502 also does |
M423: X twist compensation
Since 2.0.9.4; needs X_AXIS_TWIST_COMPENSATION. The compensation
corrects the G29 mesh for a twisted X beam. Alone, M423
reports the data.
| Parameter | Meaning |
|---|---|
R | Reset the table to its defaults |
A pos | X position where the table starts |
E pos | X position where it ends |
I distance | Spacing along X |
X index | Entry to set, counted from 0; needs Z |
Z offset | Value for that entry; needs X |
The documented example M423 X0 I50 is described there as setting the
start to 0 and the spacing to 50, although by the parameter list the start is
A.
Sources
- MarlinDocumentation – Marlin’s own documentation source, files G029, G029-mbl, G029-abl-bilinear, G029-abl-linear, G029-abl-3point, G029-ubl, M420, M421, M422 and M423 in
docs/gcode/, as of 3 December 2026