Variables for heating to a temperature

I have been manually editing my start gcode macro every time I change filament to change the temperature. I know there is a way to automate this process but I have had trouble understanding how to use variable. I would like to know how to set up variables in the start macro and change those variables in Cura slicer using my existing filament profiles.

here is my existing start gcode:

      M190 S100 #heat bed

      G28 #home
      BED_MESH_CALIBRATE PROFILE="default" #auto bed level
      
      G0 X110 Y110 Z10
      G1 X0 Y0 Z10 F4000.0  #move to start position
   
     M109 S240 #heat nozzle

[gcode_macro START_PRINT]
gcode:
{% set BED_TEMP = params.BED_TEMP|default(60)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(200)|float %}
M190 S{BED_TEMP}
M109 S{EXTRUDER_TEMP}
G28 ;Home
BED_MESH_PROFILE LOAD=default
G92 E0 ;Reset Extruder
G1 Z2.0 F3000 ;Move Z Axis up
G1 X10.1 Y20 Z0.28 F5000.0 ;Move to start position
G1 X10.1 Y200.0 Z0.28 F1500.0 E15 ;Draw the first line
G1 X10.4 Y200.0 Z0.28 F5000.0 ;Move to side a little
G1 X10.4 Y20 Z0.28 F1500.0 E30 ;Draw the second line
G92 E0 ;Reset Extruder
G1 Z2.0 F3000 ;Move Z Axis up

CURA

Add this code
START_PRINT EXTRUDER_TEMP={first_layer_temperature[0]} BED_TEMP={first_layer_bed_temperature[0]}

1 Like

That is a task for the slicer

alright thanks, I am currently running a print but I will try this code after it finishes. This should save me a lot of time.

Ideally the slicer should be able to do it but I have my start gcode in Klipper, if I try to put the exact same gcode into the slicer I run into weird errors and can’t start a print.

Usually you have temperature values for your filaments in the slicer (the good ones :wink: ).

Like here in OrcsSlicer:

These values are passed on to the printer via the gcode file.

You don’t have to fiddle around in the printer.cfg for that.

And copying the start code from the slicer into Klipper is usually not a good idea. Changes have to be made.

And always keep in mind: Klipper macros can’t be interrupted/cancelled.

this worked to correctly set the temperature but the heater immediately turns off after reaching the correct temperature

Just slice a small model and upload the gcode file here.
And paste the PRINT_START macro as it is in your config and use Preformatted Text tags!

Same problem. the value of print temperature for filament in Cura 5.5.0 is not used. the temperature used is the temperature given in begining of printer.cfg for variable_defaultTempNozzle
So i must edit printer.cfg each time i change filament.
Any idea ?
Thanks in advance for any help

The answer is above. You need to configure your slicer correctly to make use of the custom macros you’re using.

start gcode:

# Use absolute coordinates 
      G90 

      # Reset extruder 
      G92 E0

    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
  {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(200)|float %}
  M190 S{BED_TEMP}
  
  G28 ;Home
  BED_MESH_CALIBRATE PROFILE="default"
  M109 S{EXTRUDER_TEMP}



    # Move Z axis up 
    G1 Z2.0 F3000 
    # Move to start position 
    G1 X10.1 Y20 Z0.28 F5000.0 
    # Draw the first line
    G1 X10.1 Y200.0 Z0.28 F1500.0 E15 
    # Move to the side
    G1 X10.4 Y200.0 Z0.28 F5000.0 
    # Draw the second line 
    G1 X10.4 Y20 Z0.28 F1500.0 E30 
    # Reset extruder 
    G92 E0
    G1 Z20

gcode file
cube.gcode (961.3 KB)