Oh No, another nozzle cleaning macro

This macro performs a back-and-forth wipe of the nozzle along the X-axis of a Cartesian bed-slinger. The brush is attached to the X-gantry outside of the normal bed range. So, the X-axis position_max value must be increased in the PRINTER.CFG file to allow the nozzle to move to the brush.

VARIABLES:

  • wipe_count: pretty much self-explanatory just know that each count represents a wipe in one-direction only. Back-and-forth is two wipes.
  • y_dir [-1 | 0 | 1]: If nozzle is near Y edges of bed where it could interfere with bed clips then 10mm will be subtracted | omitted | added to the Y position.

PRINTER.CFG file:
Revise [stepper_x] section
position_max: 255 # this value is peculiar to my printer which is normally 220. Yours will certainly be different.

Add the following macro:

[gcode_macro CLEAN_NOZZLE]
description: Simple X-axis back and forth nozzle wipe performed wipe_count/2 times. Two PARAMETERS are both optional. The LAYER parameter provides the current layer info from your slicer's Layer Change G-code and CLEAN_LAYERS provides the iteration control for how frequently the nozzle procedure is actually performed. Defaults to 1, i.e., every layer. E.g. , CLEAN_NOZZLE LAYER={[layer_num] CLEAN_LAYERS=3 will clean the nozzle every third layer. Omitting the parameters forces the clean to be performed. While wipe_count could be changed to a parameter, once you determine how many wipes are sufficient it's simpler to set its value within the macro and fuhgetaboutit.
gcode:
    {% set layer = params.LAYER|default(0)|int %}; active layer number
    {% set clean_layers = params.CLEAN_LAYERS|default(1)|int %}; perform clean procedure every X layer
    {% if layer%clean_layers == 0 %} #the percent sign performs a modulo math operation, i.e., it calcs the remainder of a division operation
        SAVE_GCODE_STATE NAME=clean_nozzle_state
        {% set wipe_count = 6|int %} # each count is a wipe in one-direction
        {% set y_dir = 0|int %}
        {% if printer.toolhead.position.y > (printer.toolhead.axis_maximum.y - 10) %}: # check for potential nozzle movement interference with bed's edge retaining clips
            {% set y_dir = -1 %}
            {% elif printer.toolhead.position.y < (printer.toolhead.axis_minimum.y + 10) %}
                {% set y_dir = 1 %}
        {% endif %}
        G91
        G0 Z5 # avoid potential nozzle drag across existing print
        G90
        G0 Y{printer.toolhead.position.y|int + 10 * y_dir} # move nozzle away from edge clips
        {% for wipe in range(wipe_count) %} # simple X-axis back-and-forth wipe
            G0 X{235 + (20 * (loop.index is even))}
        {% endfor %}
        RESTORE_GCODE_STATE NAME=clean_nozzle_state MOVE=1
    {% endif %}

Add to your slicer’s Layer Change G-code section:
CLEAN_NOZZLE LAYER={[layer_num] CLEAN_LAYERS=3 will clean the nozzle every third layer. Omitting the parameters forces the clean to be performed on each layer.

Add to your slicer’s End G-code section:
CLEAN_NOZZLE

Brush Holder model can be DL’d from Printables.

1 Like