Customizing Ultimaker Cura g-code

Ultimaker Cura offers some limited customization of g-code using placeholders. There is no way of comparing values or altering flow of the code. Each line is run from top through bottom.

Start G-Code

The default g-code that ships with the Prusa profiles for Ultimaker Cura works just fine, but I found myself wanting to tweak a few things to my liking. I have updated my startup g-code to incorporate several functions that I want to use on every print.

  • A 2-step “no ooze” nozzle warmup routine to expedite startup, but avoid dots and strings caused by molten filament dripping out during the mesh bed leveling and bed warmup processes.

  • Position the nozzle away from the PEI print surface during warmup and startup motion to avoid damaging the print surface.

  • PINDA warmup to ensure a consistent 35C PINA temperature before performing mesh bed leveling to ensure consistent results.

  • A modified prime line print routine to catch errant nozzle ooze, test extrusion and perform a final wipe action to avoid stringing between the prime line and start of the print.

Note

These notes are based on my experiences with the Prusa i3 Mk3 and Artillery/Evnovo Sidewinder X1 printers. If you are using a different printer, please verify the hardware details are same. These pages may be a bit rough as I revise them and add new material. Please check back regularly for updates.

I’ve incorporated these features into my own customized g-code settings for Ultimaker Cura.

Caution

Please be sure that you’ve calibrated your printer, and particularly your Live-Z settings before using any of the following examples. These routines move the nozzle around close to the bed, and could cause damage if your printer is not adjusted properly.

I’m not a fan of loud peizo beeps, much less music, but I have inserted several chirp sounds (M300 S100 P10) to indicate progress throughout the print.

Here’s a line-by-line breakdown:

Version control

The first lines are simple date, firmware and hardware settings checks.

  • Line 3 does a firmware version check. If you print generated gcode on a printer running an older firmware version, you’ll get a warning message to update. You can press the front knob to continue and ignore this warning, but updating to recent firmware is always recommended to take full advantage of enhanced features that Prusa is continually adding to the printer firmware and PrusaSlicer.

Listing 21 Ultimaker Cura start g-code version control
1
2
3
; Last updated 20200216
M300 S40 P10 ; chirp
M115 U3.7.2 ; tell printer latest fw version

Initialize movement and extrusion coordinates

The next stanza sets the initial movement and extrusion coordinates. These aren’t technically required, but if they’re improperly set, they can cause problems with a print.

  • Line 6 sets absolute move coordinates for movement.

  • Line 7 sets relative extruder coordinates for printing the prime line.

Listing 22 Ultimaker Cura movement and extrusion coordinates
4
5
6
7
M117 Initializing
G21 ; set units to millimeters
G90 ; use absolute move coordinates
M83 ; use relative extrusion mode for prime line

Initialization

The next block resets printing parameters that can persist after an aborted job.

  • Line 9 disables volumetric e (autospeed) printing.

  • Line 10 resets the print speed to 100% in case it was changed using the front knob.

  • Line 11 adjusts the extrusion rate (M221) to 90% for layer heights over 0.32mm. I find this necessary using large nozzles with very high layers.

Listing 23 Ultimaker Cura initialization
 8
 9
10
11
; Reset speed and extrusion rates
M200 D0 ; disable volumetric e
M220 S100 ; reset speed
M221 S100 ; reset extrusion multiplier

Set Mk3 hardware parameters

Prusa has added printer hardware parameters recently, but I like to specifically set these values to match the Mk3 hardware. This section may be obsolete.

  • Line 13 sets maximum accelerations (M201)

  • Lne 14 sets maximum feedrates (speeds M203)

  • Line 15 sets acceleration for the extruder (M204)

  • Line 16 sets hardware jerk limits (M205)

  • Line 17 sets minimum extruding and travel feed rates (M205)

Listing 24 Ultimaker Cura set Mk3 hardware parameters
12
13
14
15
16
17
; Set hardware parameters
M201 X1500 Y1500 Z1000 E5000 ; sets maximum accelerations, mm/sec^2
M203 X200 Y200 Z12 E120 ; sets maximum feedrates, mm/sec
M204 P1500 R1250 T1500 ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2
M205 X10.00 Y10.00 Z0.40 E1.50 ; sets the jerk limits, mm/sec
M205 S0 T0 ; sets the minimum extruding and travel feed rate, mm/sec

Initialize warmup temperatures

The next block sets initial “two step” extruder warmup temperatures to avoid oozing during mesh bed leveling.

  • Line 20 sets the extruder (nozzle) temperature to 160C (S160), a good “no ooze” temp that will soften most filament, but not hot enough to cause filament to trickle out of the nozzle. This will prevent dots of filament and stringing during mesh bed leveling.

  • Line 21 sets the bed temperature to the higher of the specified bed temperature or 80C. This is to ensure that the bed is hot enough to warm up the PINDA even on cold days.

Note

I recently increased this to 80C due to cold weather. See the PINDA warmup notes for details.

  • Line 23 waits for the nozzle to hit the no-ooze temp before proceeding. This ensures any filament stuck to the nozzle will be soft enough to bend if it hits the PEI print surface.

Listing 25 Ultimaker Cura start g-code initial warmup temps
18
19
20
21
22
23
24
; Set initial warmup temps
M117 Nozzle preheat
M104 S160 ; set extruder no-ooze temp
M140 S80  ; set bed PINDA warmup temp high enough for cold days
; Nozzle warmup before home to avoid driving hardened ooze into PEI surface
M109 S160 ; wait for extruder no-ooze warmup temp before mesh bed leveling, cool hot PINDA
M300 S40 P10 ; chirp

Initial homing

The next stanza prepares for initial homing. On startup, the printer has no way of knowing where the extruder is in 3D space, so homing is necessary for it to establish a known position. This is to ensure that any filament hanging from the nozzle is sufficiently soft to either break off or bend when the nozzle is lowered in the next line. This avoids creating dents in the PEI sheet at the lower-left corner.

  • Line 27 performs homing, moving the printer to the lowest (Z 0) left (X 0) front (Y 210) coordinates to establish the current position.

Listing 26 Ultimaker Cura start g-code initial homing
25
26
27
; Home
M117 Homing
G28 W ; home all without mesh bed level

PINDA warmup

The next stanza waits for the PINDA probe to reach a consistent temperature before automatic mesh bed leveling. For more info on the PINDA warmup procedure, refer to the about PINDA warmup notes.

  • Line 29 raises the nozzle 3mm to avoid possibly damaging the PEI sheet during nozzle movement in the steps that follow.

  • Line 30 moves the nozzle to the center (X 125) rear (Y 180) to allow access to the bed for final inspection and cleaning while waiting for the PINDA warmup in the following steps.

  • Line 31 lowers the nozzle and PINDA probe close to the bed (Z 0.15mm) to aid in warming up the PINDA probe.

  • Line 34 issues to command to wait for the PINDA probe to reach at least 35C, an all-around good temperature for mesh bed leveling. Note that this can take a long time (5-10 minutes) on the first print on a cold day. For subsequent prints, it should warm up much more quickly.

  • Line 35 sets the final bed temperature for the print. This is done here to allow the bed to start cooling to the final print temperature as mesh bed leveling is completed.

  • Line 36 raises the nozzle 3mm (Z3) for movement as a precaution before rapid moves close to the print surface.

Listing 27 Ultimaker Cura start g-code PINDA warmup
28
29
30
31
32
33
34
35
36
37
; Present bed for cleaning in PINDA warmup position
G0 Z3; Raise nozzle before move
G0 X125 Y180 F10200; Move nozzle to PINDA warming position
G0 Z0.15 F10200; Lower nozzle to PINDA warming position
; Wait for PINDA warmup
M117 PINDA warmup
M860 S35 ; wait for PINDA temp to stabilize
M140 S{material_bed_temperature_layer_0} ; set bed final temp
G0 Z3; Raise nozzle before move
M300 S40 P10 ; chirp

Mesh bed leveling and final warmup

Now that the PINDA is warmed up to a consistent temperature, we can perform mesh bed leveling.

  • Line 40 performs the actual leveling (G80). With the latest firmware releases, this will do either 3X3 or 7X7 grid leveling as configured in the printer setup menu. After leveling, the nozzle will return to the home position.

  • Line 41 stores the leveling results for use with the Octoprint Prusa mesh bed leveling plugin.

  • Line 45 raises the nozzle 5mm (Z5) while we wait for the nozzle to come up to full print temperature. This both avoids possibly damaging the PEI sheet under the nozzle, and also provides a clean prime line in the steps that follow.

  • Line 46 sets the final bed temperature to the user-specified temperature specified in the slicer settings. (Redundant with line 31 - to be removed)

  • Lines 47 and 48 set (M104) and wait for (M109) the final nozzle print temperatures specified in the slicer settings.

  • Line 49 waits for the bed temperature to settle before printing.

Listing 28 Ultimaker Cura start g-code mesh bed leveling & final warmup
38
39
40
41
42
43
44
45
46
47
48
49
50
; Mesh bed leveling
M117 Mesh bed leveling
G80 ; mesh bed leveling
M117 Saving results
G81 ; save mesh leveling results
; Final warmup routine
M117 Final warmup
G0 Z5; Raise nozzle to avoid denting bed while nozzle heats
M140 S{material_bed_temperature_layer_0} ; set bed final temp
M104 S{material_print_temperature_layer_0} ; set extruder final temp
M109 S{material_print_temperature_layer_0} ; wait for extruder final temp
M190 S{material_bed_temperature_layer_0} ; wait for bed final temp
M300 S40 P10 ; chirp

Prime line

Once the hotend comes up to temp, a custom prime line will be printed. I’ve made some tweaks to the bog-standard line.

  • Line 53 lowers the nozzle (Z0.15) to initial printing position.

  • Line 54 disables Linear Advance (M900 K0) for printing the prime line. With LA enabled, I often get distracting extruder clicks and skips when printing the initial thick line.

  • Line 56 moves to the initial prime line position at the left (X=0) front (Y=-3) bed position.

  • Line 57 extrudes an intial 2mm “blort” of filament without moving (G1 E2 with no X or Y movement) to trap any ooze or string remaing on the nozzle.

  • Line 58 extrudes 6mm of filament (E6) while moving 20mm along the X axis (X20.0).

  • Line 59 extrudes 3.2mm of filament (E3.2) while moving another 40mm along the X axis (X60).

  • Line 60 extrudes 6mm of filament (E6) while moving another 40mm along the X axis (X100).

  • Line 61 retracts 0.8mm of filament (E-0.8) to reduce stringing.

  • Line 62 performs a wipe action back over the printed line along the X axis (X99.5) without extruding (E0).

  • Line 63 moves another 10mm along the X axis (X110.0) without extruding (E0) to complete the wiping action and eliminate any stringing.

  • Line 64 de-retracts (pushes) 0.6mm of filament (E0.6) to re-prime after the previous retraction.

Listing 29 Ultimaker Cura start g-code prime line
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
; Prime line routine
M117 Printing prime line
G0 Z0.15 ; Restore nozzle position - (thanks tim.m30)
M900 K0; Disable Linear Advance for prime line
G92 E0.0 ; reset extrusion distance
G1 Y-3.0 F1000.0 ; go outside print area
G1 E2 F1000 ; de-retract and push ooze
G1 X20.0 E6  F1000.0 ; fat 20mm intro line @ 0.30
G1 X60.0 E3.2  F1000.0 ; thin +40mm intro line @ 0.08
G1 X100.0 E6  F1000.0 ; fat +40mm intro line @ 0.15
G1 E-0.8 F3000; retract to avoid stringing
G1 X99.5 E0 F1000.0 ; -0.5mm wipe action to avoid string
G1 X110.0 E0 F1000.0 ; +10mm intro line @ 0.00
G1 E0.6 F1500; de-retract
G92 E0.0 ; reset extrusion distance

Final print adjustments

Finally, we do any last minute print adjustments.Adjust for your printer.

  • Line 69 sets absolute extrusion mode for the print. This is the default setting for Ultimaker Cura. This line is necessary to set the printer back to absolute mode to match the Ultimaker Cura defaults after setting it to relative mode for the prime line routine.

  • Line 70 resets retraction acceleration (M204) (not needed, to be removed)

  • Line 71 sets the Linear Advance value for the current filament as set by the LA plugin.

  • Line 72 sets the Linear Advance print parameters.

Listing 30 Ultimaker Cura start g-code final print adjustments
66
67
68
69
70
71
72
73
; Final print adjustments
M117 Preparing to print
M300 S40 P10 ; chirp
M82 ; use absolute extrusion mode for print
M204 R1250 ; sets retract acceleration (R), mm/sec^2
M900 K{material_linear_advance_factor}
M900 W{line_width} H{layer_height} D{material_diameter}
M117 Print in progress

At this point, the print will proceed normally.

Full startup g-code example

Here’s the full start g-code:

Listing 31 Ultimaker Cura start g-code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
; Last updated 20200216
M300 S40 P10 ; chirp
M115 U3.7.2 ; tell printer latest fw version
M117 Initializing
G21 ; set units to millimeters
G90 ; use absolute move coordinates
M83 ; use relative extrusion mode for prime line
; Reset speed and extrusion rates
M200 D0 ; disable volumetric e
M220 S100 ; reset speed
M221 S100 ; reset extrusion multiplier
; Set hardware parameters
M201 X1500 Y1500 Z1000 E5000 ; sets maximum accelerations, mm/sec^2
M203 X200 Y200 Z12 E120 ; sets maximum feedrates, mm/sec
M204 P1500 R1250 T1500 ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2
M205 X10.00 Y10.00 Z0.40 E1.50 ; sets the jerk limits, mm/sec
M205 S0 T0 ; sets the minimum extruding and travel feed rate, mm/sec
; Set initial warmup temps
M117 Nozzle preheat
M104 S160 ; set extruder no-ooze temp
M140 S80  ; set bed PINDA warmup temp high enough for cold days
; Nozzle warmup before home to avoid driving hardened ooze into PEI surface
M109 S160 ; wait for extruder no-ooze warmup temp before mesh bed leveling, cool hot PINDA
M300 S40 P10 ; chirp
; Home
M117 Homing
G28 W ; home all without mesh bed level
; Present bed for cleaning in PINDA warmup position
G0 Z3; Raise nozzle before move
G0 X125 Y180 F10200; Move nozzle to PINDA warming position
G0 Z0.15 F10200; Lower nozzle to PINDA warming position
; Wait for PINDA warmup
M117 PINDA warmup
M860 S35 ; wait for PINDA temp to stabilize
M140 S{material_bed_temperature_layer_0} ; set bed final temp
G0 Z3; Raise nozzle before move
M300 S40 P10 ; chirp
; Mesh bed leveling
M117 Mesh bed leveling
G80 ; mesh bed leveling
M117 Saving results
G81 ; save mesh leveling results
; Final warmup routine
M117 Final warmup
G0 Z5; Raise nozzle to avoid denting bed while nozzle heats
M140 S{material_bed_temperature_layer_0} ; set bed final temp
M104 S{material_print_temperature_layer_0} ; set extruder final temp
M109 S{material_print_temperature_layer_0} ; wait for extruder final temp
M190 S{material_bed_temperature_layer_0} ; wait for bed final temp
M300 S40 P10 ; chirp
; Prime line routine
M117 Printing prime line
G0 Z0.15 ; Restore nozzle position - (thanks tim.m30)
M900 K0; Disable Linear Advance for prime line
G92 E0.0 ; reset extrusion distance
G1 Y-3.0 F1000.0 ; go outside print area
G1 E2 F1000 ; de-retract and push ooze
G1 X20.0 E6  F1000.0 ; fat 20mm intro line @ 0.30
G1 X60.0 E3.2  F1000.0 ; thin +40mm intro line @ 0.08
G1 X100.0 E6  F1000.0 ; fat +40mm intro line @ 0.15
G1 E-0.8 F3000; retract to avoid stringing
G1 X99.5 E0 F1000.0 ; -0.5mm wipe action to avoid string
G1 X110.0 E0 F1000.0 ; +10mm intro line @ 0.00
G1 E0.6 F1500; de-retract
G92 E0.0 ; reset extrusion distance
; Final print adjustments
M117 Preparing to print
M300 S40 P10 ; chirp
M82 ; use absolute extrusion mode for print
M204 R1250 ; sets retract acceleration (R), mm/sec^2
M900 K{material_linear_advance_factor}
M900 W{line_width} H{layer_height} D{material_diameter}
M117 Print in progress

End G-Code

My end g-code is pretty standard. Several gcode settings will persist between prints if not reset, so I like to ensure everything is at defaults on completion.

  • Line 5 retracts 2mm of filament (E-2).

  • Line 6 raises the nozzle to the maximum print area of 210mm.

  • Line 7 moves the extruder to the far left (X0) and forward (Y200) to present the print for easy removal.

  • Line 8 resets print speed over-rides made with the front knob.

  • Line 9 resets Linear Advance.

  • Lines 10-13 shut down the printer hardware.

Here’s my current end g-code:

Listing 32 Ultimaker Cura end g-code
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
; Last updated 20190324
G4 ; wait
M83 ; relative extrusion mode
G92 E0 ; prepare to retract
G1 E-2 F4800; retract quickly to avoid ooze
G1 Z{machine_height} ; raise Z
G0 X0 Y200 F10200; present bed
M221 S100 ; reset extruder factor to 100%
M900 K0 ; reset linear acceleration
M104 S0 ; turn off temperature
M140 S0 ; turn off heatbed
M107 ; turn off fan
M84 ; disable motors
M300 S100 P10 ; chirp

Ultimaker Cura Placeholders

Table 2 Ultimaker Cura G-Code Placeholders

Setting

Placeholder

Notes

First Layer Temperature

{material_print_temperature_layer_0}

First Layer Bed Temperature

{material_bed_temperature_layer_0}

Contact and feedback

You can find me on the Prusa support forums or Reddit where I lurk in many of the 3D printing-related subreddits.

Last modified 20200311