Help with Macros please

Basic Information:

Printer Model: TEVO Tornado
MCU / Printerboard: MKS GEN L V2.1
Host / SBC - RPI
klippy.log - attached
klippy.zip (1.5 MB)

Describe your issue:

Starting from scratch on this printer, I have it printing properly, but I think I messed up my macros. I was taking suggestions from too many different places and I think I really messed things up.

Here’s my rundown.
Tevo Tornado - Printer specs in the config are good (feel free to take a look and suggest if you see something out of the ordinary)

Using a Filament sensor (switch style)
Klipperscreen
Slicer - Simplify3d
(Let me know if there are other specifics needed)

Here’s my printer.cfg. Please review my macros, let me know what needs to be fixed, removed, added.

I totally confused myself and now I can’t make heads or tails of what I need and how to format for my setup.

I really appreciate this! I have been struggling for days trying to make sense of everything.

[include mainsail.cfg]
[include timelapse.cfg]
[include macros/*.cfg]
[include s2dw.cfg]

[mcu]
serial: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
restart_method: command

[virtual_sdcard]
path: ~/printer_data/gcodes

[display_status]

[idle_timeout]
timeout: 1800
gcode:
    M140 S0  ; Turn off bed heater
    M104 S0  ; Turn off extruder heater

[pause_resume]

[gcode_macro START_PRINT]
description: Start print macro
gcode:
    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
    {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(215)|float %}
    M117 "Let's do this!" ; Printer LCD
    M118 "Heating up... keep it hot" ; KlipperScreen
    G90
    # Reset the G-Code Z offset (adjust Z offset if needed)
    SET_GCODE_OFFSET Z=0.0
    # Home the printer
    G28
    # Wait for bed to reach temperature
    M190 S{BED_TEMP}
    # Set and wait for nozzle to reach temperature
    M109 S{EXTRUDER_TEMP}
    BED_MESH_PROFILE LOAD=default
    G1 Z5 F3000
    G4 S5
    G1 Z0.15 F300
    G1 Z2.0 F3000
    G1 X5 Y20 Z0.3 F5000.0
    G1 X5 Y200 Z0.3 F1500.0 E7.5  ; Adjusted extrusion
    G1 X5.4 Y200 Z0.3 F5000.0
    G1 X5.4 Y20 Z0.3 F1500.0 E15  ; Adjusted extrusion
    G92 E0

[gcode_macro END_PRINT] ### MODIFIED ###
description: End print macro
gcode:
    M140 S0  ; Turn off bed heater
    M104 S0  ; Turn off extruder heater
    M106 S0  ; Turn off fan
     G91
    G1 Z10 F3000  ; Raise Z axis by 10mm
    G90
    G1 X0 Y200 F3000  ; Move to park position
    M84  ; Disable all steppers

[gcode_macro PRINT_END] ### MODIFIED ###
description: End print macro
gcode:
    M140 S0  ; Turn off bed heater
    M104 S0  ; Turn off extruder heater
    M106 S0  ; Turn off fan
    G91
    G1 Z10 F3000  ; Raise Z axis by 10mm
    G90
    G1 X0 Y200 F3000  ; Move to park position
    M84  ; Disable all steppers
 
[gcode_macro CANCEL_PRINT] ### NEW/EDITED ###
description: Cancel print with themed shutdown
gcode:
    TURN_OFF_HEATERS
    G91  ; Switch to relative positioning
    G1 Z10 F300  ; Lift Z to safe height
    G90  ; Return to absolute positioning
    G1 X0 Y200 F3000  ; Park the printhead
    M84  ; Disable all steppers
 
[pause_resume]

[filament_switch_sensor Filament_Runout] ### NEW/EDITED ###
switch_pin: ^!PD0  ; D21 on the MKS Gen L v2.1 board
pause_on_runout: true
    
[gcode_macro PAUSE]
rename_existing: BASE_PAUSE
gcode:
    # Parameters
    {% set z = params.Z|default(10)|int %}                                                   ; z hop amount

    {% if printer['pause_resume'].is_paused|int == 0 %}
        SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=zhop VALUE={z}                              ; set z hop variable for reference in resume macro
        SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=etemp VALUE={printer['extruder'].target}    ; set hotend temp variable for reference in resume macro

        SET_FILAMENT_SENSOR SENSOR=filament_Runout ENABLE=0                                  ; disable filament sensor
        SAVE_GCODE_STATE NAME=PAUSE                                                          ; save current print position for resume
        BASE_PAUSE                                                                           ; pause print
        {% if (printer.gcode_move.position.z + z) < printer.toolhead.axis_maximum.z %}       ; check that zhop doesn't exceed z max
            G91                                                                              ; relative positioning
            G1 Z{z} F900                                                                     ; raise Z up by z hop amount
        {% else %}
            { action_respond_info("Pause zhop exceeds maximum Z height.") }                  ; if z max is exceeded, show message and set zhop value for resume to 0
            SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=zhop VALUE=0
        {% endif %}
        G90                                                                                  ; absolute positioning
        G1 X{printer.toolhead.axis_maximum.x/2} Y{printer.toolhead.axis_minimum.y+5} F6000   ; park toolhead at front center
        SAVE_GCODE_STATE NAME=PAUSEPARK                                                      ; save parked position in case toolhead is moved during the pause (otherwise the return zhop can error)
        M104 S{etemp}                                                                            ;
        SET_IDLE_TIMEOUT TIMEOUT=86400                                                       ; set timeout to many hours
    {% endif %}

[gcode_macro RESUME]
rename_existing: BASE_RESUME
variable_zhop: 0
variable_etemp: 0
gcode:
    # Parameters
    {% set e = params.E|default(2.5)|int %}                                          ; hotend prime amount (in mm)

    {% if printer['pause_resume'].is_paused|int == 1 %}
        SET_FILAMENT_SENSOR SENSOR=filament_runout ENABLE=1                          ; enable filament sensor
        #INITIAL_RGB                                                                    ; reset LCD color
        SET_IDLE_TIMEOUT TIMEOUT={printer.configfile.settings.idle_timeout.timeout}  ; set timeout back to configured value
        {% if etemp > 0 %}
            M109 S{etemp|int}                                                        ; wait for hotend to heat back up
        {% endif %}
        RESTORE_GCODE_STATE NAME=PAUSEPARK MOVE=1 MOVE_SPEED=100                     ; go back to parked position in case toolhead was moved during pause (otherwise the return zhop can error)
        G91                                                                          ; relative positioning
        M83                                                                          ; relative extruder positioning
        {% if printer[printer.toolhead.extruder].temperature >= printer.configfile.settings.extruder.min_extrude_temp %}
            G1 Z{zhop * -1} E{e} F900                                                ; prime nozzle by E, lower Z back down
        {% else %}
            G1 Z{zhop * -1} F900                                                     ; lower Z back down without priming (just in case we are testing the macro with cold hotend)
        {% endif %}
        RESTORE_GCODE_STATE NAME=PAUSE MOVE=1 MOVE_SPEED=60                          ; restore position
        BASE_RESUME                                                                  ; resume print
    {% endif %}

[gcode_macro CANCEL_PRINT]
rename_existing: BASE_CANCEL_PRINT
gcode:
    SET_IDLE_TIMEOUT TIMEOUT={printer.configfile.settings.idle_timeout.timeout} ; set timeout back to configured value
    CLEAR_PAUSE
    SDCARD_RESET_FILE
    PRINT_END
    BASE_CANCEL_PRINT

[gcode_macro M600]
gcode:
    #LCDRGB R=0 G=1 B=0  ; Turn LCD green
    PAUSE                ; Pause

[gcode_macro M109]
rename_existing: M99109
gcode:
    # Parameters
    {% set s = params.S|default(0)|float %}
    
    M104 S{s}  ; Set hotend temp
    {% if s != 0 %}
        TEMPERATURE_WAIT SENSOR=extruder MINIMUM={s} MAXIMUM={s+1}  ; Wait for hotend temp (within 1 degree)
    {% endif %}


[gcode_macro M190]
rename_existing: M99190
gcode:
    # Parameters
    {% set s = params.S|default(0)|float %}

    M140 S{s}  ; Set bed temp
    {% if s != 0 %}
        TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={s} MAXIMUM={s+1}  ; Wait for bed temp (within 1 degree)
    {% endif %}


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

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

[stepper_z]
step_pin: PL3
dir_pin: PL1
enable_pin: !PK0
microsteps: 16
rotation_distance: 8
endstop_pin: probe:z_virtual_endstop
position_max: 500
homing_speed: 10
position_min: -5

[extruder]
step_pin: PA4
dir_pin: PA6
enable_pin: !PA2
rotation_distance: 6.74
microsteps: 16
nozzle_diameter: 0.400
filament_diameter: 1.750
heater_pin: PB4
sensor_type: ATC Semitec 104GT-2
sensor_pin: PK5
pressure_advance: 0.128
#control: pid
#pid_Kp: 22.2
#pid_Ki: 1.08
#pid_Kd: 114
min_extrude_temp: 150
min_temp: 0
max_temp: 265
max_extrude_only_distance: 101
max_extrude_cross_section: 20

########################################
# TMC UART configuration
########################################

[tmc2208 stepper_z]
uart_pin: PK3
# tx_pin aka the pin with the 1K resistor
tx_pin: PL7
run_current: 0.60
stealthchop_threshold: 0

#[tmc2208 extruder]
#uart_pin: PK4        # Replace with the correct UART pin for your board
#tx_pin: PL5          # Replace with the correct TX pin for your board
#interpolate: True
#run_current: 0.8     # Adjust according to your motor's rated current
#hold_current: 0.5   # Uncomment and adjust if needed
#sense_resistor: 0.110
#stealthchop_threshold: 0  # Set to 0 to disable StealthChop and use SpreadCycle

[heater_bed]
heater_pin: PH5
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK6
#control: pid
#pid_Kp: 690.34
#pid_Ki: 111.47
#pid_Kd: 1068.83
min_temp: 0
max_temp: 140

[printer]
kinematics: cartesian
max_velocity: 400
max_accel: 2000
max_z_velocity: 5
max_z_accel: 100
square_corner_velocity: 5.0

[input_shaper]
#shaper_type_x = mzv
#shaper_freq_x = 78.8
#shaper_type_y = 2hump_ei
#shaper_freq_y = 45.6

[bltouch]
sensor_pin: ^PD2
control_pin: PB5
stow_on_each_sample: True
probe_with_touch_mode: false
x_offset: 43
y_offset: 0
speed: 10
samples: 3
sample_retract_dist: 3
samples_result: median
samples_tolerance: 0.150
samples_tolerance_retries: 3
pin_up_touch_mode_reports_triggered: False

[bed_mesh]
speed: 100
horizontal_move_z: 3
mesh_min: 43, 5  
mesh_max: 222, 260
probe_count: 7, 7
fade_start: 0.1
fade_end: 5.0
mesh_pps: 3, 3
algorithm: bicubic
bicubic_tension: 0.15

[safe_z_home]
home_xy_position: 130, 130
speed: 80.0
z_hop: 10.0 
z_hop_speed: 5.0

[heater_fan hotend_fan]
pin: PH4
max_power: 1.0
fan_speed: 1
kick_start_time: 0
heater: extruder
heater_temp: 50.0

[fan]
pin: PH6

[gcode_macro G29]
gcode:
  G28
  PROBE_CALIBRATE
  bed_mesh_calibrate
  G1 X0 Y0 Z10 F4200

[board_pins]
aliases:
    # EXP1 header
    EXP1_1=PC0, EXP1_3=PH0, EXP1_5=PA1, EXP1_7=PA5, EXP1_9=<GND>,
    EXP1_2=PC2, EXP1_4=PH1, EXP1_6=PA3, EXP1_8=PA7, EXP1_10=<5V>,
    # EXP2 header
    EXP2_1=PB3, EXP2_3=PC6, EXP2_5=PC4, EXP2_7=PL0,  EXP2_9=<GND>,
    EXP2_2=PB1, EXP2_4=PB0, EXP2_6=PB2, EXP2_8=PG0, EXP2_10=<NC>
    # Pins EXP2_1, EXP2_6, EXP2_2 are also MISO, MOSI, SCK of bus "ssp1"
# See the MKS Lcd Config path file for definitions of common LCD displays.

[display]
lcd_type: st7920
cs_pin: EXP1_4
sclk_pin: EXP1_5
sid_pin: EXP1_3
encoder_pins: ^EXP2_5, ^EXP2_3
click_pin: ^!EXP1_2

[output_pin beeper]
pin: EXP1_1
value: 0
shutdown_value: 0

[gcode_macro BEEP]
gcode:
    # Parameters
    {% set i = params.I|default(1)|int %}        ; Iterations (number of times to beep).
    {% set dur = params.DUR|default(100)|int %}  ; Duration/wait of each beep in ms. Default 100ms.

    {% for iteration in range(i|int) %}
        SET_PIN PIN=beeper VALUE=1
        G4 P{dur}
        SET_PIN PIN=beeper VALUE=0
		G4 P{dur}
    {% endfor %}

[gcode_arcs]

[axis_twist_compensation]
calibrate_start_x: 43
calibrate_end_x: 222
calibrate_y: 130

[shaketune]
result_folder: ~/printer_data/config/ShakeTune_results
number_of_results_to_keep: 3
keep_raw_csv: False
show_macros_in_webui: True
timeout: 300

#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
#*# [extruder]
#*# control = pid
#*# pid_kp = 21.713
#*# pid_ki = 1.088
#*# pid_kd = 108.293
#*#
#*# [heater_bed]
#*# control = pid
#*# pid_kp = 56.647
#*# pid_ki = 0.926
#*# pid_kd = 866.700
#*#
#*# [bltouch]
#*# z_offset = 0.700
#*#
#*# [input_shaper]
#*# shaper_type_x = 3hump_ei
#*# shaper_freq_x = 52.4
#*# shaper_type_y = 2hump_ei
#*# shaper_freq_y = 39.0
#*#
#*# [axis_twist_compensation]
#*# z_compensations = -0.003333, -0.000833, 0.004167
#*# compensation_start_x = 43.0
#*# compensation_end_x = 222.0
#*#
#*# [bed_mesh default]
#*# version = 1
#*# points =
#*# 	  -0.917034, -0.673701, -0.460368, -0.249534, -0.061201, 0.197597, 0.384263
#*# 	  -0.972034, -0.708701, -0.495368, -0.259534, -0.038701, 0.197597, 0.391763
#*# 	  -0.972034, -0.708701, -0.497868, -0.292034, -0.051201, 0.147597, 0.354263
#*# 	  -1.024534, -0.778701, -0.527868, -0.332034, -0.093701, 0.160097, 0.354263
#*# 	  -1.132034, -0.881201, -0.600368, -0.397034, -0.151201, 0.110097, 0.299263
#*# 	  -1.197034, -0.928701, -0.702868, -0.469534, -0.223701, 0.042597, 0.274263
#*# 	  -1.287034, -1.008701, -0.680368, -0.419534, -0.221201, 0.005097, 0.229263
#*# x_count = 7
#*# y_count = 7
#*# mesh_x_pps = 3
#*# mesh_y_pps = 3
#*# algo = bicubic
#*# tension = 0.15
#*# min_x = 43.0
#*# max_x = 221.98
#*# min_y = 5.0
#*# max_y = 260.0

One short questiion?

What’s the deal with always deleting this section?

Fill out above information and in all cases attach your klippy.log file (use zip to compress it, if too big). Pasting your printer.cfg is not needed
Be sure to check our “Knowledge Base” Category first. Most relevant items, e.g. error messages, are covered there

1 Like

sorry about that. New to all of this and just learning the cadence. I’ll know for next time.

It’s ok. Just wanted to say that the printer.cfg usually appears in the klippy.log.

So, the config looks legit.

Some errors explain themself.

gcode.CommandError: Must home axis first: 134.220 111.780 26.510 [24016.562]

Maybe you tried to move the printhead before homing (G28).

There are some macros that include the M84 command.

This turns off all motors and Klipper is in an undefined state and has to be homed again.

You may need it in END_PRINT and CANCEL_PRINT but it is questionable if it’s use is required in the other macros.

what sent me down the rabbit hole was a 16 hour print that ran out of filament.

The run-out sensor did it’s thing, however, when I went to reload the filament and resume the print, Klipper wouldn’t resume till I re-homed.

Well, there was no way I could re-home because my print was on the bed right where Z would home.

I have been racking my brain trying to figure it out.

Then as I was reading, I saw how others changed their macros “for the better” and now I am completely messed up.

So, I think I need to start from scratch and re-do all the macros properly.

Just trying to figure out what a “proper” macro is and which ones do I actually need.

D

Actually this one killed your print:

[filament_switch_sensor Filament_Runout]
switch_pin = ^!PD0
pause_on_runout = true
runout_gcode = 
	M600       # <- Calls M600
	M117 "Refuel needed"
	M118 "We're out, give me more!"
insert_gcode = 
	M117 "Rearmed"
	M118 "Back to it, you machine"
event_delay = 3.0
pause_delay = 0.5
[gcode_macro M600]
description = Filament change macro
gcode = 
	SET_IDLE_TIMEOUT TIMEOUT=7200
	M117 "Cap needs new ammo!"
	M118 "Hold tight... swapping the goods"
	PAUSE_NOHOME   # <--- Calls PAUSE_NOHOME
	G91
	G1 Z10 F300
	G90
	M117 "Reloading..."
	M118 "Put that thing in, nice and slow."
	PAUSE
	M117 "Good to go!"
	M118 "Locked and loaded, baby. Back to work."
	RESUME_NOHOME
[gcode_macro PAUSE_NOHOME]
description = Custom pause macro that avoids re-homing
gcode = 
	SET_IDLE_TIMEOUT TIMEOUT=7200
	M117 "Taking a break, Cap"
	M118 "Pause detected... let's see where this goes"
	PAUSE_BASE
	G91
	G1 Z10 F300
	G90
	M117 "Paused, waiting"
	M118 "I'm just waiting... think dirty thoughts"
	M84      #   <---- Turns off the motors and messes it up.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.