Skip to content

Instantly share code, notes, and snippets.

@JRHeaton
Last active June 1, 2022 20:38
Show Gist options
  • Save JRHeaton/196415feff91790c7f2ced3c758db5b2 to your computer and use it in GitHub Desktop.
Save JRHeaton/196415feff91790c7f2ced3c758db5b2 to your computer and use it in GitHub Desktop.
Ender 3 Pro 4.2.2
[skew_correction]
[display_status]
[pause_resume]
[respond]
[gcode_arcs]
[delayed_gcode clear_display]
gcode =
M117
[gcode_macro CANCEL_PRINT]
rename_existing = BASE_CANCEL_PRINT
gcode =
CLEAR_PAUSE
SDCARD_RESET_FILE
BASE_CANCEL_PRINT
SET_SKEW CLEAR=1
{% if params.KEEP_HEATING|default(true) == False %}
M117 Turning off heaters
TURN_OFF_HEATERS
{% endif %}
M107
M117 Moving bed forward
G1 Y{printer.toolhead.axis_maximum.y} F{printer.configfile.settings.stepper_y.homing_speed * 60}
UPDATE_DELAYED_GCODE ID=clear_display DURATION=10
[gcode_macro end_print]
gcode =
TURN_OFF_HEATERS
SET_SKEW CLEAR=1
M107 ; turn off fan
M117 Presenting print...
{% set x_homing_speed = printer.configfile.settings.stepper_x.homing_speed %}
{% set y_homing_speed = printer.configfile.settings.stepper_y.homing_speed %}
{% set xy_homing_speed = [x_homing_speed, y_homing_speed]|min %}
G1 Z{[printer.toolhead.axis_maximum.z - 5, printer.gcode_move.gcode_position.z + 20] | min} F{printer.configfile.settings.stepper_z.homing_speed * 60}
G1 X{printer.toolhead.axis_minimum.x} Y{printer.toolhead.axis_maximum.y} F{xy_homing_speed * 60}
M117 Print Done!
UPDATE_DELAYED_GCODE ID=clear_display DURATION=30
[gcode_macro PAUSE]
rename_existing = BASE_PAUSE
gcode =
{% set x = params.X|default(printer.toolhead.axis_minimum.x + 5) %}
{% set y = params.Y|default(printer.toolhead.axis_minimum.y + 5) %}
{% set z = params.Z|default(20)|float %}
{% set e = params.E|default(printer.firmware_retraction.retract_length) %}
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% set lift_z = z|abs %}
{% if act_z < (max_z - lift_z) %}
{% set z_safe = lift_z %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
SAVE_GCODE_STATE NAME=PAUSE_state
BASE_PAUSE
G91
M117 Retracting
G10
M117 Moving to safe Z position
G1 Z{z_safe}
G90
M117 Moving to XY park position
G1 X{x} Y{y} F{60 * 140}
UPDATE_DELAYED_GCODE ID=clear_display DURATION=10
[gcode_macro RESUME]
rename_existing = BASE_RESUME
gcode =
{% set e = params.E|default(printer.firmware_retraction.retract_length) %}
; TODO: Change to conditional use of firmware retraction g-codes
M117 Resuming...
G90
RESTORE_GCODE_STATE NAME=PAUSE_state MOVE=1
BASE_RESUME
UPDATE_DELAYED_GCODE ID=clear_display DURATION=10
[gcode_macro prime_nozzle]
gcode =
{% set vfr = params.VFR|default(8.0) %}
{% set line_length = params.LINE_LENGTH|default(190) %}
{% set nozzle_diameter = printer.configfile.settings.extruder.nozzle_diameter %}
{% set layer_height = nozzle_diameter * 0.75 %}
{% set cross_sectional_area = 3.14159*(printer.configfile.settings.extruder.filament_diameter / 2)**2 %}
{% set extrusion_width = nozzle_diameter * 1.4 %}
{% set line_sectional_area = extrusion_width * layer_height %}
{% set line_to_filament_ratio = line_sectional_area / cross_sectional_area %}
{% set volumetric_feed_rate = ((vfr * 60) / line_sectional_area)|int %}
SAVE_GCODE_STATE NAME=pre_prime_nozzle
G90
M83
G1 Z5
G1 X{10} Y{5} Z{layer_height} F{100 * 60}
G1 Y{5 + line_length} E{line_length * line_to_filament_ratio} F{volumetric_feed_rate}
G1 X6 F{60 * 60}
G1 Y15 E{(line_length - 10) * line_to_filament_ratio} F{volumetric_feed_rate}
G10
RESTORE_GCODE_STATE NAME=pre_prime_nozzle MOVE=0
[gcode_macro start_print]
gcode =
{% if 'BED_TEMP' is not in params or 'NOZZLE_TEMP' is not in params %}
CANCEL_PRINT
{ action_raise_error("You must specify both temps(BED_TEMP/NOZZLE_TEMP). Print cancelled") }
{% endif %}
{% set bed_temp = params.BED_TEMP|float %}
{% set nozzle_temp = params.NOZZLE_TEMP|float %}
{% set nozzle_preheat_factor = params.NOZZLE_PREHEAT_FACTOR|default(0.7)|float %}
{% set use_relative_extrusion = params.RELATIVE_EXTRUSION|default(false) %}
CLEAR_PAUSE
M107
G90
M83
M140 S{bed_temp}
{% set nozzle_preheat_temp = nozzle_temp * nozzle_preheat_factor %}
{% if printer.extruder.temperature < nozzle_preheat_temp %}
M104 S{nozzle_preheat_temp}
{% else %}
M104 S{nozzle_temp}
{% endif %}
M117 Heating bed and nozzle
{% if printer.toolhead.homed_axes|length < 3 %}
M117 Homing...
G28 ; home all axes
{% endif %}
{% set s = printer.configfile.settings %}
{% set x_homing_speed = s.stepper_x.homing_speed %}
{% set y_homing_speed = s.stepper_y.homing_speed %}
{% set xy_homing_speed = [x_homing_speed, y_homing_speed]|min %}
{% set z_homing_speed = s.stepper_z.homing_speed %}
{% set x_position_min = printer.toolhead.axis_minimum.x %}
{% set y_position_min = printer.toolhead.axis_minimum.y %}
M117 Moving to XY min
G1 X{x_position_min} Y{y_position_min} F{xy_homing_speed * 60}
G1 Z20 F{z_homing_speed * 60}
M117 Waiting for bed to stabilize
M190 S{bed_temp}
G1 Z3 F{z_homing_speed * 60}
M117 Waiting for nozzle to stabilize
M109 S{nozzle_temp}
M117 Priming nozzle...
PRIME_NOZZLE
{% if use_relative_extrusion %}
M83
{% else %}
M82
{% endif %}
G92 E0
M117 Starting print
UPDATE_DELAYED_GCODE ID=clear_display DURATION=10
[gcode_macro autotune_pids]
gcode =
{% set bed_temp = params.BED_TEMP|default(60)|int %}
{% set extruder_temp = params.EXTRUDER_TEMP|default(200)|int %}
{% set min_bed_temp = printer.configfile.settings.heater_bed.min_temp %}
{% set max_bed_temp = printer.configfile.settings.heater_bed.max_temp %}
{% set min_ext_temp = printer.configfile.settings.extruder.min_temp %}
{% set max_ext_temp = printer.configfile.settings.extruder.max_temp %}
{% if bed_temp < min_bed_temp or bed_temp > max_bed_temp %}
{ action_raise_error("bed_temp must be between %d and %d" % (min_bed_temp, max_bed_temp)) }
{% endif %}
{% if extruder_temp < min_ext_temp or extruder_temp > max_ext_temp %}
{ action_raise_error("extruder_temp must be between %d and %d" % (min_ext_temp, max_ext_temp)) }
{% endif %}
M117 Tuning bed...
PID_CALIBRATE heater=heater_bed target={bed_temp}
M117 Tuning extruder...
PID_CALIBRATE heater=extruder target={extruder_temp}
M117 Done!
UPDATE_DELAYED_GCODE ID=clear_display DURATION=15
[gcode_macro center_z_endstop_cal]
gcode =
G28
G1 X120 Y120 Z2 F{60 * 60}
Z_ENDSTOP_CALIBRATE
[gcode_macro filament_load]
gcode =
{% set load_length = 100 %}
SAVE_GCODE_STATE NAME=pre_load
M83
G1 E{load_length} F{4 * 60}
RESTORE_GCODE_STATE NAME=pre_load MOVE=0
[gcode_macro filament_unload]
gcode =
{% set push_length = 10 %}
{% set first_retract_length = 8 %}
{% set unload_retract_length = 100 %}
{% set retract_speed = 45 %}
{% set push_speed = 4 %}
SAVE_GCODE_STATE NAME=pre_unload
M83
G1 E{push_length} F{4 * 60}
G1 E-{first_retract_length} F{retract_speed * 60}
G4 P{5 * 1000}
G1 E-{unload_retract_length} F{retract_speed * 60}
RESTORE_GCODE_STATE NAME=pre_unload MOVE=0
[gcode_macro heat_soak]
gcode =
{% set temp = params.TEMP|default(65)|int %}
{% set heater = params.HEATER|default("heater_bed") %}
SET_HEATER_TEMPERATURE HEATER={heater} TARGET={temp}
TEMPERATURE_WAIT SENSOR={heater} MAXIMUM={temp}
G4 P{params.SECONDS|int * 1000}
[gcode_macro set_accel]
variable_decel_factor = 0.5
description = "Set acceleration and deceleration (by way of deceleration factor [0-1])"
gcode =
{% set decel_factor = params.DECEL_FACTOR|default(decel_factor)|float %}
{% if decel_factor < 0 or decel_factor > 1 %}
{ action_raise_error("DECEL_FACTOR must be between 0 and 1") }
{% endif %}
{% set accel = 0 %}
{% if 'ACCEL' in params %}
{% set accel = params.ACCEL %}
{% else %}
{% set accel = printer.toolhead.max_accel %}
{% endif %}
SET_GCODE_VARIABLE MACRO=set_accel VARIABLE=decel_factor VALUE={decel_factor}
SET_VELOCITY_LIMIT ACCEL={accel} ACCEL_TO_DECEL={accel|float * decel_factor}
[gcode_macro soak_and_probe]
gcode =
HEAT_SOAK {rawparams}
G28
BED_MESH_CALIBRATE
[gcode_macro M204]
rename_existing = M204.1
description = "Set maximum acceleration/deceleration. Use SET_ACCEL.decel_factor to control deceleration. Old G-Code: M204.1"
gcode =
{% if 'S' in params %}
SET_ACCEL ACCEL={params.S}
{% endif %}
[virtual_sdcard]
path = ~/gcode_files
[heater_bed]
heater_pin = BED_HEATER
sensor_pin = BED_SENSOR
sensor_type = EPCOS 100K B57560G104F
min_temp = 0
max_temp = 115
control = pid
pid_kp = 74.194
pid_ki = 1.459
pid_kd = 943.193
[extruder]
heater_pin = HEATER0
sensor_pin = TEMP_SENSOR0
nozzle_diameter = 0.4
filament_diameter = 1.75
step_pin = E0_STEP
dir_pin = E0_DIR
enable_pin = !STEP_EN
microsteps = 16
rotation_distance = 4.63
sensor_type = PT1000
min_temp = 0
max_temp = 300
min_extrude_temp = 0
max_extrude_only_distance = 500
max_extrude_only_velocity = 200
max_extrude_only_accel = 5000
pressure_advance = 0.054
pressure_advance_smooth_time = 0.030
control = pid
pid_kp = 25.855
pid_ki = 1.657
pid_kd = 100.836
[printer]
max_velocity = 800
max_accel = 7000
max_accel_to_decel = 7000
max_z_velocity = 16
max_z_accel = 300
kinematics = cartesian
[stepper_x]
homing_speed = 160
second_homing_speed = 30
position_endstop = 4
position_min = 4
position_max = 230
step_pin = X_STEP
dir_pin = X_DIR
enable_pin = !STEP_EN
endstop_pin = ^X_ENDSTOP_MIN
microsteps = 16
rotation_distance = 40
[stepper_y]
homing_speed = 160
second_homing_speed = 30
position_endstop = -14
position_min = -14
position_max = 220
step_pin = Y_STEP
dir_pin = Y_DIR
enable_pin = !STEP_EN
endstop_pin = ^Y_ENDSTOP_MIN
microsteps = 16
rotation_distance = 40
[stepper_z]
homing_speed = 16
second_homing_speed = 0.5
position_min = -8
position_max = 250
step_pin = Z_STEP
dir_pin = !Z_DIR
enable_pin = !STEP_EN
endstop_pin = ^Z_ENDSTOP_MIN
microsteps = 16
rotation_distance = 8
position_endstop = 0.402
[firmware_retraction]
retract_length = 0.5
retract_speed = 45
unretract_speed = 45
[fan]
pin = FAN1
[bed_screws]
screw1 = 32, 32
screw1_name = Front left screw
screw2 = 203, 203
screw2_name = Rear right screw
screw3 = 203, 32
screw3_name = Front right screw
screw4 = 32, 203
screw4_name = Rear left screw
probe_height = 0.10
speed = 200
probe_speed = 12
[board_pins Creality_v4.2.2]
aliases =
STEP_EN=PC3,
X_STEP=PC2, X_DIR=PB9,
Y_STEP=PB8, Y_DIR=PB7,
Z_STEP=PB6, Z_DIR=PB5,
E0_STEP=PB4, E0_DIR=PB3
aliases_heaters =
HEATER0=PA1, BED_HEATER=PA2
aliases_temp_sensors =
TEMP_SENSOR0=PC5,
BED_SENSOR=PC4
aliases_fans =
FAN1=PA0
aliases_endstops =
X_ENDSTOP_MIN=PA5,
Y_ENDSTOP_MIN=PA6,
Z_ENDSTOP_MIN=PA7
aliases_display =
LCD_CS=PB12, LCD_SCLK=PB13, LCD_SID=PB15,
LCD_ENCODER_PULSE0=PB14, LCD_ENCODER_PULSE1=PB10,
LCD_CLICK=PB2
aliases_probe =
PROBE_INPUT=PB1, PROBE_OUTPUT=PB0
aliases_exp1 =
EXP_1_9=null, EXP_1_10=null,
EXP_1_7=null, EXP_1_8=null,
EXP_1_5=null, EXP_1_6=null,
EXP_1_4=null, EXP_1_3=null,
EXP_1_1=null, EXP_1_2=null
aliases_exp2 =
EXP_2_9=null, EXP_2_10=null,
EXP_2_7=null, EXP_2_8=null,
EXP_2_5=null, EXP_2_6=null,
EXP_2_4=null, EXP_2_3=null,
EXP_2_1=null, EXP_2_2=<null
[temperature_sensor Creality_4.2.2_STM32F103]
sensor_type = temperature_mcu
[safe_z_home]
home_xy_position = 110, 110
speed = 60
z_hop = 6
z_hop_speed = 16
[display]
lcd_type = st7920
cs_pin = LCD_CS
sclk_pin = LCD_SCLK
sid_pin = LCD_SID
encoder_pins = ^LCD_ENCODER_PULSE0, ^LCD_ENCODER_PULSE1
click_pin = ^!LCD_CLICK
[menu __main __tune tune_accel]
type = list
name = "Acceleration"
[menu __main __tune tune_accel accel]
type = input
name = { "Accel: " + menu.input|string }
input = { printer.toolhead.max_accel }
input_min = 100
input_max = 50000
input_step = 50
realtime = False
gcode =
SET_ACCEL ACCEL={menu.input}
[menu __main __tune tune_accel decel_factor]
type = input
name = { "Decel Fact: " + menu.input|string }
input = { printer["gcode_macro set_accel"].decel_factor }
input_min = 0.1
input_max = 1
input_step = 0.05
realtime = False
gcode =
SET_GCODE_VARIABLE MACRO=set_accel VARIABLE=decel_factor VALUE={menu.input}
SET_ACCEL ACCEL={printer.toolhead.max_accel}
[menu __main __tune tune_accel decel]
type = input
name = { "Decel: " + menu.input|string }
input = { printer.toolhead.max_accel_to_decel }
input_min = 100
input_max = 50000
input_step = 50
realtime = False
gcode =
SET_VELOCITY_LIMIT ACCEL_TO_DECEL={menu.input}
[menu __main __tune tune_pressure_advance]
type = input
enable = True
name = { "Pres Adv: %.3f" % menu.input }
input = { printer.configfile.settings.extruder.pressure_advance }
input_min = 0
input_max = 1
input_step = 0.005
realtime = False
gcode =
SET_PRESSURE_ADVANCE ADVANCE={menu.input}
[menu __main __tune tune_retraction]
type = list
enable = { 'firmware_retraction' in printer }
name = "Retraction"
[menu __main __tune tune_retraction length]
type = input
name = { "Ret Len: " + menu.input|string }
input = { printer.firmware_retraction.retract_length }
input_min = 0
input_max = 10
input_step = 0.1
realtime = False
gcode =
SET_RETRACTION RETRACT_LENGTH={menu.input}
[menu __main __tune tune_retraction retract_speed]
type = input
name = { "Ret Spd: " + menu.input|string }
input = { printer.firmware_retraction.retract_speed }
input_min = 5
input_max = 80
input_step = 5
realtime = False
gcode =
SET_RETRACTION RETRACT_SPEED={menu.input}
[menu __main __tune tune_retraction unretract_speed]
type = input
name = { "Unret Spd: " + menu.input|string }
input = { printer.firmware_retraction.unretract_speed }
input_min = 5
input_max = 80
input_step = 5
realtime = False
gcode =
SET_RETRACTION UNRETRACT_SPEED={menu.input}
[menu __main __tune tune_retraction unretract_extra_length]
type = input
name = { "Unret Len+: " + menu.input|string }
input = { printer.firmware_retraction.unretract_extra_length }
input_min = 0
input_max = 2
input_step = 0.01
realtime = False
gcode =
SET_RETRACTION UNRETRACT_EXTRA_LENGTH={menu.input}
[force_move]
enable_force_move = True
[temperature_sensor pi]
sensor_type = temperature_host
[mcu]
#serial = /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4:1.0-port0
restart_method = command
[bed_mesh]
#mesh_min: 5, 5
#mesh_max: 195, 210
algorithm: bicubic
probe_count: 7
fade_end: 0.0
speed: 150
[bltouch]
#x_offset: -55
#y_offset: -10
sample_retract_dist: 3
speed: 12
lift_speed: 12
samples: 5
samples_tolerance: 0.01
samples_tolerance_retries: 25
stow_on_each_sample: False
probe_with_touch_mode: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment