Skip to content

Instantly share code, notes, and snippets.

@brandonmartinez
Last active March 13, 2025 05:09
Show Gist options
  • Save brandonmartinez/0d4e79a2bf3f607905d06738edf9515e to your computer and use it in GitHub Desktop.
Save brandonmartinez/0d4e79a2bf3f607905d06738edf9515e to your computer and use it in GitHub Desktop.
# Based on: https://github.com/Klipper3d/klipper/blob/master/config/printer-creality-ender3-s1plus-2022.cfg
# This file contains pin mappings for the stock 2022 Creality Ender 3
# S1 Plus. To use this config check the STM32 Chip on the Mainboard,
# during "make menuconfig" select accordingly either the
# STM32F103 with "28KiB bootloader" or the STM32F401 with
# "64KiB bootloader" and serial (on USART1 PA10/PA9) for both.
# For a direct serial connection, in "make menuconfig" select
# "Enable extra low-level configuration options" and Serial
# (on USART2 PA3/PA2), which is on the 10 pin IDC cable used
# for the LCD module as follows: 3: Tx, 4: Rx, 9: GND, 10: VCC
# Flash this firmware by copying "out/klipper.bin" to a SD card and
# turning on the printer with the card inserted. The filename
# must be changed to "firmware.bin"
# With STM32F401, you might need to put "firmware.bin" in a
# folder on the SD card called "STM32F4_UPDATE" in order to flash.
# See docs/Config_Reference.md for a description of parameters.
[stepper_x]
step_pin: PC2
dir_pin: PB9
enable_pin: !PC3
microsteps: 16
rotation_distance: 40
endstop_pin: !PA5
position_endstop: -10
position_max: 316
position_min: -15
homing_speed: 50
[stepper_y]
step_pin: PB8
dir_pin: PB7
enable_pin: !PC3
microsteps: 16
rotation_distance: 40
endstop_pin: !PA6
position_endstop: -10
position_max: 304
position_min: -15
homing_speed: 50
[stepper_z]
step_pin: PB6
dir_pin: !PB5
enable_pin: !PC3
microsteps: 16
rotation_distance: 8
endstop_pin: probe:z_virtual_endstop
position_max: 300
position_min: -4
[extruder]
step_pin: PB4
dir_pin: PB3
enable_pin: !PC3
microsteps: 16
gear_ratio: 42:12
rotation_distance: 26.359
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PA1
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC5
#control: pid
#pid_Kp: 23.561
#pid_Ki: 1.208
#pid_Kd: 114.859
min_temp: 0
max_temp: 260
max_extrude_only_distance: 100.0
[heater_bed]
heater_pin: PA7
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PC4
control: pid
pid_Kp: 71.867
pid_Ki: 1.536
pid_Kd: 840.843
min_temp: 0
max_temp: 110
[heater_fan hotend_fan]
pin: PC0
[fan]
pin: PA0
[mcu]
serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
#serial: platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0
restart_method: command
[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 2000
max_z_velocity: 5
max_z_accel: 100
# Be sure to review https://www.klipper3d.org/Bed_Level.html and adjust bltouch/x_offset, bltouch/y_offset
# I recommend doing a manual bed leveling (paper test) on a new machine, then run through the probe
# calibration found here: https://www.klipper3d.org/Probe_Calibrate.html
[bltouch]
sensor_pin: ^PC14
control_pin: PC13
x_offset: -31
y_offset: -41.9
#z_offset: 0
probe_with_touch_mode: true
stow_on_each_sample: false
# After that, you can run the bed mesh calibration found here: https://www.klipper3d.org/Bed_Mesh.html
# Remember, *ANY* changes to your bed invalidate the mesh, so you'll need to re-run the Z-Offset
# calibration again: https://www.klipper3d.org/Probe_Calibrate.html#calibrating-probe-z-offset
# Then re-run the bed mash calibration
[bed_mesh]
speed: 150
horizontal_move_z: 10
mesh_min: 20, 20
mesh_max: 265, 258
probe_count: 8, 8
algorithm: bicubic
[safe_z_home]
home_xy_position: 187, 192
speed: 75
z_hop: 10
z_hop_speed: 5
move_to_previous: true
[filament_switch_sensor e0_sensor]
switch_pin: !PC15
pause_on_runout: false
runout_gcode: PAUSE
runout_gcode:
M600
insert_gcode:
M117 Filament inserted
event_delay: 3.0
pause_delay: 0.0001
[pause_resume]
recover_velocity: 25
######################################################################
# Override M117 command with rawparams
######################################################################
# The macro below will override the default M117 command to echo the message.
#
# It uses the rawparams pseudo-variable that contains the full unparsed
# parameters that was passed to the M117 command.
#
# As this can include comments, we are trimming the text when a `;` or `#` is
# found, and escaping any existing `"`
[gcode_macro M117]
gcode:
{% if rawparams %}
{% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0]|replace('"', '\\"') %}
SET_DISPLAY_TEXT MSG="{escaped_msg}"
RESPOND TYPE=command MSG="{escaped_msg}"
{% else %}
SET_DISPLAY_TEXT
{% endif %}
# 'Marlin' style M808 compatibility macro for SDCard looping
[gcode_macro M808]
gcode:
{% if params.K is not defined and params.L is defined %}SDCARD_LOOP_BEGIN COUNT={params.L|int}{% endif %}
{% if params.K is not defined and params.L is not defined %}SDCARD_LOOP_END{% endif %}
{% if params.K is defined and params.L is not defined %}SDCARD_LOOP_DESIST{% endif %}
# Cancel object (aka Marlin/RRF M486 commands) support
#
# Enable object exclusion
[exclude_object]
[gcode_macro M486]
gcode:
# Parameters known to M486 are as follows:
# [C<flag>] Cancel the current object
# [P<index>] Cancel the object with the given index
# [S<index>] Set the index of the current object.
# If the object with the given index has been canceled, this will cause
# the firmware to skip to the next object. The value -1 is used to
# indicate something that isn’t an object and shouldn’t be skipped.
# [T<count>] Reset the state and set the number of objects
# [U<index>] Un-cancel the object with the given index. This command will be
# ignored if the object has already been skipped
{% if 'exclude_object' not in printer %}
{action_raise_error("[exclude_object] is not enabled")}
{% endif %}
{% if 'T' in params %}
EXCLUDE_OBJECT RESET=1
{% for i in range(params.T | int) %}
EXCLUDE_OBJECT_DEFINE NAME={i}
{% endfor %}
{% endif %}
{% if 'C' in params %}
EXCLUDE_OBJECT CURRENT=1
{% endif %}
{% if 'P' in params %}
EXCLUDE_OBJECT NAME={params.P}
{% endif %}
{% if 'S' in params %}
{% if params.S == '-1' %}
{% if printer.exclude_object.current_object %}
EXCLUDE_OBJECT_END NAME={printer.exclude_object.current_object}
{% endif %}
{% else %}
EXCLUDE_OBJECT_START NAME={params.S}
{% endif %}
{% endif %}
{% if 'U' in params %}
EXCLUDE_OBJECT RESET=1 NAME={params.U}
{% endif %}
# The Following Based on:
# https://github.com/Klipper3d/klipper/blob/master/config/sample-macros.cfg
# https://pastebin.com/Bsi0C03E
[gcode_macro START_PRINT]
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
{% set X_START = 10.0|default(10.0)|float %}
{% set Y_START = 20.0|default(20.0)|float %}
# 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 (low to prevent oozing) and bed to target for bed mesh
M104 S150 T0
M190 S{BED_TEMP}
# Home and Calibrate Bed Mesh
G28
BED_MESH_CALIBRATE
# Load Bed Mesh
# BED_MESH_PROFILE LOAD=default
# BED_MESH_OUTPUT PGP=1
# Home
# G28
# Move up to clean bed
G1 Y{Y_MAX - 20} Z{Z_MAX/4.0} F6000
# Heat nozzle and bed
M109 S{EXTRUDER_TEMP} T0
M190 S{BED_TEMP}
# Precondition extruder
G92 E0
# G1 X{X_START} Y{Y_START} Z{PRIMER_HEIGHT} F6000.0 ; Move to start position
# G1 X{X_MAX - 2 * X_START} Y{Y_START} Z{PRIMER_HEIGHT} F2000.0 E15; Draw the first line
# G1 X{X_MAX - 2 * X_START} Y{Y_START + PRIMER_WIDTH} Z{PRIMER_HEIGHT} ; Move to side a little
# G1 X{X_START} Y{Y_START + PRIMER_WIDTH} Z{PRIMER_HEIGHT} F2000.0 E30; Draw the second line
# G92 E0 ; Reset Extruder
G1 Z2.0 F600
G1 Z0.2 F600
G1 Z2.0 F600
[gcode_macro PRESENT_PRINT]
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 %}
# Present print
G90
G1 Z{printer.toolhead.position.z + 10} F600
G1 X{X_MAX / 2} Y{Y_MAX} F6000
M106 S0
M104 S0
M140 S0
[gcode_macro END_PRINT]
gcode:
# Fix-up extruder
G91
G1 E-2 F2700
G1 E-1.5 Z0.2 F2400
G1 X5 Y5 F6000
G1 Z10
PRESENT_PRINT
# Disable Steppers
M84 X Y E
[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
M220 S100 ; Reset Speed factor override percentage to default (100%)
M221 S100 ; Reset Extrude factor override percentage to default (100%)
G91 ; Set coordinates to relative
{% if printer.extruder.temperature >= 170 %}
G1 F1800 E-1 ; Retract filament 3 mm to prevent oozing
{% endif %}
PRESENT_PRINT
;set part fan speed to zero.
M106 S0
;bed and hotend are left at the print temps in case I want to restart.
CLEAR_PAUSE
BASE_CANCEL_PRINT
# The follow macros are for use with pause/resume and the filamnet switch sensor
# Based on: https://www.reddit.com/r/ender5plus/comments/kb5oe9/klipper_m600_filament_change/
# And: https://github.com/KevinOConnor/klipper/issues/1354
[gcode_macro PARK_MACRO]
gcode:
{% set X = params.X|default(0)|float %}
{% set Y = params.Y|default(0)|float %}
{% set Z = params.Z|default(30)|float %}
M117 PARKING...
G91
G1 E-3.14 F1500
G1 Z{Z}
G90
G1 X{X} Y{Y} F3000
[gcode_macro UNLOAD]
gcode:
G91
G1 E5.0 F1200
G1 E3.0 F1600
G1 E-13.14 F7000
G1 E-100 F3000 # This is a partial unload for the E5, but you need to adjust the default setting for max extrusion from 50
G90
[gcode_macro M600]
gcode:
PAUSE_MACRO
UNLOAD
[gcode_macro PAUSE_MACRO]
gcode:
PAUSE
PARK_MACRO
SET_IDLE_TIMEOUT TIMEOUT=7200
[gcode_macro PURGE]
gcode:
M117 PURGING...
G91
G1 E45.0 F250
G90
[gcode_macro LOAD_FILAMENT]
gcode:
M117 LOADING...
G91
G1 E25.0 F1000
G1 E100 F2500
G4 P900
G1 E45.0 F250
G90
[gcode_macro RESUME_MACRO]
gcode:
M117 RESUMING...
RESUME
#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [bltouch]
#*# z_offset = 3.310
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# 0.485000, 0.387500, 0.195000, 0.132500, 0.007500, -0.065000, -0.197500, -0.460000
#*# 0.257500, 0.202500, 0.077500, 0.052500, -0.047500, -0.032500, -0.077500, -0.290000
#*# 0.125000, 0.097500, 0.025000, 0.022500, -0.017500, 0.050000, 0.005000, -0.112500
#*# 0.002500, 0.017500, -0.012500, 0.020000, 0.020000, 0.105000, 0.132500, 0.080000
#*# -0.072500, -0.007500, -0.040000, 0.037500, 0.027500, 0.112500, 0.180000, 0.150000
#*# -0.232500, -0.137500, -0.085000, 0.040000, 0.110000, 0.267500, 0.370000, 0.375000
#*# -0.312500, -0.150000, -0.070000, 0.157500, 0.242500, 0.437500, 0.545000, 0.652500
#*# -0.392500, -0.162500, -0.005000, 0.252500, 0.432500, 0.690000, 0.875000, 1.010000
#*# tension = 0.2
#*# min_x = 20.0
#*# algo = bicubic
#*# y_count = 8
#*# mesh_y_pps = 2
#*# min_y = 20.0
#*# x_count = 8
#*# max_y = 258.0
#*# mesh_x_pps = 2
#*# max_x = 265.0
#*#
#*# [extruder]
#*# control = pid
#*# pid_kp = 19.184
#*# pid_ki = 1.007
#*# pid_kd = 91.365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment