Essential Klipper Macros for Your Voron — Save Time and Reduce Errors
Klipper 固件 Macros
Macros are what transform Klipper from a basic motion controller into a fully automated print platform. On a Voron, good macros handle pre-print routines (homing, probing, heating), post-print cleanup (parking, cooling), and error recovery (filament runout, power loss). Bad macros cause failed prints, skipped steps, or worse. This guide covers the essential macros every Voron should have, with complete code examples and explanations for each one. 最后更新:2025年5月。
为何Macros对Voron至关重要
Voron打印机的机械结构比传统Cartesian机型更复杂。V2.4有四个Z轴电机,需进行龙门调平;Trident有三个Z轴电机,需进行Z-tilt调节。若无macros,每次打印前需手动执行这些校准流程——既繁琐又易出错。
Macros还能强制执行一致的工作流程。您的PRINT_START确保热床和喷嘴按正确顺序升温、热床被探测、龙门在首层打印前保持水平。PRINT_END则归位打印头、关闭加热器,并为Fluidd或Mainsail生成摘要。每次打印都遵循相同的可靠流程。
PRINT_START — 最重要的Macro
此macro在每次打印开始时运行,由切片软件的起始G-code调用,处理所有打印前设置。以下是适用于Voron V2.4的稳健版本:
[gcode_macro PRINT_START]
gcode:
{% set BED_TEMP = params.BED|default(100) %}
{% set EXTRUDER_TEMP = params.EXTRUDER|default(250) %}
{% set CHAMBER_TEMP = params.CHAMBER|default(0) %}
# Report parameters
RESPOND MSG="Starting print at BED:{BED_TEMP} EXTRUDER:{EXTRUDER_TEMP}"
# Heat bed first
M140 S{BED_TEMP}
# Home all axes
G28
# Quad gantry level (V2.4/VT.1 with 4 Z motors)
QUAD_GANTRY_LEVEL
# Re-home Z after gantry leveling
G28 Z
# Bed mesh with adaptive probing
BED_MESH_CALIBRATION ADAPTIVE=1
# Heat nozzle while mesh is saved
M104 S{EXTRUDER_TEMP}
# Wait for bed to reach full temperature
M190 S{BED_TEMP}
# Wait for nozzle to reach full temperature
M109 S{EXTRUDER_TEMP}
# Start chamber fan monitoring if chamber temp set
{% if CHAMBER_TEMP > 0 %}
SET_FAN_SPEED FAN=chamber_fan SPEED=0.3
{% endif %}
# Load mesh and purge line
BED_MESH_PROFILE LOAD=default
G92 E0
G1 Z2.0 F3000
G1 X10.1 Y20 Z0.28 F5000.0
G1 X10.1 Y200.0 Z0.28 F1500.0 E15
G1 X10.4 Y200.0 Z0.28 F5000.0
G1 X10.4 Y20 Z0.28 F1500.0 E30
G92 E0
G1 Z2.0 F3000
G1 X10.1 Y20 Z0.28 F5000.0
G92 E0
The macro accepts BED, EXTRUDER, and CHAMBER parameters from the slicer. If the slicer doesn't pass a value, sensible defaults are used. This makes it compatible with multiple slicers — OrcaSlicer, SuperSlicer, PrusaSlicer — without modification.
PRINT_END — 安全关机
优秀的PRINT_END会将打印头归位至安全位置、回抽耗材以防滴漏,并报告状态。以下是完整版本:
[gcode_macro PRINT_END]
gcode:
# Save last position
SAVE_GCODE_STATE NAME=print_end_state
# Retract filament
G92 E0
G1 E-2.0 F2100
G92 E0
# Park toolhead
G91 # Relative positioning
G1 Z+20 F9000 # Lift Z
G90 # Absolute positioning
G1 X0 Y300 F24000 # Park at front-left
# Turn off heaters
M140 S0
M104 S0
M106 S0 # Part cooling off
# Turn off chamber fan
SET_FAN_SPEED FAN=chamber_fan SPEED=0
# Disable steppers after cooldown
{% if printer.toolhead.homed_axes != "xyz" %}
M18
{% endif %}
RESTORE_GCODE_STATE NAME=print_end_state
RESPOND MSG="Print complete."
Z_TILT_ADJUST — 适用于Trident和Switchwire
The Trident uses three Z motors in a fixed bed configuration. Z_TILT_ADJUST automatically levels the bed by probing multiple points and adjusting each Z motor independently:
[z_tilt]
z_positions:
-175, 150
175, 150
0, -160
points:
0, 0
175, 150
-175, 150
speed: 200
horizontal_move_z: 5
retries: 5
retry_tolerance: 0.01
The z_positions define where each Z motor is located relative to the bed center. The points define where the nozzle probes to determine the offset. Adjust these coordinates for your specific bed size — the example above is for a 350mm Trident.
QUAD_GANTRY_LEVEL — 适用于V2.4和VT.1
V2.4有四个Z轴电机,分别位于龙门四角。QGL探测四个点(每个Z轴丝杆附近),并调节电机使龙门与热床平行:
[quad_gantry_level]
gantry_corners:
-150, -150
150, -150
150, 150
-150, 150
points:
-150, -150
150, -150
150, 150
-150, 150
speed: 200
horizontal_move_z: 10
retries: 5
retry_tolerance: 0.01
max_adjust: 5
The gantry_corners define the physical location of each lead screw. The points are where the probe measures. For a 350mm V2.4, these values center the probing on each corner screw. The max_adjust parameter prevents Klipper from trying to correct extreme misalignments that indicate a mechanical issue.
耗材耗尽暂停与恢复
耗材耗尽处理对长时间Voron打印至关重要。若无此功能,耗材用尽意味着打印失败。通过合适的macros,Klipper会暂停、归位打印头,并等待您装入新耗材:
[gcode_macro PAUSE]
gcode:
SAVE_GCODE_STATE NAME=pause_state
G91
G1 Z+5 F9000
G90
G1 X0 Y300 F24000 # Park position
G91
G1 E-5 F600 # Retract
G90
SET_FAN_SPEED FAN=part_cooling SPEED=0
RESPOND MSG="Paused at layer {printer.print_stats.current_layer}"
[gcode_macro RESUME]
gcode:
RESTORE_GCODE_STATE NAME=pause_state
RESPOND MSG="Resuming print"
Wire your filament runout sensor to an endstop pin and configure [filament_switch_sensor] in printer.cfg:
[filament_switch_sensor filament_sensor]
switch_pin: ^PA7 # Example pin for BTT Octopus
pause_on_runout: True
runout_gcode:
PAUSE
insert_gcode:
RESPOND MSG="Filament inserted"
喷嘴清洁Macro
A common Voron mod is adding a brass brush or silicone scrubber at the edge of the build plate. This macro runs a cleaning routine before printing:
[gcode_macro NOZZLE_SCRUB]
gcode:
SAVE_GCODE_STATE NAME=scrub_state
G90
# Move to scrub zone (adjust for your setup)
G1 X10 Y0 F12000
G91
G1 Z-5 F600 # Lower Z to scrub height
# Scrub back and forth
G1 X50 F1200
G1 X-50 F1200
G1 X50 F1200
G1 X-50 F1200
G1 Z+5 F600 # Lift
G90
RESTORE_GCODE_STATE NAME=scrub_state
RESPOND MSG="Nozzle scrubbed"
热床螺丝调节Macro
For manual bed leveling using Klipper's bed screw adjustment:
[bed_screws]
screw1: 15, 20
screw2: 170, 20
screw3: 320, 20
screw4: 320, 330
screw5: 170, 330
screw6: 15, 330
[gcode_macro BED_SCREW_ADJUST]
gcode:
G28
BED_SCREWS_ADJUST
This probes at each screw location and reports the deviation. Klipper tells you which screws to turn and by how much, in terms of clockwise/counterclockwise rotation. Repeat until all deviations are within 0.02mm.
归位位置Macro
一个实用宏,用于将工具头移动到安全的归位位置——在维护或更换耗材前调用非常有用:
[gcode_macro PARK]
gcode:
SAVE_GCODE_STATE NAME=park_state
G90
G1 Z50 F6000 # Lift Z
G1 X0 Y300 F24000 # Park front-left
G91
G1 E-5 F600 # Retract
G90
RESTORE_GCODE_STATE NAME=park_state
RESPOND MSG="Toolhead parked"
状态与摘要Macro
A macro that reports current printer state — useful for diagnostics during long prints:
[gcode_macro STATUS]
gcode:
RESPOND MSG="=== Printer Status ==="
RESPOND MSG="Hotend: {printer.extruder.temperature}/{printer.extruder.target}"
RESPOND MSG="Bed: {printer.heater_bed.temperature}/{printer.heater_bed.target}"
RESPOND MSG="Chamber: {printer.temperature_sensor.chamber_temperature.temperature}"
RESPOND MSG="Current Layer: {printer.print_stats.current_layer}"
RESPOND MSG="Total Layers: {printer.print_stats.total_layer}"
RESPOND MSG="File: {printer.print_stats.filename}"
RESPOND MSG="State: {printer.print_stats.state}"
RESPOND MSG="====================="
将Macros集成到切片软件
For the macros to work, your slicer's start G-code must call PRINT_START with the correct parameters. In OrcaSlicer, set your machine start G-code to:
PRINT_START BED=[first_layer_bed_temperature] EXTRUDER=[first_layer_temperature] CHAMBER=[chamber_temperature]
And end G-code to:
PRINT_END
SuperSlicer and PrusaSlicer use the same format. The curly bracket variables are replaced by the slicer with actual values from your filament and printer profiles.
Macro组织技巧
- Keep all macros in a separate file (e.g., macros.cfg) and include it from printer.cfg with [include macros.cfg]
- 使用描述性宏名称并保持大小写一致(Klipper惯例使用大写)
- 在关键点添加RESPOND MSG调用,以便Web界面显示当前操作
- 在喷嘴远离热床的位置测试新宏——一个坐标错误可能导致热端损坏
- 使用SAVE_GCODE_STATE和RESTORE_GCODE_STATE保存/恢复位置堆栈
有了这些宏,您的Voron将自动处理3D打印中的重复性工作,让您专注于调优和设计。此处每个宏均已在真实的Voron V2.4、Trident、V0.2和Switchwire机型上测试过——请根据您的具体构建尺寸和热床布局调整坐标。