Anycubic Kossel Klipper Macros

|

Macros are one of the best features in Klipper FW.
You can easily create g-code commands and call them with their name.

There are two ways to use macros:
1. As buttons in Octoprint
2. As commands in g code in your slicer – start/end g-code

1. Download file with macros

I have prepared some macros for you that I use in my Kossel setup.
Start with downloading the file and copying it into your printer.cfg configuration file.

2. Copy macros to your printer.cfg

Copy macros you want between configuration and calibration in your printer.cfg.
If you have a clean printer.cfg file without calibration values, insert macros at the bottom.

3. Prepared macros description

3.1. System macros

I call these macros as “system macros“, because they take care of problems with some g code commands which Klipper does not know.

Also M300 macro defines how to use beeper.

########################################
# System Macros
########################################

[gcode_macro m205]
gcode:
  G4
  
[gcode_macro m108]
gcode:
  G4  

[gcode_macro M300]
default_parameter_S=1000
default_parameter_P=100
gcode:  SET_PIN PIN=BEEPER_pin VALUE={S}
        G4 P{P}
        SET_PIN PIN=BEEPER_pin VALUE=0

3.2. Home and calibration macros

This section contains macros for:
Homing
Delta Calibration
PID Extruder Calibration

Using these macros is very handy, for example:
PID calibration – instead of sending 5 commands via terminal, you can just use one macro which performs all movements, calibrations and also saves values and uploads new configuration.

If you are wondering why I have used so long macro names and why they always start with Macro, such as MacroHome….
Clarity is the reason. It is always better to name macros so you can easily read what it does just from the name.

########################################
# Home and Calibration Macros
########################################

[gcode_macro MacroHome]
gcode:  G28
        M300

[gcode_macro MacroDeltaCalibrate]
gcode:  G28
        M300
        DELTA_CALIBRATE
        M300   
        G28         
        M300   
        SAVE_CONFIG
        M300   
        M18  
        M300
        
[gcode_macro MacroPIDExtruderFanOFF200]
gcode:  G28                
        M300
        G1 X0 Y0 Z2 F 3000      
        M300
        M107
        PID_CALIBRATE HEATER=extruder TARGET=200
        M300     
        G28 
        SAVE_CONFIG        
        M300    
        M18   
        M300               
        
[gcode_macro MacroPIDExtruderFanOFF230]
gcode:  G28                
        M300
        G1 X0 Y0 Z2 F 3000      
        M300     
        M107
        PID_CALIBRATE HEATER=extruder TARGET=230
        M300     
        G28 
        SAVE_CONFIG        
        M300  
        M18     
        M300               
        
        
[gcode_macro MacroPIDExtruderFanON200]
gcode:  G28                
        M300
        G1 X0 Y0 Z2 F 3000      
        M300   
        M106
        PID_CALIBRATE HEATER=extruder TARGET=200
        M300     
        G28 
        SAVE_CONFIG        
        M300    
        M18   
        M300               
        
[gcode_macro MacroPIDExtruderFanON230]
gcode:  G28                
        M300
        G1 X0 Y0 Z2 F 3000      
        M300   
        M106
        PID_CALIBRATE HEATER=extruder TARGET=230
        M300     
        G28 
        SAVE_CONFIG        
        M300  
        M18     
        M300   

3.3. Z offset macros

These are awesome macros for those who frequently change their nozzles or do not use Z offset plugin in their slicer.

For example – PETG needs to be printed cca 0.1 mm higher than PLA.

You have many options how to do that, but these two are the easiest:
Z offset plugin in your slicer such as Cura and use a 0.1 mm offset
Use offset of Z = 0.1

Just remember that eaach time you reboot the printer, you have to send the offset macro again, it resets to default value without this offset.

########################################
# Offset Macros
########################################

[gcode_macro MacroZOffsetPlus0200]
gcode:  SET_GCODE_OFFSET Z=0.2
        M300
 
[gcode_macro MacroZOffsetPlus0150]
gcode:  SET_GCODE_OFFSET Z=0.15
        M300
 
[gcode_macro MacroZOffsetPlus0100]
gcode:  SET_GCODE_OFFSET Z=0.1
        M300
 
[gcode_macro MacroZOffsetPlus005]
gcode:  SET_GCODE_OFFSET Z=0.05
        M300
 
[gcode_macro MacroZOffset0]
gcode:  SET_GCODE_OFFSET Z=0
        M300

[gcode_macro MacroZOffsetMinus005]
gcode:  SET_GCODE_OFFSET Z=*0.05
        M300
   
[gcode_macro MacroZOffsetMinus0100]
gcode:  SET_GCODE_OFFSET Z=*0.1
        M300
   
[gcode_macro MacroZOffsetMinus0150]
gcode:  SET_GCODE_OFFSET Z=*0.15
        M300

[gcode_macro MacroZOffsetMinus0200]
gcode:  SET_GCODE_OFFSET Z=-0.2
        M300

3.4. Nozzle wipe macro

This macro does a simple thing – tries to clean the nozzle before you start printing.
It moves nozzle to the motor on right, squeezes some filament out and cleans the nozzle with a few movements.

If you want to modify and “upgrade” this macro, I would recommend you to perform more movements so the nozzle goes around the whole bed.

########################################
# Nozzle Wipe Macro
########################################
                   
[gcode_macro WIPE]
gcode:
    # Use absolute coordinates
    #G90
    # Reset the G-Code Z offset (adjust Z offset if needed)
    #SET_GCODE_OFFSET Z=0.4
    # Home the printer
    #G28
    # Wipe routine
    G1 X115 Y-50 Z0.2 F 6000
    
    G92 E0
    G4 P2000
    G1 E10 F100
    G1 Z0.2
    G4 P2000
    G1 E10 F100
	
    G1 X100 Y-45 Z0.2 F4000
    G1 X100 Y-35 Z0.2 F4000
    G1 X105 Y-40 Z0.2 F4000
    G1 X110 Y-40 Z0.2 F4000

4. How to use macros as buttons

You will need OctoKlipper plugin for creating these buttons. If you do not have it installed, follow OctoKlipper Installation Guide.

Log in into your OctoPrint and click on a settings button.

Navigate to Plugins – OctoKlipper.

And select Macros.
You can create buttons as you want to.
Just write desired button name and insert macro name in the Command.

5. How to use macros in gcode

You can simply call macros via start or end g code in your slicer.

Open your slicer, in this case Cura and navigate to Settings – Printer – Manage Printers – select your printer – Machine Settings

I use WIPE macro in this example. After the last M109 S command is executed, WIPE macro will be executed.

You can find more guides here:

Anycubic Kossel Klipper guide

More Klipper guides HERE.

Similar Posts

3 Comments

  1. I’m kinda late to the game but I’m getting this error ” Option ‘default_parameter_s’ is not valid in section ‘gcode_macro m300′”. Any idea how to fix?

  2. These are excellent! Does anyone have the Gcode for Extrude 50mm, and Set bed temp 60°C please?

Leave a Reply

Your email address will not be published. Required fields are marked *