Customizing Ultimaker Cura 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 printer. 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 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.

Start G-Code

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 and firmware version stamps. 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.

Listing 21 Ultimaker Cura start g-code version control
1
2
; Last updated 20190324
M115 U3.5.1 ; tell printer latest fw version

Initial warmup temperatures

The next stanza sets preliminary warmup temperatures.

  • Line 4 sets the extruder (nozzle) temperature to 160C, 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 5 sets the bed temperature to 65C. This is to ensure that the bed is hot enough to warm up the PINDA even on cold days. See the PINDA warmup notes for details.

  • Line 7 specifies relative exturder positioning mode.

  • Line 9 waits for the extruder warmup temperature.

Listing 22 Ultimaker Cura start g-code initial warmup temps
3
4
5
6
7
8
9
; Set initial warmup temps
M104 S160 ; set extruder no-ooze temp
M140 S65  ; set bed PINDA warmup temp
G21 ; set units to millimeters
G90 ; use absolute positioning
; Nozzle warmup routine
M109 ; wait for extruder no-ooze warmup temp before mesh bed leveling, cool hot PINDA

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 11 performs homing, moving the printer to the lowest (Z 0) left (X 0) front (Y 210) coordinates to establish the current position.

Listing 23 Ultimaker Cura start g-code initial homing
10
11
M300 S40 P10 ; chirp
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 14 raises the nozzle 3mm to avoid possibly damaging the PEI sheet during nozzle movement in the steps that follow.

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

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

  • Line 17 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 18 raises the nozzle 3mm (Z3) for movement as a precaution before rapid moves close to the print surface.

Listing 24 Ultimaker Cura start g-code PINDA warmup
12
13
14
15
16
17
18
; PINDA warmup routine
M300 S40 P10 ; chirp
G0 Z3; Raise nozzle before move
G0 X125 Y210 F10200; Move nozzle to PINDA warming position
G0 Z0.10 F10200; Lower nozzle to PINDA warming position
M860 S35 ; wait for PINDA temp to stabilize
G0 Z3; Raise nozzle before move

Mesh bed leveling and final warmup

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

  • Line 20 performs the actual leveling. With the latest firmware releases, this will do either 3X3 or 7X7 grid leveling as specified in the printer setup menu.

  • After leveling, the nozzle will be returned to the home position. Line 21 raises the nozzle 3mm (Z3) 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 22 sets the final bed temperature to the user-specified temperature specified in the slicer settings. This may be warmer or cooler than the 65C PINDA warmup temp.

  • Lines 24 and 25 set (M104) and wait for (M109) thefinal nozzle print temperatures specified in the slicer settings.

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

Listing 25 Ultimaker Cura start g-code mesh bed leveling & final warmup
19
20
21
22
23
24
25
26
M300 S40 P10 ; chirp
G80 ; mesh bed leveling
G0 Z3; Raise nozzle to avoid denting bed while nozzle heats
M140 S{material_bed_temperature_layer_0} ; set bed final temp
; Final warmup routine
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

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 28 lowers the nozzle (Z-3) to initial printing position.

  • Line 30 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.

  • Lines 32 moves to the initial prime line position (X=0, Y=-3).

  • Line 33 extrudes an intial “blort” of filament without moving to trap any ooze or string remaing on the nozzle.

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

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

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

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

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

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

  • Line 40 de-retracts (pushes) 0.6mm of filament (E0.6) to re-prime after the retraction in line 37.

Listing 26 Ultimaker Cura start g-code prime line
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
; Prime line routine
M300 S25 P10 ; chirp
G0 Z-3; Restore nozzle position
M82  ; extruder absolute mode
M900 K0; Disable LA 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 F2100; 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. I’ve commented out line 43, but it shows an example of extrusion rate adjustment. Adjust for your printer.

Listing 27 Ultimaker Cura start g-code final print adjustments
41
; Final print adjustments

At this point, the print will proceed normally.

Full startup g-code example

Here’s the full start g-code:

Listing 28 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
; Last updated 20190324
M115 U3.5.1 ; tell printer latest fw version
; Set initial warmup temps
M104 S160 ; set extruder no-ooze temp
M140 S65  ; set bed PINDA warmup temp
G21 ; set units to millimeters
G90 ; use absolute positioning
; Nozzle warmup routine
M109 ; wait for extruder no-ooze warmup temp before mesh bed leveling, cool hot PINDA
M300 S40 P10 ; chirp
G28 W ; home all without mesh bed level
; PINDA warmup routine
M300 S40 P10 ; chirp
G0 Z3; Raise nozzle before move
G0 X125 Y210 F10200; Move nozzle to PINDA warming position
G0 Z0.10 F10200; Lower nozzle to PINDA warming position
M860 S35 ; wait for PINDA temp to stabilize
G0 Z3; Raise nozzle before move
M300 S40 P10 ; chirp
G80 ; mesh bed leveling
G0 Z3; Raise nozzle to avoid denting bed while nozzle heats
M140 S{material_bed_temperature_layer_0} ; set bed final temp
; Final warmup routine
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
; Prime line routine
M300 S25 P10 ; chirp
G0 Z-3; Restore nozzle position
M82  ; extruder absolute mode
M900 K0; Disable LA 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 F2100; 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
M204 R1250 ; sets retract acceleration (R), mm/sec^2

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 29 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.