3D Printing and the Power of Klipper Macros
What is a Klipper Macro?
A Klipper macro is a variable subprogram (or subroutine) that allows a user to create a complex set of reusable commands in GCODE. It should be noted that GCODE macros are common in not only Klipper, CNC, and Marlin. In Marlin, most users are familiar with a simple GCODE macro for print start in a slicer. Like Marlin, the most common macros are used in printer start and end code. For example, from the Klipper GitHub:
[gcode_macro START_PRINT]
gcode:
{% set BED_TEMP = params.BED_TEMP|default(60)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}
# Start bed heating
M140 S{BED_TEMP}
# Use absolute coordinates
G90
# Reset the G-Code Z offset (adjust Z offset if needed)
SET_GCODE_OFFSET Z=0.0
# Home the printer
G28
# Move the nozzle near the bed
G1 Z5 F3000
# Move the nozzle very close to the bed
G1 Z0.15 F300
# Wait for bed to reach temperature
M190 S{BED_TEMP}
# Set and wait for nozzle to reach temperature
M109 S{EXTRUDER_TEMP}[gcode_macro END_PRINT]
gcode:
# Turn off bed, extruder, and fan
M140 S0
M104 S0
M106 S0
# Move nozzle away from print while retracting
G91
G1 X-2 Y-2 E-3 F300
# Raise nozzle by 10mm
G1 Z10 F3000
G90
# Disable steppers
M84
The above START_PRINT code heats the bed and nozzle, homes the printer, and preps the printer to start printing.
Like most new Klipper users, my first real experience with Klipper macro is the above start and end code. As I explored and researched Klipper, I saw this “Faster Klipper Bed Probing Macro” post. This article opened my eyes to the power of Klipper macros. With the code, the printer will look at the model's size and only probe an area slightly larger than the model. This greatly reduces the time to print. As far as I can tell, there is no impact on bed adhesion.
This macro led me to look for additional powerful macros. I then found this repo, described as a “collection of macros for the Klipper 3D printer firmware”,
What are jschuh’s klipper macros?
BEFORE INSTALLING BE SURE TO READ THE ENTIRE README ON GITHUB
jschuh’s klipper macros are a massive collection of macros compiled and developed by GitHub user jschuh. The scripts include many powerful tools including:
- Bed Mesh Improvements
- Bed Surface Options
- Draw/Purge line options
- Fan Controls
- Filament Options
- Heater Control
- Kinematics
- Layer Triggers
- Pause, Resume, Cancel
- Print Start and End
- Velocity Controls
- Optional Fast Bed Mesh Probing
For me, the fast bed mesh is a game changer. Using that in conjunction with the draw options allows me to create a universal code.
In most cases, I can use the same basic code over and over. Basically, the same scripts are usable on all of my printers. Overall, these scripts allow me to manage my printers in the same way with the same functionality.
Video Tutorial
Create Your Own Macro:
- Klipper Macro Creation — https://klipper.discourse.group/t/macro-creation-tutorial/30/1