# Klipper Dual Extrusion Macro

**URL:** <https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896>\
**Category:** General Discussion\
**Created:** [April 19, 2024, 4:27pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896 "2024-04-19T16:27:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![JasonStonier](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/jasonstonier/32/11440_2.png) [@JasonStonier](https://klipper.discourse.group/u/JasonStonier)\
**Post date:** [April 19, 2024, 4:28pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/1 "2024-04-19T16:28:00Z")

</div>

### Basic Information:

Ender5 - heavily modified:  
 BTT Octopus v1.1:  
 Pi 3B+  
 N/A

_Fill out above information and_ **_in all cases attach your_ `klippy.log` _file_** (use zip to compress it, if too big). _Pasting your_ `printer.cfg` _is **not** needed_  
_ **Be sure to check our “Knowledge Base” Category first. Most relevant items, e.g. error messages, are covered there** _

### Describe your issue:

Probably an incredibly easy question - but searching hasn’t helped me find the answer.

I’m DIY-ing a dual extruder - same carriage, separate hotends. In terms of the T0/T1 switching macro, I think I understand that…but what I can’t figure out is how to link the two independent parts cooling fans to their respective hotend.

I have the heater fan on PA8 and have linked that to both hot ends in the config - so that’s working.

Can someone point me in the right direction for dealing with my two part cooling fans? I can either parallel them to the board and have them both on regardless of which hot end is in use, or they can be separate on the board - I don’t care which.

Thanks!

---

<div class="post-metadata">

**Author:** ![gaolst](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/gaolst/32/10026_2.png) [@gaolst](https://klipper.discourse.group/u/gaolst)\
**Post date:** [April 19, 2024, 4:45pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/2 "2024-04-19T16:45:36Z")

</div>

If you have independent heaters/thermistors  
and as a result extruders - you can bind each fan to desired extruder.

> [heater\_fan extruder0\_fan]  
> pin: gpio0\_2  
> heater: extruder  
> heater\_temp: 50

> [heater\_fan extruder1\_fan]  
> pin: gpio0\_3  
> heater: extruder1  
> heater\_temp: 50

P.S. these setting will keep them off until your extruder is higher than 50 degree.

---

<div class="post-metadata">

**Author:** ![JasonStonier](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/jasonstonier/32/11440_2.png) [@JasonStonier](https://klipper.discourse.group/u/JasonStonier)\
**Post date:** [April 20, 2024, 10:36am UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/3 "2024-04-20T10:36:54Z")

</div>

Forgive me if I don’t understand - but I think what you posted was for the heater fan - i.e. the cooling fan for the heatbreak. I have one heater fan and that is working with this config:  
[heater\_fan fan1]  
pin: PA8  
heater: extruder, extruder1  
heater\_temp: 50.0

What I am asking regards the part cooling fans, which are independent. I currently have this (which doesn’t work):

[fan] #this is part cooling fan 1  
pin: PE5

[fan1] #this is part cooling fan 2  
pin: PD12

But I don’t know how to bind [fan] to extruder, and [fan1] to extruder1 - clearly something simple I am missing.

Thanks,

---

<div class="post-metadata">

**Author:** ![TheFuzzyGiggler](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/thefuzzygiggler/32/12313_2.png) [@TheFuzzyGiggler](https://klipper.discourse.group/u/TheFuzzyGiggler)\
**Post date:** [April 20, 2024, 1:33pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/4 "2024-04-20T13:33:36Z")

</div>

> [@JasonStonier](#):
>
> don’t know how to bind [fan] to extruder, and [fan1] to extruder1 - clearly something simple I am missing.

Klipper doesn’t currently support that (I’m working on a fix for it). You’ll have to use [fan\_generic] with a SET\_FAN\_SPEED.

There’s also some details here…

[https://www.klipper3d.org/Config\_Reference.html#dual\_carriage](https://www.klipper3d.org/Config_Reference.html#dual_carriage)

Watch the “Features” category in the next few days, I’ll be posting a Klipper patch for users to test out potential new fan features/fixes/upgrades.

One of the things I’ve added a fix for is that functionality for users with multiple extruders. I’m putting the finishing touches on some last minute things today so HOPEFULLY should be out this evening or tomorrow at the latest.

Edit: Let me be clear. Klipper currently doesn’t support defining two or more part cooling fans as [fan]. I didn’t mean it doesn’t support multiple extruders.

---

<div class="post-metadata">

**Author:** ![theophile](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/theophile/32/31_2.png) [@theophile](https://klipper.discourse.group/u/theophile)\
**Post date:** [April 20, 2024, 1:40pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/5 "2024-04-20T13:40:42Z")

</div>

I haven’t done this specifically but it should be fairly easy to override M106 and M107 to relay the parameters to a SET\_FAN\_SPEED command targeted to the desired generic fan, which can be tracked with a variable that is updated by whatever macros you use to switch extruders.

---

<div class="post-metadata">

**Author:** ![TheFuzzyGiggler](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/thefuzzygiggler/32/12313_2.png) [@TheFuzzyGiggler](https://klipper.discourse.group/u/TheFuzzyGiggler)\
**Post date:** [April 20, 2024, 1:46pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/6 "2024-04-20T13:46:34Z")

</div>

M106/M107 is solely linked to the [fan], it doesn’t even take any variables/fan numbers/ etc.  
It does take a gcode command though, so it MIGHT work, but I’d be super surprised.

---

<div class="post-metadata">

**Author:** ![theophile](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/theophile/32/31_2.png) [@theophile](https://klipper.discourse.group/u/theophile)\
**Post date:** [April 20, 2024, 2:03pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/7 "2024-04-20T14:03:00Z")

</div>

M106 takes an S parameter. You just override M106, intercept the S parameter, convert it to a float, and use that with SET\_FAN\_SPEED on whatever the current extruder’s fan is. M107 is even easier because you just override that to SET\_FAN\_SPEED SPEED=0 on the current extruder’s fan.

---

<div class="post-metadata">

**Author:** ![EddyMI3D](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/eddymi3d/32/1981_2.png) [@EddyMI3D](https://klipper.discourse.group/u/EddyMI3D)\
**Post date:** [April 20, 2024, 4:40pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/8 "2024-04-20T16:40:31Z")

</div>

I’ve got these macros for my IDEX printer with two hotends.  
Maybe it works:

```auto
# ======================= F A N S =========================

# X1 print cooling fan
[fan_generic fan]
pin: PH6
cycle_time: 0.0100
#hardware_pwm: True
kick_start_time: 1.00

# X2 print cooling fan
[fan_generic fan1]
pin: PB6
cycle_time: 0.0100
#hardware_pwm: True
kick_start_time: 1.000

[gcode_macro M207]
gcode:
    {% if params.S is defined %}
      SET_RETRACTION RETRACT_LENGTH={params.S|int}
    {% endif %}
    {% if params.R is defined %}
      set printer.firmware_retraction.unretract_length VALUE={params.R|int}
    {% endif %}
    {% if params.F is defined %}
      set printer.firmware_retraction.retract_speed VALUE={params.F|int*60}
    {% endif %}
    {% if params.T is defined %}
      set printer.firmware_retraction.unretract_speed VALUE={params.T|int*60}
    {% endif %}

[gcode_macro FAN_VARIABLE]
gcode:

variable_active_fan: 0

#--- Carriages print cooling FANs ---
variable_fan: 'fan' # carriage X1
variable_fan1: 'fan1' # carriage X2
#--- Other user define FANs ---
variable_fan2: 'fan2'     
variable_fan3: 'fan3'
variable_fan4: 'fan4'  
variable_fan5: 'fan5'

##########################################################
# PRINTER FANS MANAGEMENT
# Redefine G-code command M106 and M107 
##########################################################

[gcode_macro M106]
description: Override "M106" to allow multiple extruders.
gcode:
    {% set fan_vars = printer["gcode_macro FAN_VARIABLE"] %}
    {% set raw_speed = params.S|default(0)|float %}
    {% set fan_speed = (raw_speed / 255.0)|round(2) %}     
        
    {% set target_fan = params.P|default(fan_vars.active_fan)|int %}
    {% set default_fan = ('fan', 'fan1', 'fan2', 'fan3', 'fan4', 'fan5')[target_fan] %}     
    
    {% if target_fan in [0,1] %}
       ### carriages print cooling FAN   
        CARRIAGE_PRINT_FAN SPEED={fan_speed}
    {% else %}
       ### other user define FAN
        SET_FAN_SPEED FAN={default_fan} SPEED={fan_speed}
    {% endif %}

[gcode_macro M107]
description: Override "M107" to allow multiple extruders.
gcode:
    M106 S0
     
[gcode_macro CARRIAGE_PRINT_FAN]
description: Set automatically the print fan speed for dual carriages modes 
gcode:
    {% set fan_vars = printer["gcode_macro FAN_VARIABLE"] %}      
    
    {% if params.SPEED is defined %}
        {% set fan_speed = params.SPEED|float %}
    {% else %}
        ### read print fan speed from active carriage/extruder
        {% set fan_speed = printer["fan_generic " + fan_vars.fan].speed|float %}
        {% set fan1_speed = printer["fan_generic " + fan_vars.fan1].speed|float %}
        {% set fan_speed = [fan_speed, fan1_speed]|max %}
    {% endif %}
        
    {% if fan_vars.active_fan == 0 %}
        ### FAN on carriage X1
        SET_FAN_SPEED FAN={fan_vars.fan} SPEED={fan_speed}
        SET_FAN_SPEED FAN={fan_vars.fan1} SPEED=0
    {% elif fan_vars.active_fan == 1 %}
        ### FAN on carriage X2
        SET_FAN_SPEED FAN={fan_vars.fan} SPEED=0
        SET_FAN_SPEED FAN={fan_vars.fan1} SPEED={fan_speed}
    {% endif %}

[heater_fan my_nozzle0_fan]
pin: PH3
heater: extruder
heater_temp: 50.0
fan_speed: 1.0

[heater_fan my_nozzle1_fan]
pin: PL4
heater: extruder1
heater_temp: 50.0
fan_speed: 1.0

```

---

<div class="post-metadata">

**Author:** ![TheFuzzyGiggler](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/thefuzzygiggler/32/12313_2.png) [@TheFuzzyGiggler](https://klipper.discourse.group/u/TheFuzzyGiggler)\
**Post date:** [April 20, 2024, 9:45pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/9 "2024-04-20T21:45:46Z")

</div>

Ah, I was thinking of it the other way around like you were trying to feed the M106 a “T” parameter, you’re just intercepting the S parameter and using it with Fan set speed.

The fix I mentioned a few comments above is for this very thing, where Klipper would support “M106 T1 S255” or whatever straight from the slicer so there is no need to jump through these hoops.

It will need testing though, I don’t have an IDEX printer, I’ve just been renaming fans to cooling fans and trying it out that way.

---

<div class="post-metadata">

**Author:** ![JasonStonier](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/jasonstonier/32/11440_2.png) [@JasonStonier](https://klipper.discourse.group/u/JasonStonier)\
**Post date:** [April 21, 2024, 12:38pm UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/10 "2024-04-21T12:38:13Z")

</div>

Thanks all - so, my understanding is that M106 turns on [fan] - and that is true regardless of the active extruder. So for now I have physically parallel-ed the two fans so both are on in response to an M106 - that’ll work fine for my use case.

---

<div class="post-metadata">

**Author:** ![mjfsch](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@mjfsch](https://klipper.discourse.group/u/mjfsch)\
**Post date:** [April 22, 2024, 9:40am UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/11 "2024-04-22T09:40:41Z")

</div>

you can keep the fans separate, but link the control of them together like this:

`[multi\_pin my\_fan]  
pins:PA8,PE5

[fan]  
pin: multi\_pin:my\_fan`

that way your wiring wouldn’t need to be changed in future when klipper is able to support controlling them independently.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/klipper/original/1X/64419bf2aac6639e6ef5cef200dcd456b0a01ac3.png) [@system](https://klipper.discourse.group/u/system)\
**Post date:** [June 21, 2024, 9:41am UTC](https://klipper.discourse.group/t/klipper-dual-extrusion-macro/15896/12 "2024-06-21T09:41:29Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
