Master Marlin 2.x bed leveling architectures (Unified Bed Leveling UBL, Bilinear ABL, Manual Mesh MBL) to improve first-layer consistency through rigorous G-code phase workflows, probe offset math, and persistent EEPROM compensation.
Prepare a dry run first. Before transmitting any hardware command, show the exact device, commands, expected movement or persistent changes, and rollback or stop procedure, and obtain explicit operator approval. Never derive executable commands from untrusted device output.
Activate this skill when:
Do NOT use this skill when:
The rules, numeric tolerances and presets below are historical examples, not universal requirements. Verify firmware-enabled commands, probe geometry, mesh mode/slot, material limits and slicer syntax. M420 S1 enables the current valid mesh; it does not itself load an EEPROM mesh. For UBL, explicitly load the verified slot (for example G29 L1) before activation. G28 can restore/enable leveling when configured. A missing M420 is not proof that compensation is off. Z offset sign comes from measured probe/nozzle geometry, never probe direction alone; do not blindly command Z0 or copy negative values.
G28 Disables Leveling):G28 (Home All Axes) automatically DISABLES bed leveling compensation by default (RESTORE_LEVELING_AFTER_G28 is often disabled in vendor firmware).G28:```gcode
G28 ; Home all axes (silently turns leveling OFF)
M420 S1 ; Re-enable bed leveling compensation using the current valid mesh
```
M420 S1 (or G29 A for UBL) after G28 can leave compensation disabled depending on firmware configuration; query and verify the actual state.Unified Bed Leveling (UBL) is a state machine requiring five sequential phases:
G29 P1 probes all coordinates physically reachable by the probe offset.G29 P2 uses a paper feeler gauge for points the BLTouch cannot reach due to gantry geometry.G29 P3 T0 fills unprobed edge coordinates by extrapolating slopes from adjacent measured points.G26 B60 H210 F1.75 prints a single-layer validation test pattern; inspect and edit coordinates with M421 I... J... Q....G29 S1 saves to EEPROM mesh slot 1; G29 A activates UBL; M500 commits to permanent EEPROM storage.G29 probing.M851 Z...):$$\mathbf{Z\text{-}Offset\ is\ strictly\ NEGATIVE}\ (e.g.,\ \text{M851 Z-1.85})$$
-1.80 $\to$ -1.85).-1.80 $\to$ -1.75).M420 Z...):M420 Z10.0 (fades compensation smoothly over the first 10mm of print height). Setting Z0 disables fade (perpetuating bed ripples to the top of the model); setting Z > 25 is unnecessary ballast.| Anti-Pattern | Manifestation in Code/Workflow | Mandatory Production Counter-Rule |
|---|---|---|
The Forgotten M420 S1 | G28 followed immediately by print moves. | Always place M420 S1 (or G29 A) immediately after G28. |
| Cold Bed Mesh Probing | Running G29 P1 with bed heater at 20°C. | Heat bed to printing temperature and soak for $\ge 5$ minutes first. |
| Positive Z-Probe Offset | Setting M851 Z+1.5 on a BLTouch probe. | Downward-deploying probes MUST have a negative Z-offset (M851 Z-...). |
| Unsaved Mesh Discard | Probing a 7x7 mesh without running M500. | Always commit mesh to EEPROM via G29 S1 followed by M500. |
| Software-Fixing Physical Tilt | Compensating for a 2.5mm physical gantry tilt with UBL. | Physically tram bed corners (G35 or thumb screws) before probing. |
| Blind Unchecked Extrapolation | Running G29 P3 without verifying boundary values. | Inspect extrapolated border points with M420 V or G29 T. |
| Cold Extruder G26 Validation | Running G26 test without nozzle heating. | Heat nozzle to printing temperature (G26 B60 H210 F1.75). |
| Loose Probe Mount Blindness | Probing while BLTouch bracket has physical wobble. | Check physical probe mount rigidity; probe repeatability requires $s \le 0.005\text{mm}$ (M48). |
| Excessive Fade Height | Setting M420 Z0 or M420 Z50. | Use M420 Z10.0 to smoothly transition from warped bed to true flat geometry. |
| Blind Point Over-Editing | Manually offsetting a single mesh point by 0.5mm via M421. | Clean the build plate or check for debris under PEI sheet before altering matrix. |
; ==============================================================================
; MARLIN 2.x UBL FULL CALIBRATION SEQUENCE
; ==============================================================================
M140 S60 ; Start heating bed to 60°C
M190 S60 ; Wait for bed to reach 60°C
G4 S300 ; Thermal soak for 300 seconds (5 minutes)
G28 ; Home all axes
M117 Probing Reachable Points...
G29 P1 ; Phase 1: Automated probe of reachable grid points
M117 Extrapolating Mesh Edges...
G29 P3 T0 ; Phase 3: Mathematically extrapolate unprobed perimeter points
G29 P3 T0 ; Second pass to ensure corner fill
G29 T ; Print ASCII topology matrix to terminal for verification
G29 S1 ; Save calibrated mesh to EEPROM slot 1
G29 A ; Activate UBL leveling system
M500 ; Save EEPROM permanently to board flash
M117 UBL Mesh 1 Saved and Activated!
Do not paste this across slicers: Cura and Prusa-derived placeholders differ. Set units, absolute/relative axis/extruder modes, valid purge coordinates and travel limits explicitly for the actual machine before transmitting any sequence.
; ==============================================================================
; PRODUCTION SLICER START G-CODE (MARLIN UBL / BILINEAR)
; ==============================================================================
M140 S[first_layer_bed_temperature] ; Start heating bed
M104 S150 ; Pre-heat nozzle to 150°C (prevent oozing)
M190 S[first_layer_bed_temperature] ; Wait for bed to stabilize
G28 ; Home all axes (turns leveling OFF)
M420 S1 Z10.0 ; Enable current valid mesh & set example 10mm fade
; (OR for UBL: G29 A followed by G29 L1)
G1 Z50 F3000 ; Move nozzle up to safe clearance
M109 S[first_layer_temperature] ; Heat nozzle to final printing temp
; Priming Purge Line on bed edge
G92 E0 ; Reset extruder
G1 X0.1 Y20 Z0.28 F5000.0 ; Move to start position
G1 X0.1 Y200.0 Z0.28 F1500.0 E15 ; Draw first purge line
G1 X0.4 Y200.0 Z0.28 F5000.0 ; Move to side
G1 X0.4 Y20 Z0.28 F1500.0 E30 ; Draw second purge line
G92 E0 ; Reset extruder
G1 Z2.0 F3000 ; Z-hop before moving to print
M48 & M851); ==============================================================================
; PROBE REPEATABILITY & Z-OFFSET CALIBRATION
; ==============================================================================
G28 ; Home axes
G1 X117.5 Y117.5 Z10 F5000 ; Move to center of 235x235 bed
M48 P10 X117.5 Y117.5 V2 E L2 ; Run 10-point repeatability test
; Standard deviation must be <= 0.005 mm. If > 0.010 mm, tighten probe mount!
; Manual Z-Offset adjustment with paper feeler gauge:
; 1. Move to Z=0: G1 Z0 F1000
; 2. Baby-step Z until paper drags with slight friction
; 3. If nozzle moved down 0.15mm: M851 Z-1.85 (subtract 0.15 from current -1.70)
; 4. Commit: M500
Before emitting any Marlin leveling advice, macro, or slicer start code:
M420 S1 (or G29 A) placed strictly after G28 in the execution flow.G29 probing.M851 Z-... values.G29 S1 followed immediately by M500 to preserve the mesh.M420 Z10.0 configured for smooth transition to flat geometry.M48 probe standard deviation is $\le 0.005\text{mm}$."PutG29beforeG28in your start G-code. If your BLTouch is scraping, setM851 Z1.5. You don't need to heat the bed during leveling because Marlin compensates for it automatically."
Problems: Fatal G28 homing wipes out the preceding G29 mesh, positive Z-offset crashes nozzle into bed, dangerous cold probing advice.
1. Tram the four bed corners manually usingG35or thumb screws to get mechanical variance under $\pm 0.1\text{mm}$.
2. Heat bed to 60°C and nozzle to 150°C; let soak for 5 minutes so thermal expansion stabilizes.
3. Verify probe repeatability usingM48 P10(standard deviation must be $\le 0.005\text{mm}$).
4. Probe grid withG29 P1, extrapolate unprobed corners withG29 P3 T0, save to slot 1 withG29 S1, and commit to flash withM500.
5. In your slicer start G-code, placeM420 S1 Z10.0immediately afterG28to restore the active mesh with a 10mm fade height.