Load/Unload to Filament Detection Sensor

Hi all,

Looking for some help on loading and unloading filament on a 2 in 1 out extruder system.

I have gone through what seems like hundreds of Macro’s and all seem to just define a set distance using the G1 command.

My current test system consist of the folling hardware:

2 extruders feeding into a Y-Splitter then a single tube feeding the hotend, between the extruders and the Y-Splitter, I have a filament detection switch on each line.

So very simple and basic system, I would like to do something along the line of “Homing” the filament, below is just a basic rundown on what I would like to do:

if filament is detected on switch 1 then retract T0 until switch 1 does not detect filament
if filament is detected on switch 2 then retract T1 until switch 2 does not detect filament
if filament is not detected on switch 1 then extrude T0 until switch 1 does detect filament then retract until filament is not detected on switch 1
if filament is not detected on switch 2 then extrude T1 until switch 2 does detect filament then retract until filament is not detected on switch 2

Now to calibrate the distance between the switch and the extruder, I extrude until I see filament coming from the hotend, then:

if filament is detected on switch 1 then retract T0 until switch 1 does not detect filament
if filament is detected on switch 2 then retract T1 until switch 2 does not detect filament
log the E steps used
Save the E steps
Extruder calibrated

I can do most of the above easily if I just command G1 to move the extruder a given length, but I cant work out out how to command the extruder to move until it hits the filament detection switch.

Does Klipper have a built in Macro for load to a filament switch or unoad to a filament switch?

Ive looked through the MMU2 macros, and they are way to complex for the simple tasks I would like to do, I can have the system operate okay by just defining a set distance, but I was hoping someone much more clever than I, has worked this out already.

Caveat up front, I don’t have a filament sensor, but I do have a 6-in-1-out setup that uses a splitter and a set of “close enough” hardcoded distance values like you describe. Having true extruder stepper homing like this would be really nice.

However, I think the problem you’re going to have with doing what you’re trying to do with a macro is that you can’t interrupt a running G1 command without issuing an emergency shutdown. So there’s no way to have a macro do something like retract filament until a filament sensor is triggered. What you could do is use delayed_gcode to hack together the equivalent of a while loop that (for example) retracts 1mm of filament and then checks whether the filament sensor has been activated, and repeats doing this until the filament sensor is activated, at which point the loop breaks and the macro continues. This is a very imperfect solution though, and it has some significant downsides:

  • This method of “homing” will only be accurate to within one unit of whatever distance value you use (e.g. 1mm in the example above).
  • The extruder stepper will come to a complete stop between each successive G1 command, so stringing ten G1 E1 s together will not look the same as a G1 E10. The motion will be jerky and since extruder steppers respect acceleration too, the max extrusion speed likely won’t ever be reached, so the smaller your E value, the slower this will be.

I think the “proper” way to do what you want would be to add some core Klipper code that truly homes the extruder as with other axes. About a year ago someone attempted to do this using a physical endstop switch. It looks like they are still maintaining a Klipper fork with this functionality included. Maybe some parts of that fork could be adapted to use the currently supported filament sensors.

Thanks for the reply, yes I tried all sorts of ways to issue a move without defining an actual distance, and nothing works for the Extruder, the 1 step check system I suppose is a hacky way to do it, but I will just roll with the following code and work on something more substantial, as Im introducing a laser based filament motion detection sensor next, which will ne position after the Y splitter and before the hotend and a motorized nozzle cleaner with catchment bucket.

#######################################################

[gcode_macro T0]
gcode:
{% if “xyz” not in printer.toolhead.homed_axes %}
G28
{% endif %}
SAVE_GCODE_STATE
G1 X60 Y118
{% if printer.configfile.config.extruder.min_extrude_temp is defined %}
{% set TARGET = printer.configfile.config.extruder.min_extrude_temp|float %}
{% else %}
{% set TARGET = 240.0 %}
{% endif %}
{% set TEMP = printer.extruder.temperature|float %}
{% if TEMP|int < TARGET|int %}
M109 S{TARGET}
{% endif %}
{% if printer[“filament_switch_sensor Filament_2”].filament_detected == True %}
Filament_2
Unload
{% endif %}
Filament_1
{% if printer[“filament_switch_sensor Filament_1”].filament_detected == False %}
load
{% endif %}
RESTORE_GCODE_STATE MOVE=1 MOVE_SPEED=5000

[gcode_macro T1]
gcode:
{% if “xyz” not in printer.toolhead.homed_axes %}
G28
{% endif %}
SAVE_GCODE_STATE
G1 X60 Y118
{% if printer.configfile.config.extruder.min_extrude_temp is defined %}
{% set TARGET = printer.configfile.config.extruder.min_extrude_temp|float %}
{% else %}
{% set TARGET = 240.0 %}
{% endif %}
{% set TEMP = printer.extruder.temperature|float %}
{% if TEMP|int < TARGET|int %}
M109 S{TARGET}
{% endif %}
{% if printer[“filament_switch_sensor Filament_1”].filament_detected == True %}
Filament_1
Unload
{% endif %}
Filament_2
{% if printer[“filament_switch_sensor Filament_2”].filament_detected == False %}
Load
{% endif %}
RESTORE_GCODE_STATE MOVE=1 MOVE_SPEED=5000

###########################################################

Okay, I checked out that fork, started to get excited as it does exactl what I want…then I kept reading and seen this:

  • Limitations: It is untested on extruder steppers configured as [extruder_stepper] later synced to a particular [extruder]. No “second home” is performed.

Unfortunately I need to to only home extruder_stepper’s as both T0 and T1 are synced to the single direct drive extruder.