# QIDI Plus4 V1.0.0

[include plr.cfg]
[include gcode_macro.cfg]
[include time_update.cfg]

# Plugins
[include timelapse.cfg]
[include KAMP_Settings.cfg]
[include box.cfg]

[mcu]
serial: /dev/ttyS2
restart_method: command
baud:500000

[mcu U_1]
serial: /dev/ttyS0
restart_method: command
baud:500000

[temperature_sensor GD32]
sensor_type: temperature_mcu
sensor_mcu: mcu

[respond]
default_type: echo

[save_variables] 
filename =/home/mks/printer_data/config/saved_variables.cfg

[resonance_tester]
accel_per_hz: 150
max_smoothing:0.5

[duplicate_pin_override]
pins:

[bed_screws]
screw1:25,21
screw1_name: Front left
screw2: 285,21
screw2_name: Front right
screw3: 285,281
screw3_name: Last right
screw4: 25,281

#[screws_tilt_adjust]
#screw_thread: CW-M4

[hall_filament_width_sensor]
adc1: PA2
adc2: PA3
cal_dia1: 1.50
cal_dia2: 2.0
raw_dia1: 14197
raw_dia2: 15058
default_nominal_filament_diameter: 1.75
max_difference: 0
measurement_delay: 50
enable: false
measurement_interval: 10
logging: False
min_diameter: 0.3
use_current_dia_while_delay: False
pause_on_runout:True
runout_gcode:
            RESET_FILAMENT_WIDTH_SENSOR
            M118 Filament run out
            {% set can_auto_reload = printer.save_variables.variables.auto_reload_detect|default(0) %}
            {% if can_auto_reload == 1 %}
              AUTO_RELOAD_FILAMENT
            {% endif %}
event_delay: 3.0
pause_delay: 0.5

[extruder]
step_pin:PB9
dir_pin:PB8
enable_pin:!PC15
rotation_distance: 53.7  #22.6789511 Bondtech 5mm Drive Gears
gear_ratio: 1517:170
microsteps: 16
full_steps_per_rotation: 200 #200 for 1.8 degree, 400 for 0.9 degree
nozzle_diameter: 0.400
filament_diameter: 1.75
min_temp: 0
max_temp: 380
min_extrude_temp: 175
smooth_time: 0.000001
heater_pin:PB3
sensor_type:MAX6675
sensor_pin:PB12
spi_speed: 100000
spi_software_sclk_pin:PB13
spi_software_mosi_pin:PA11
spi_software_miso_pin:PB14
max_power: 1

control : pid  
pid_Kp=33.555
pid_Ki=4.76
pid_Kd=59.141

pressure_advance: 0.032
pressure_advance_smooth_time: 0.03
max_extrude_cross_section:500
instantaneous_corner_velocity: 10.000
max_extrude_only_distance: 1000.0
max_extrude_only_velocity:5000
max_extrude_only_accel:5000
step_pulse_duration:0.000002

[tmc2209 extruder]
uart_pin:PC13
interpolate: True
run_current: 0.714
stealthchop_threshold: 0

[adxl345]
cs_pin:PA4
spi_software_sclk_pin:PA5
spi_software_mosi_pin:PA7
spi_software_miso_pin:PA6
axes_map: -x, z, -y

[printer]
kinematics:corexy
max_velocity: 600
max_accel: 20000
max_accel_to_decel: 10000
max_z_velocity: 20
max_z_accel: 500
square_corner_velocity: 8

[stepper_x]
step_pin:U_1:PB4
dir_pin:!U_1:PB3
enable_pin:!U_1:PB5
microsteps:32
rotation_distance: 38.82
full_steps_per_rotation:200 # set to 400 for 0.9 degree stepper
endstop_pin:tmc2240_stepper_x:virtual_endstop
position_min: -1.5
position_endstop: -1.5
position_max:307
homing_speed:50
homing_retract_dist:0
homing_positive_dir:False
step_pulse_duration:0.0000001

[stepper_y]
step_pin:U_1:PC14
dir_pin:!U_1:PC13
enable_pin:!U_1:PC15
microsteps: 32
rotation_distance: 38.82
full_steps_per_rotation:200 # set to 400 for 0.9 degree stepper
endstop_pin:tmc2240_stepper_y:virtual_endstop
position_min: -2
position_endstop: -2
position_max:325
homing_speed:50
homing_retract_dist:0
homing_positive_dir:False
step_pulse_duration:0.0000001

[stepper_z]
step_pin:U_1:PB1
dir_pin:U_1:PB6
enable_pin:!U_1:PB0
microsteps: 128
rotation_distance: 4
full_steps_per_rotation: 200
endstop_pin:probe:z_virtual_endstop # U_1:PC3 for Z-max
endstop_pin_reverse:tmc2209_stepper_z:virtual_endstop
position_endstop:1
position_endstop_reverse:285
position_max:285
position_min: -4
homing_speed: 10
homing_speed_reverse: 10
second_homing_speed: 5
homing_retract_dist: 5.0
homing_positive_dir:false
homing_positive_dir_reverse:true
#step_pulse_duration:0.0000001

[stepper_z1]
step_pin:U_1:PC10
dir_pin:U_1:PA15
enable_pin:!U_1:PC11
microsteps: 128
rotation_distance: 4
full_steps_per_rotation: 200
endstop_pin_reverse:tmc2209_stepper_z1:virtual_endstop
#step_pulse_duration:0.0000001

[z_tilt]
z_positions:
    -17.5,138.5
    335.7,138.5

points:
    0,138.5
    255,138.5

speed: 150
horizontal_move_z: 5
retries: 2
retry_tolerance: 0.05

[tmc2240 stepper_y]
cs_pin:U_1:PB9
spi_software_sclk_pin:U_1:PA5
spi_software_mosi_pin:U_1:PA7
spi_software_miso_pin:U_1:PA6
spi_speed:200000
run_current: 1.07
#hold_current: 0.5
interpolate:true
stealthchop_threshold:0
diag0_pin:!U_1:PC0
driver_SGT:1

[tmc2240 stepper_x]
cs_pin:U_1:PD2
spi_software_sclk_pin:U_1:PA5
spi_software_mosi_pin:U_1:PA7
spi_software_miso_pin:U_1:PA6
spi_speed:200000
run_current: 1.07
# hold_current: 0.5
interpolate:true
stealthchop_threshold:0
diag0_pin:!U_1:PB8
driver_SGT:1

[tmc2209 stepper_z]
uart_pin:U_1: PB7
run_current: 1.07
# hold_current: 0.17
interpolate: True
stealthchop_threshold: 9999999999
diag_pin:^U_1:PA13
driver_SGTHRS:100

[tmc2209 stepper_z1]
uart_pin:U_1: PC5
run_current: 1.07
# hold_current: 0.17
interpolate: True
stealthchop_threshold: 9999999999
diag_pin:^U_1:PC12
driver_SGTHRS:100

[heater_bed]
heater_pin: U_1:PB10
sensor_type:NTC 100K MGB18-104F39050L32
sensor_pin:U_1: PA0
max_power: 1.0
control = pid
pid_Kp=63.418 
pid_Ki=1.342 
pid_Kd=749.125
pwm_cycle_time:0.001
min_temp: -60
max_temp: 125

[heater_generic chamber]
heater_pin:U_1:PC8
max_power:0.4
sensor_type:NTC 100K MGB18-104F39050L32
sensor_pin:U_1:PA1

control = pid
pid_Kp=63.418 
pid_Ki=1.342 
pid_Kd=749.125

min_temp:-100
max_temp:70
target_min_temp:45
target_max_temp:65
heat_with_heater_bed:True
heat_with_heater_bed_tem_add:25

[verify_heater chamber]
max_error: 400
check_gain_time:600
hysteresis: 5
heating_gain: 2
position_z: 270

[temperature_sensor Chamber_Thermal_Protection_Sensor]
sensor_type:NTC 100K MGB18-104F39050L32
sensor_pin:U_1:PC2
min_temp:-100
max_temp:140

[verify_heater extruder]
max_error: 120
check_gain_time:20
hysteresis: 5
heating_gain: 1

[verify_heater heater_bed]
max_error: 200
check_gain_time:60
hysteresis: 10
heating_gain: 1

[fan_generic auxiliary_cooling_fan]
pin: U_1:PA8
shutdown_speed: 0.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.100
off_below: 0.0

[fan_generic chamber_circulation_fan]
pin: U_1:PC9
shutdown_speed: 0.0
cycle_time: 0.0100
hardware_pwm: false
kick_start_time: 0.100
off_below: 0.0

[chamber_fan chamber_fan]
pin:U_1:PA4
max_power: 1.0
shutdown_speed: 0
kick_start_time: 0.5
heater:chamber
fan_speed: 1.0
off_below: 0
idle_timeout:60
idle_speed:1.0

[heater_fan hotend_fan]
pin:PB5
max_power: 1.0
shutdown_speed:1.0
kick_start_time: 0.5
heater: extruder
heater_temp: 50.0
fan_speed: 1.0
off_below: 0

[heater_fan hotend_fan2]
pin:PB4
max_power: 1.0
shutdown_speed:1.0
kick_start_time: 0.5
heater: extruder
heater_temp: 50.0
fan_speed: 1.0
off_below: 0

[heater_fan hotend_fan3]
pin:PB10
max_power: 1.0
shutdown_speed:1.0
kick_start_time: 0.5
heater: extruder
heater_temp: 50.0
fan_speed: 1.0
off_below: 0

[fan_generic cooling_fan]
pin:PA8
max_power: 1.0
shutdown_speed:0
cycle_time: 0.010
hardware_pwm: False
kick_start_time: 0.100
off_below: 0.0
tachometer_pin:PA9
tachometer_ppr: 2
tachometer_poll_interval: 0.0015

[controller_fan board_fan]
pin:U_1:PC4
max_power:1.0
shutdown_speed:1.0
cycle_time:0.01
fan_speed: 1.0
heater:chamber
stepper:stepper_x,stepper_y

[output_pin caselight]
pin: U_1:PC7
pwm: false
shutdown_value:1
value:1

[output_pin beeper]
pin:U_1: PA2
pwm: false
shutdown_value:0
value:0

[output_pin ctlyd]
pin:U_1: PA14
pwm: false
shutdown_value:0
value:0

[smart_effector]
pin:U_1:PC1
recovery_time:0
x_offset: 25
y_offset: 1.3
z_offset: 0.000001
speed:5
lift_speed:5
probe_accel:50
samples: 2
samples_result: submaxmin
sample_retract_dist: 5
samples_tolerance: 0.05
samples_tolerance_retries:5

[qdprobe]
pin:!PA10
z_offset:0.000001

[bed_mesh]
speed:150
horizontal_move_z:5
mesh_min:25,10
mesh_max:295,295
probe_count:9,9
algorithm:bicubic
bicubic_tension:0.4
mesh_pps: 2,2

[filament_switch_sensor fila]
pause_on_runout: True
runout_gcode:
    M118 Filament tangle detected
event_delay: 3.0
pause_delay: 0.5
switch_pin:U_1:PC3

[resonance_tester]
accel_chip:adxl345
probe_points:
   150, 150, 10

[idle_timeout]
timeout: 43200
gcode:
    PRINT_END

[pause_resume]

[display_status]

[gcode_macro_break]

[virtual_sdcard]
path: ~/printer_data/gcodes
on_error_gcode:CANCEL_PRINT
    
[print_stats]

[force_move]
enable_force_move : True

#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [input_shaper]
#*# shaper_type_x = mzv
#*# shaper_freq_x = 48.2
#*# shaper_type_y = zv
#*# shaper_freq_y = 38.0
