Advanced Configuration Section - Phil1988/FreeDi GitHub Wiki
FreeDi is designed to work correctly out of the box, but advanced users can tune certain aspects of the configuration for more control or better compatibility with custom setups.
This page collects optional tweaks that go beyond the default behavior.
⚠️ Note: The default configuration works with any slicer and does not require these extras.
This page is exclusively for users who want to dive deeper into Klipper configuration files.
Fan Integration (output_pin vs fan_generic vs fan)
On FreeDi v1.X fans are integrated by default as [output_pin].
FreeDi v2.00 keeps supporting that scheme, but also supports [fan_generic] and the part-cooling-specific [fan], which gives you smoother control and cleaner macros.
-
[output_pin]– Simple on/off or PWM pin viaSET_PIN.
(Compatible with FreeDi v1.x macros, no "FAN=" commands.) -
[fan_generic]– Manually controlled fan, supportsSET_FAN_SPEED FAN=<name>.
(Recommended forsidefan,filterfanand all auxiliary fans.) -
[fan]– Special definition for the part cooling fan; responds toM106/M107.
(Only one instance possible, ideal for thepartfanchannel.)
The configuration in printer.cfg can be changed from something like:
## Part cooling fan
[output_pin partfan]
pin: MKS_THR:gpio2
pwm: True
cycle_time: 0.0100
hardware_pwm: false
value: 0
scale: 255
shutdown_value: 0to one of these variants:
## Part cooling fan (fan_generic variant)
[fan_generic partfan]
pin: MKS_THR:gpio2
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.200
off_below: 0.08
shutdown_speed: 0or:
## Part cooling fan (fan variant)
[fan]
pin: Toolhead:gpio2
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.200
off_below: 0.08
shutdown_speed: 0This can be done for the partfan, sidefan and filterfan depending on your use case.
The names in the macros must match the fan names (partfan, sidefan, filterfan, fan) in every case.
This gives you the cleanest Klipper API usage and full M106/M107 support for the partfan.
Make sure you have this in your printer.cfg:
[fan]
pin: Toolhead:gpio2
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.200
off_below: 0.08
shutdown_speed: 0.0
## Big side radial turbo fan
[fan_generic sidefan]
pin: PA8
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.250
off_below: 0.3
shutdown_speed: 0
## Activated charcoal blowing fan
[fan_generic filterfan]
pin: PC9
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.200
off_below: 0.3
shutdown_speed: 0Make sure you have this in your macros.cfg:
[gcode_macro M106]
rename_existing: M106.1
[gcode_macro M107]
rename_existing: M107.1
[gcode_macro M106]
gcode:
{% if params.P is defined %}
{% if params.S is defined %}
{% set speed = 0.003921*params.S|int %}
{% if (params.P|int) == 0 %}
M106.1 S{params.S|int}
{% elif (params.P|int) == 2 %}
SET_FAN_SPEED FAN=sidefan SPEED={speed}
{% elif (params.P|int) == 3 %}
SET_FAN_SPEED FAN=filterfan SPEED={speed}
{% else %}
SET_FAN_SPEED FAN=fan{params.P|int} SPEED={speed}
{% endif %}
{% else %}
{% if (params.P|int) == 0 %}
M106.1 S255
{% elif (params.P|int) == 2 %}
SET_FAN_SPEED FAN=sidefan SPEED=1
{% elif (params.P|int) == 3 %}
SET_FAN_SPEED FAN=filterfan SPEED=1
{% else %}
SET_FAN_SPEED FAN=fan{params.P|int} SPEED=1
{% endif %}
{% endif %}
{% endif %}
{% if params.T is defined %}
{% if (params.T|int) == -2 %}
{% if params.S is defined %}
{% set speed = 0.003921*params.S|int %}
SET_FAN_SPEED FAN=filterfan SPEED={speed}
{% else %}
SET_FAN_SPEED FAN=filterfan SPEED=1
{% endif %}
{% endif %}
{% endif %}
{% if params.P is undefined %}
{% if params.T is undefined %}
{% if params.S is defined %}
M106.1 S{params.S|int}
{% else %}
M106.1 S255
{% endif %}
{% endif %}
{% endif %}
[gcode_macro M107]
gcode:
M106.1 S0If you don't want to change anything or specifically need the hardware dependencies of output_pin, you can use the standard macro code.
Make sure you have this in your macros.cfg:
[gcode_macro M106]
gcode:
{% if params.P is defined %}
{% if params.S is defined %}
{% if (params.P|int) == 0 %}
SET_PIN PIN=partfan VALUE={params.S|int}
{% elif (params.P|int) == 2 %}
SET_PIN PIN=sidefan VALUE={params.S|int}
{% elif (params.P|int) == 3 %}
SET_PIN PIN=filterfan VALUE={params.S|int}
{% else %}
SET_PIN PIN=fan{params.P|int} VALUE={params.S|int}
{% endif %}
{% else %}
{% if (params.P|int) == 0 %}
SET_PIN PIN=partfan VALUE=255
{% elif (params.P|int) == 2 %}
SET_PIN PIN=sidefan VALUE=255
{% elif (params.P|int) == 3 %}
SET_PIN PIN=filterfan VALUE=255
{% else %}
SET_PIN PIN=fan{params.P|int} VALUE=255
{% endif %}
{% endif %}
{% endif %}
{% if params.T is defined %}
{% if (params.T|int) == -2 %}
{% if params.S is defined %}
SET_PIN PIN=filterfan VALUE={params.S|int}
{% else %}
SET_PIN PIN=filterfan VALUE=255
{% endif %}
{% endif %}
{% endif %}
{% if params.P is undefined %}
{% if params.T is undefined %}
{% if params.S is defined %}
SET_PIN PIN=partfan VALUE={params.S|int}
{% else %}
SET_PIN PIN=partfan VALUE=255
{% endif %}
{% endif %}
{% endif %}
[gcode_macro M107]
gcode:
SET_PIN PIN=partfan VALUE=0This variant is clean if you don't need M106 semantics for the partfan and want to control everything explicitly via SET_FAN_SPEED.
Make sure you have this in your printer.cfg:
## Part cooling fan
[fan_generic partfan]
pin: Toolhead:gpio2
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.200
off_below: 0.08
shutdown_speed: 0
## Big side radial turbo fan
[fan_generic sidefan]
pin: PA8
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.250
off_below: 0.3
shutdown_speed: 0
## Activated charcoal blowing fan
[fan_generic filterfan]
pin: PC9
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.200
off_below: 0.3
shutdown_speed: 0Make sure you have this in your macros.cfg:
[gcode_macro M106]
gcode:
{% if params.P is defined %}
{% if params.S is defined %}
{% set speed = 0.003921*params.S|int %}
{% if (params.P|int) == 0 %}
SET_FAN_SPEED FAN=partfan SPEED={speed}
{% elif (params.P|int) == 2 %}
SET_FAN_SPEED FAN=sidefan SPEED={speed}
{% elif (params.P|int) == 3 %}
SET_FAN_SPEED FAN=filterfan SPEED={speed}
{% else %}
SET_FAN_SPEED FAN=fan{params.P|int} SPEED={speed}
{% endif %}
{% else %}
{% if (params.P|int) == 0 %}
SET_FAN_SPEED FAN=partfan SPEED=1
{% elif (params.P|int) == 2 %}
SET_FAN_SPEED FAN=sidefan SPEED=1
{% elif (params.P|int) == 3 %}
SET_FAN_SPEED FAN=filterfan SPEED=1
{% else %}
SET_FAN_SPEED FAN=fan{params.P|int} SPEED=1
{% endif %}
{% endif %}
{% endif %}
{% if params.T is defined %}
{% if (params.T|int) == -2 %}
{% if params.S is defined %}
{% set speed = 0.003921*params.S|int %}
SET_FAN_SPEED FAN=filterfan SPEED={speed}
{% else %}
SET_FAN_SPEED FAN=filterfan SPEED=1
{% endif %}
{% endif %}
{% endif %}
{% if params.P is undefined %}
{% if params.T is undefined %}
{% if params.S is defined %}
{% set speed = 0.003921*params.S|int %}
SET_FAN_SPEED FAN=partfan SPEED={speed}
{% else %}
SET_FAN_SPEED FAN=partfan SPEED=1
{% endif %}
{% endif %}
{% endif %}
[gcode_macro M107]
gcode:
SET_FAN_SPEED FAN=partfan SPEED=0This hybrid approach uses the native [fan] definition for the part cooling fan while keeping other fans as output_pin.
Make sure you have this in your printer.cfg:
[fan]
pin: Toolhead:gpio2
max_power: 1.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.200
off_below: 0.08
shutdown_speed: 0.0Make sure you have this in your macros.cfg:
[gcode_macro M106]
rename_existing: M106.1
[gcode_macro M107]
rename_existing: M107.1
[gcode_macro M106]
gcode:
{% if params.P is defined %}
{% if params.S is defined %}
{% if (params.P|int) == 0 %}
M106.1 S{params.S|int}
{% elif (params.P|int) == 2 %}
SET_PIN PIN=sidefan VALUE={params.S|int}
{% elif (params.P|int) == 3 %}
SET_PIN PIN=filterfan VALUE={params.S|int}
{% else %}
SET_PIN PIN=fan{params.P|int} VALUE={params.S|int}
{% endif %}
{% else %}
{% if (params.P|int) == 0 %}
M106.1 S255
{% elif (params.P|int) == 2 %}
SET_PIN PIN=sidefan VALUE=255
{% elif (params.P|int) == 3 %}
SET_PIN PIN=filterfan VALUE=255
{% else %}
SET_PIN PIN=fan{params.P|int} VALUE=255
{% endif %}
{% endif %}
{% endif %}
{% if params.T is defined %}
{% if (params.T|int) == -2 %}
{% if params.S is defined %}
SET_PIN PIN=filterfan VALUE={params.S|int}
{% else %}
SET_PIN PIN=filterfan VALUE=255
{% endif %}
{% endif %}
{% endif %}
{% if params.P is undefined %}
{% if params.T is undefined %}
{% if params.S is defined %}
M106.1 S{params.S|int}
{% else %}
M106.1 S255
{% endif %}
{% endif %}
{% endif %}
[gcode_macro M107]
gcode:
M106.1 S0This page will be expanded with additional advanced configuration options as they become relevant for the FreeDi community.
If you have suggestions for topics to cover, feel free to open a discussion on GitHub.