Creality Ender-3 Pro Custom with Creality 2.2 Silent Board + second Z motor and BLtouch

thanks to jamonterrell

# This file contains pin mappings for a customized Creality Ender 3 Pro.
# This config uses a Creality v2.2 Silent Board with second Z-motor and BLtouch.
# The heatbreak cooling fan is connected to the pins for the second extruder
# and starts automatically when the nozzle heats up and is powered off when the
# nozzle-temp is below 40°C.

# NOTE the BLtouch z offset is set to 0.0 to avoid any errors! please measure your
# z offset before use and update the config with your value.

# Aditionally added PRINT_START and PRINT_END macros to use with slicers
# just add these instead of start and end GCODE.

# To use this config, the firmware should be compiled for the AVR
# atmega2560.

# See docs/Config_Reference.md for a description of parameters.

[stepper_x]
step_pin: PF0
dir_pin: PF1
enable_pin: !PD7
microsteps: 16
rotation_distance: 40
endstop_pin: ^PE5
position_endstop: 0
position_max: 235
homing_speed: 100

[stepper_y]
step_pin: PF6
dir_pin: PF7
enable_pin: !PF2
microsteps: 16
rotation_distance: 40
endstop_pin: ^PJ1
position_endstop: 0
position_max: 235
homing_speed: 100

[stepper_z]
step_pin: PL3
dir_pin: PL1
enable_pin: !PK0
microsteps: 16
rotation_distance: 8 # silent board 2.2: 4
endstop_pin: probe:z_virtual_endstop
position_max: 250
position_min: 0
homing_speed: 10.0

[extruder]
#max_extrude_only_distance: 100.0 # ender3pro.cfg
step_pin: PA4
dir_pin: PA6
enable_pin: !PA2
microsteps: 16
rotation_distance: 34.406
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK5
control: pid
pid_Kp: 21.527
pid_Ki: 1.063
pid_Kd: 108.982
min_temp: 0
max_temp: 250

[safe_z_home]
home_xy_position: 160, 124
speed: 100
z_hop: 10
z_hop_speed: 10
move_to_previous: True

[bltouch]
sensor_pin: ^PD3
control_pin: PB5
x_offset: -42
y_offset: -6.3
z_offset: 0.0
speed: 3.0
pin_up_touch_mode_reports_triggered: False

[bed_mesh]
speed: 100
horizontal_move_z: 8
mesh_min: 25, 25
mesh_max: 190, 203
probe_count: 3, 3

[heater_bed]
heater_pin: PH5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK6
control: pid
pid_Kp: 54.027
pid_Ki: 0.770
pid_Kd: 948.182
min_temp: 0
max_temp: 130

[fan]
pin: PH6



[heater_fan heatbreak_cooling_fan]
pin: PH4
max_power: 1.0
shutdown_speed: 0.0
off_below: 0.3
heater: extruder
heater_temp: 40.0
fan_speed: 1.0

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

#[filament_switch_sensor filament_sensor] # not available
#switch_pin:PE4

[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

#[display]
#lcd_type: st7920
#cs_pin: PB12
#sclk_pin: PB13
#sid_pin: PB15
#encoder_pins: ^PB14, ^PB10
#click_pin: ^!PB2

[gcode_macro PRINT_START]
gcode:
    #Get Printer built volume dimensions
    {% set X_MAX = printer.toolhead.axis_maximum.x|default(100)|float %}
    {% set Y_MAX = printer.toolhead.axis_maximum.y|default(100)|float %}
    {% set Z_MAX = printer.toolhead.axis_maximum.z|default(100)|float %}
    #Get Nozzle diameter and filament width for conditioning
    {% set NOZZLE = printer.extruder.nozzle_diameter|default(0.4)|float %}
    {% set FILADIA = printer.extruder.filament_diameter|default(1.75)|float %}

    #Set Start coordinates of priming lines (enable / disable for your chosen bed)
    #{% set X_START = 25.0|default(10.0)|float %} # for glass-bed with clamps
    #{% set Y_START = 35.0|default(20.0)|float %} # for glass-bed with clamps
    {% set X_START = 10.0|default(10.0)|float %} # for regular magnetic bed
    {% set Y_START = 15.0|default(20.0)|float %} # for regular magnetic bed

    #Calculate Primer line extrusion volume and filament length
    {% set PRIMER_WIDTH = 0.75 * NOZZLE %}                    
    {% set PRIMER_HEIGHT = 0.70 * NOZZLE %}           
    {% set PRIMER_SECT = PRIMER_WIDTH * PRIMER_HEIGHT %}    
    {% set PRIMER_VOL = PRIMER_SECT * (X_MAX - 3 * X_START) %}    
    {% set FILA_SECT = 3.1415 * ( FILADIA / 2.0)**2 %}          
    {% set FILA_LENGTH = 1.55 * PRIMER_VOL / FILA_SECT %}      

    #Get Bed and Extruder temperature from Slicer GCode
    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
    {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(190)|float %}
    #Preheat nozzle and bed
    M104 S{EXTRUDER_TEMP} T0                        
    M140 S{BED_TEMP}                                

    #Home
    #G28

    #Move up to clean bed
    G1 Y{Y_MAX - 25} Z{Z_MAX/4.0} F6000                

    #Heat nozzle and bed
    M190 S{BED_TEMP}                               
    M109 S{EXTRUDER_TEMP} T0                       

    #Precondition extruder
    G92 E0     
    G1 X{X_START} Y{Y_START} Z{PRIMER_HEIGHT} F6000.0     
    G1 X{X_MAX - 2 * X_START} Y{Y_START} Z{PRIMER_HEIGHT} E{FILA_LENGTH} F2000.0 
    G1 X{X_MAX - 2 * X_START} Y{Y_START + PRIMER_WIDTH} Z{PRIMER_HEIGHT} E{FILA_LENGTH}
    G1 X{X_START} Y{Y_START + PRIMER_WIDTH} Z{PRIMER_HEIGHT} E{FILA_LENGTH} F2000.0 
    G92 E0            
    G1 Z10.0 F600        
    G1 Z0.2 F600        
    G1 Z10.0 F600
    
[gcode_macro PRINT_END]
gcode:
    G91 # Relative Move
    G1 E-2 Z0.2 F2400 # Retract and Raise
    M104 S0 T0 # Nozzle Temp 0
    M140 S0 # Bed Temp 0
    M400
    G1 Z30
    M400
    G90 # Absolute Move
    G0 X0
    M400
    G0 Y220
    
[gcode_macro G29]
gcode: 
  G28
  BED_MESH_CALIBRATE
  BED_MESH_PROFILE SAVE=p1
  G1 X0 Y0 Z5 F4000

Have fun!
Dan