Home » 3DP » Ender 3 Klipper Conversion – Stage 6 – Macros

Ender 3 Klipper Conversion – Stage 6 – Macros

There are two ways to create macros

Ender 3 Klipper Conversion – Stage 1 – Klipper & Mainsail
Ender 3 Klipper Conversion – Stage 2 – Configure Bed Level Probe
Ender 3 Klipper Conversion – Stage 3 – Extruder Rate & Stepper Motor Calibration
Ender 3 Klipper Conversion – Stage 4 – PID calibration
Ender 3 Klipper Conversion – Stage 5 – Camera Setup & Remote Access
Ender 3 Klipper Conversion – Stage 6 – Macros
Ender 3 Klipper Conversion – Stage 7 – Filament Runout Sensor
Ender 3 Klipper Conversion – Troubleshooting

  • Adding macros to printer.cfg file
  • Creating a macros.cfg file and instruct printer.cfg file about its location.

Filament change

Midprint filament change macro to allow filament change called from slicer using M600 gcode:

# MACROS

[gcode_macro M600]
gcode:
    {% set X = params.X|default(50)|float %}
    {% set Y = params.Y|default(0)|float %}
    {% set Z = params.Z|default(10)|float %}
    SAVE_GCODE_STATE NAME=M600_state
    PAUSE
    G91
    G1 E-.8 F2700
    G1 Z{Z}
    G90
    G1 X{X} Y{Y} F3000
    G91
    G1 E-50 F1000
    G1 E-50 F1000
    G1 E-50 F1000
    G1 E-50 F1000
    RESTORE_GCODE_STATE NAME=M600_state

The G1 E-50 F1000 code is multiplied four times because the max allowed extruder movement – defined in the config.cfg file – is set to 50.

Shutdown

  1. The printer needs a toggle switch mounted at the top of the frame:
  2. When the gantry reaches Z255, the wheel at the end of the gantry hits the switch and the PSU powering the mcu is turned off.
  3. The Raspberry Pi powered with the official pi psu and controlled by a smart plug so at this point, it’s still powered on.
  4. It shuts down using the delayed_gcode macro. Then the smart plug turns the whole thing off using external commands.
[delayed_gcode shutdown]
gcode:
    {action_call_remote_method("shutdown_machine")} # Shutdown AFTER move

[gcode_macro PRINT_END]
gcode:
    M140 S0             # Turn off bed
    M104 S0             # Turn off hotend
    M106 S0             # Turn off fan

    # Initial safety move
    G91                 # Relative
    G1 Z50 F3000         # Quick 50mm lift
    G90                 # Absolute
    G1 X0 Y220          # Present print

    # Wait for cooldown
    TEMPERATURE_WAIT SENSOR=extruder MAXIMUM=40 
    # Power switch off 
    G90
    G1 Z255 F600
    
    UPDATE_DELAYED_GCODE ID=shutdown DURATION=90

Smart plug printer power off (untested)

moonraker.cfg file:

[power printer]
type: tasmota
host: <your_plug_ip_address>
# ... other settings
off_when_shutdown: True

printer.cfg file macro

[gcode_macro POWER_OFF_PRINTER]
gcode:
    # ... (include all the cooldown sequence from above)
    {action_call_remote_method("set_device_power", device="printer", state="off")}