2.3.1. 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.
2.3.1.1. 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 similar.
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 piezo 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:
2.3.1.1.1. 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.
1; Last edited 20200216
2M300 S40 P10 ; chirp
3M115 U3.7.2 ; tell printer latest fw version
2.3.1.1.2. 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.
4M117 Initializing
5G21 ; set units to millimeters
6G90 ; use absolute move coordinates
7M83 ; use relative extrusion mode for prime line
2.3.1.1.3. 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.
8; Reset speed and extrusion rates
9M200 D0 ; disable volumetric e
10M220 S100 ; reset speed
11M221 S100 ; reset extrusion multiplier
2.3.1.1.4. 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
)Line 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
)
12; Set hardware parameters
13M201 X1500 Y1500 Z1000 E5000 ; sets maximum accelerations, mm/sec^2
14M203 X200 Y200 Z12 E120 ; sets maximum feedrates, mm/sec
15M204 P1500 R1250 T1500 ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2
16M205 X10.00 Y10.00 Z0.40 E1.50 ; sets the jerk limits, mm/sec
17M205 S0 T0 ; sets the minimum extruding and travel feed rate, mm/sec
2.3.1.1.5. 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.
18; Set initial warmup temps
19M117 Nozzle preheat
20M104 S160 ; set extruder no-ooze temp
21M140 S80 ; set bed PINDA warmup temp high enough for cold days
22; Nozzle warmup before home to avoid driving hardened ooze into PEI surface
23M109 S160 ; wait for extruder no-ooze warmup temp before mesh bed leveling, cool hot PINDA
24M300 S40 P10 ; chirp
2.3.1.1.6. 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.
25; Home
26M117 Homing
27G28 W ; home all without mesh bed level
2.3.1.1.7. 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.
28; Present bed for cleaning in PINDA warmup position
29G0 Z3; Raise nozzle before move
30G0 X125 Y180 F10200; Move nozzle to PINDA warming position
31G0 Z0.15 F10200; Lower nozzle to PINDA warming position
32; Wait for PINDA warmup
33M117 PINDA warmup
34M860 S35 ; wait for PINDA temp to stabilize
35M140 S{material_bed_temperature_layer_0} ; set bed final temp
36G0 Z3; Raise nozzle before move
37M300 S40 P10 ; chirp
2.3.1.1.8. 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.
38; Mesh bed leveling
39M117 Mesh bed leveling
40G80 ; mesh bed leveling
41M117 Saving results
42G81 ; save mesh leveling results
43; Final warmup routine
44M117 Final warmup
45G0 Z5; Raise nozzle to avoid denting bed while nozzle heats
46M140 S{material_bed_temperature_layer_0} ; set bed final temp
47M104 S{material_print_temperature_layer_0} ; set extruder final temp
48M109 S{material_print_temperature_layer_0} ; wait for extruder final temp
49M190 S{material_bed_temperature_layer_0} ; wait for bed final temp
50M300 S40 P10 ; chirp
2.3.1.1.9. 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 initial 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.
51; Prime line routine
52M117 Printing prime line
53G0 Z0.15 ; Restore nozzle position - (thanks tim.m30)
54M900 K0; Disable Linear Advance for prime line
55G92 E0.0 ; reset extrusion distance
56G1 Y-3.0 F1000.0 ; go outside print area
57G1 E2 F1000 ; de-retract and push ooze
58G1 X20.0 E6 F1000.0 ; fat 20mm intro line @ 0.30
59G1 X60.0 E3.2 F1000.0 ; thin +40mm intro line @ 0.08
60G1 X100.0 E6 F1000.0 ; fat +40mm intro line @ 0.15
61G1 E-0.8 F3000; retract to avoid stringing
62G1 X99.5 E0 F1000.0 ; -0.5mm wipe action to avoid string
63G1 X110.0 E0 F1000.0 ; +10mm intro line @ 0.00
64G1 E0.6 F1500; de-retract
65G92 E0.0 ; reset extrusion distance
2.3.1.1.10. 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.
66; Final print adjustments
67M117 Preparing to print
68M300 S40 P10 ; chirp
69M82 ; use absolute extrusion mode for print
70M204 R1250 ; sets retract acceleration (R), mm/sec^2
71M900 K{material_linear_advance_factor}
72M900 W{line_width} H{layer_height} D{material_diameter}
73M117 Print in progress
At this point, the print will proceed normally.
2.3.1.2. Full startup g-code example
Here’s the full start g-code:
1; Last edited 20200216
2M300 S40 P10 ; chirp
3M115 U3.7.2 ; tell printer latest fw version
4M117 Initializing
5G21 ; set units to millimeters
6G90 ; use absolute move coordinates
7M83 ; use relative extrusion mode for prime line
8; Reset speed and extrusion rates
9M200 D0 ; disable volumetric e
10M220 S100 ; reset speed
11M221 S100 ; reset extrusion multiplier
12; Set hardware parameters
13M201 X1500 Y1500 Z1000 E5000 ; sets maximum accelerations, mm/sec^2
14M203 X200 Y200 Z12 E120 ; sets maximum feedrates, mm/sec
15M204 P1500 R1250 T1500 ; sets acceleration (P, T) and retract acceleration (R), mm/sec^2
16M205 X10.00 Y10.00 Z0.40 E1.50 ; sets the jerk limits, mm/sec
17M205 S0 T0 ; sets the minimum extruding and travel feed rate, mm/sec
18; Set initial warmup temps
19M117 Nozzle preheat
20M104 S160 ; set extruder no-ooze temp
21M140 S80 ; set bed PINDA warmup temp high enough for cold days
22; Nozzle warmup before home to avoid driving hardened ooze into PEI surface
23M109 S160 ; wait for extruder no-ooze warmup temp before mesh bed leveling, cool hot PINDA
24M300 S40 P10 ; chirp
25; Home
26M117 Homing
27G28 W ; home all without mesh bed level
28; Present bed for cleaning in PINDA warmup position
29G0 Z3; Raise nozzle before move
30G0 X125 Y180 F10200; Move nozzle to PINDA warming position
31G0 Z0.15 F10200; Lower nozzle to PINDA warming position
32; Wait for PINDA warmup
33M117 PINDA warmup
34M860 S35 ; wait for PINDA temp to stabilize
35M140 S{material_bed_temperature_layer_0} ; set bed final temp
36G0 Z3; Raise nozzle before move
37M300 S40 P10 ; chirp
38; Mesh bed leveling
39M117 Mesh bed leveling
40G80 ; mesh bed leveling
41M117 Saving results
42G81 ; save mesh leveling results
43; Final warmup routine
44M117 Final warmup
45G0 Z5; Raise nozzle to avoid denting bed while nozzle heats
46M140 S{material_bed_temperature_layer_0} ; set bed final temp
47M104 S{material_print_temperature_layer_0} ; set extruder final temp
48M109 S{material_print_temperature_layer_0} ; wait for extruder final temp
49M190 S{material_bed_temperature_layer_0} ; wait for bed final temp
50M300 S40 P10 ; chirp
51; Prime line routine
52M117 Printing prime line
53G0 Z0.15 ; Restore nozzle position - (thanks tim.m30)
54M900 K0; Disable Linear Advance for prime line
55G92 E0.0 ; reset extrusion distance
56G1 Y-3.0 F1000.0 ; go outside print area
57G1 E2 F1000 ; de-retract and push ooze
58G1 X20.0 E6 F1000.0 ; fat 20mm intro line @ 0.30
59G1 X60.0 E3.2 F1000.0 ; thin +40mm intro line @ 0.08
60G1 X100.0 E6 F1000.0 ; fat +40mm intro line @ 0.15
61G1 E-0.8 F3000; retract to avoid stringing
62G1 X99.5 E0 F1000.0 ; -0.5mm wipe action to avoid string
63G1 X110.0 E0 F1000.0 ; +10mm intro line @ 0.00
64G1 E0.6 F1500; de-retract
65G92 E0.0 ; reset extrusion distance
66; Final print adjustments
67M117 Preparing to print
68M300 S40 P10 ; chirp
69M82 ; use absolute extrusion mode for print
70M204 R1250 ; sets retract acceleration (R), mm/sec^2
71M900 K{material_linear_advance_factor}
72M900 W{line_width} H{layer_height} D{material_diameter}
73M117 Print in progress
2.3.1.3. 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:
1; Last updated 20190324
2G4 ; wait
3M83 ; relative extrusion mode
4G92 E0 ; prepare to retract
5G1 E-2 F4800; retract quickly to avoid ooze
6G1 Z{machine_height} ; raise Z
7G0 X0 Y200 F10200; present bed
8M221 S100 ; reset extruder factor to 100%
9M900 K0 ; reset linear acceleration
10M104 S0 ; turn off temperature
11M140 S0 ; turn off heatbed
12M107 ; turn off fan
13M84 ; disable motors
14M300 S100 P10 ; chirp
2.3.1.4. Ultimaker Cura Placeholders
Setting |
Placeholder |
Notes |
---|---|---|
First Layer Temperature |
{material_print_temperature_layer_0} |
|
First Layer Bed Temperature |
{material_bed_temperature_layer_0} |
See also
The Comprehensive RepRap G-code reference page
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. I occasionally drop into the Official Prusa 3D discord server where I can be reached as bobstro (bobstro#9830). You can email me directly at projects@ttlexceeded.com.
Last modified Apr 14, 2021. Last build on Oct 22, 2021.