#####################################################################################
# SKR v1.3 Configuration for Ender 3
# X,Y and Z are TMC2208 in UART Mode. 
# E is an TMC2209
# BLTouch
# klipper v0.9.1-139-ga5ebe582
# mainsail v0.3.0
#####################################################################################

[printer]
kinematics: cartesian
max_velocity: 400 #300
max_accel: 2500 #2000
max_z_velocity: 50
max_z_accel: 150

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

[tmc2208 stepper_x]
uart_pin: P1.17
interpolate: True
run_current: 0.65
hold_current: 0.5
stealthchop_threshold: 600
driver_PWM_AUTOGRAD: True
driver_PWM_AUTOSCALE: True
driver_HEND: 3
driver_HSTRT: 0

[stepper_x]
step_pin: P2.2
dir_pin: !P2.6
enable_pin: !P2.1
rotation_distance: 40
microsteps: 16
# step_distance: .0125
endstop_pin: P1.29
position_endstop: 0
position_min: 0
position_max: 235
homing_speed: 50

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

[tmc2208 stepper_y]
uart_pin: P1.15
interpolate: True
run_current: 0.65
hold_current: 0.5
stealthchop_threshold: 600
driver_PWM_AUTOGRAD: True
driver_PWM_AUTOSCALE: True
driver_HEND: 3
driver_HSTRT: 0

[stepper_y]
step_pin: P0.19
dir_pin: !P0.20
enable_pin: !P2.8
rotation_distance: 40
microsteps: 16
# step_distance: .0125
endstop_pin: P1.27
position_endstop: -9 #0
position_min: -10
position_max: 235
homing_speed: 50

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

[tmc2208 stepper_z]
uart_pin: P1.10
interpolate: True
run_current: 0.65
hold_current: 0.5
stealthchop_threshold: 200
driver_PWM_AUTOGRAD: True
driver_PWM_AUTOSCALE: True
driver_HEND: 3
driver_HSTRT: 0

[stepper_z]
step_pin: P0.22
dir_pin: P2.11
enable_pin: !P0.21
rotation_distance: 8
microsteps: 16
# step_distance: .0025
endstop_pin: P1.25
endstop_pin: probe:z_virtual_endstop
#position_endstop: 0
position_min: -1
position_max: 250
homing_retract_dist: 10 # to fix bltouch clone error

#####################################################################################
[tmc2209 extruder]
uart_pin: P1.8
interpolate: False
hold_current: 0.3
run_current: 0.5
stealthchop_threshold: 250
#driver_PWM_AUTOGRAD: True
#driver_PWM_AUTOSCALE: True
#driver_HEND: 3
#driver_HSTRT: 0
[thermistor 104NT-4-R025H42G]
temperature1:25
resistance1:100000
beta: 4267

[extruder]
step_pin: P2.13
dir_pin: !P0.11
enable_pin: !P2.12
#0.00926 stock extruder #0.002409 7.18450
rotation_distance: 3.59225
microsteps: 16
# step_distance: 0.002245188 
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: P2.7
sensor_type: 104NT-4-R025H42G #EPCOS 100K B57560G104F
sensor_pin: P0.24
#control: pid
#pid_Kp: 22.2
#pid_Ki: 1.08
#pid_Kd: 114
min_temp: 0
max_temp: 290
#pressure_advance: 0.05
#max_extrude_only_velocity: 120
#max_extrude_only_accel: 1000


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

[heater_bed]
heater_pin: P2.5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: P0.23
control: pid
pid_Kp: 54.027
pid_Ki: 0.770
pid_Kd: 948.182
min_temp: 0
max_temp: 130

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

[fan]
pin: P2.3

[heater_fan noozle_fan]
heater: extruder
shutdown_speed: 0
cycle_time: 0.010
#hardware_pwm: True
kick_start_time: 0.100
heater_temp: 50
fan_speed: 1.0
pin: P2.4

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

[bltouch]
sensor_pin: P1.25
control_pin: P2.0
#pin_move_time: 0.8
#pin_up_reports_not_triggered: True
#pin_up_touch_mode_reports_triggered: False
x_offset: 11.684 #-60
y_offset: 40.199 #-13
z_offset:  2.9 #2.9
samples: 2
#speed: 3

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

[homing_override]
set_position_z: 10
axes: z
gcode:
    G90
    G1 Z20 F600
    G28 X0 Y0 F3000
    G1 X110 Y130 F3000 # G1 X117 Y117 F3000
    G28 Z0
    G1 Z20 F500
    BED_MESH_PROFILE Load=new

[gcode_macro bedcal]
gcode:
    M140 S60
    M190 S60
    G28
    BED_MESH_CALIBRATE
    M140 S0
    BED_MESH_PROFILE SAVE=new
    SAVE_CONFIG

[gcode_macro pidex]
gcode:
    PID_CALIBRATE HEATER=extruder TARGET=210
    SAVE_CONFIG

[gcode_macro PAUSE]
rename_existing: BASE_PAUSE
default_parameter_X: 230    #edit to your park position
default_parameter_Y: 230    #edit to your park position
default_parameter_Z: 10     #edit to your park position
default_parameter_E: 1      #edit to your retract length
gcode:
    SAVE_GCODE_STATE NAME=PAUSE_state
    BASE_PAUSE
    G91
    G1 E-{E} F2100
    G1 Z{Z}
    G90
    G1 X{X} Y{Y} F6000

[gcode_macro RESUME]
rename_existing: BASE_RESUME
default_parameter_E: 1      #edit to your retract length
gcode:
    G91
    G1 E{E} F2100
    G90
    RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
    BASE_RESUME

[pause_resume]

[display_status]

[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
    TURN_OFF_HEATERS
    CLEAR_PAUSE
    SDCARD_RESET_FILE
    BASE_CANCEL_PRINT

[bed_mesh]
speed: 100
horizontal_move_z: 10
mesh_min: 20,95
mesh_max: 225,230
probe_count: 4,4
split_delta_z: 0.025
move_check_distance: 10.0
mesh_pps: 2,2
algorithm: bicubic

[virtual_sdcard]
path = ~/sdcard

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

[mcu]
serial: /dev/serial/by-id/usb-Klipper_lpc1768_09A0FF10031436AF84F46A5BC72000F5-if00

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

#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# 	  -0.177500, -0.145000, 0.010000, -0.015000
#*# 	  -0.122500, -0.120000, 0.015000, -0.035000
#*# 	  -0.082500, -0.055000, 0.053750, -0.037500
#*# 	  -0.027500, -0.018750, 0.065000, 0.010000
#*# tension = 0.2
#*# min_x = 19.994
#*# algo = bicubic
#*# y_count = 4
#*# mesh_y_pps = 2
#*# min_y = 94.999
#*# x_count = 4
#*# max_y = 229.999
#*# mesh_x_pps = 2
#*# max_x = 224.984
#*#
#*# [bed_mesh new]
#*# version = 1
#*# points =
#*# 	  -0.177500, -0.145000, 0.010000, -0.015000
#*# 	  -0.122500, -0.120000, 0.015000, -0.035000
#*# 	  -0.082500, -0.055000, 0.053750, -0.037500
#*# 	  -0.027500, -0.018750, 0.065000, 0.010000
#*# tension = 0.2
#*# min_x = 19.994
#*# algo = bicubic
#*# y_count = 4
#*# mesh_y_pps = 2
#*# min_y = 94.999
#*# x_count = 4
#*# max_y = 229.999
#*# mesh_x_pps = 2
#*# max_x = 224.984
#*#
#*# [extruder]
#*# control = pid
#*# pid_kp = 21.448
#*# pid_ki = 0.953
#*# pid_kd = 120.647
