PrusaSlicer Start G-Code for the Prusa i3 Mk3

The default g-code that ships with PrusaSlicer 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 speed up the heating process, but avoid dots and strings caused by molten filament dripping out during mesh bed leveling and bed warmup.

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

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

  • PINDA warmup to ensure a consistent 35C PINDA temperature before performing mesh bed leveling to ensure consistent results. This is only necessary for printers with PINDA v1 probes. It is optional for PINDA v2 and v3 configurations. For more information, check out the PINDA warmup notes page.)

Important

Prusa has recently released the SuperPINDA sensor for bed leveling. SuperPINDA works differently than the previous generations of PINDA sensors. If the M860 gcode command is used, printers with the SuperPINDA mounted will simply hang.

I have updated this page and the referenced gcode to detect whether the user is using a Mk3S or Mk3S+ printer profile. Lines of gcode will inserted or left out based on this setting. If you are runnning a SuperPINDA on a Mk3 (not Mk3*S*) printer profile, this gcode may not work. I do not believe there is a way to detect a SuperPINDA configuration in the slicer at this time. Please let me know via the contact links at the bottom of this page if you encounter any problems.

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

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.

Here’s a line-by-line breakdown:

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.

Version control

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

  • Line 3 chirps the printer speaker. 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.

  • Line 4 does a printer model check. If you generated gcode using PrusaSlicer configured for a different printer, you’ll receive a warning.

  • Line 5 does a nozzle diameter check. If you generated gcode using PrusaSlicer for a different nozzle size than you’ve set in your printer settings menu, you’ll receive a warning. Note that the firmware currently only supports 0.25, 0.40 and 0.60mm nozzle sizes.

  • Line 6 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 4 PrusaSlicer start g-code version control
1
2
3
4
5
6
; PrusaSlicer start gcode for Prusa i3 Mk3
; Last updated 20210316
M300 S60 P10 ; chirp
M862.3 P "[printer_model]" ; printer model check
M862.1 P[nozzle_diameter] ; nozzle diameter check
M115 U3.9.0 ; tell printer latest fw version

Note

I am not a fan of the printer and nozzle checks since I am the only user of my printer. I have disabled these checks in the printer menu.

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 9 sets absolute move coordinates for movement.

  • Line 10 sets relative extruder coordinates.

Listing 5 PrusaSlicer start g-code coordinate initialization
 7
 8
 9
10
M117 Initializing
; Set coordinate modes
G90 ; use absolute coordinates
M83 ; extruder relative mode

Initialization

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

  • Line 12 disables volumetric e (autospeed) printing.

  • Line 13 resets the print speed to 100% on the printer in case it was previously changed by using the front knob or an aborted print.

  • Line 14 resets the extrusion multiplier to 100% on the printer in case it was previously changed by using the front knob or an aborted print.

Listing 6 PrusaSlicer start g-code print parameter initialization
11
12
13
14
; Reset speed and extrusion rates
M200 D0 ; disable volumetric e
M220 S100 ; reset speed
M221 S100 ; reset extrusion rate

Initialize warmup temperatures

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

Note

I have modified this section significantly as of January 2021:

  • Versions of the PINDA probe since the original v1 version do not require the PINDA warmup routine to ensure consistent results. However, warming up the printer is still recommended, particularly on cold days. The “PINDA warmup” is a good way to accomplish this.

  • The SuperPINDA sensor used on the Mk3S+ printer is not compatible with (and does not need) the PINDA temperature check.

I have added checks for a Mk3s/Mk3s+ printer. PINDA temperature checks will be skipped if you are running this gcode with one of these printers. Unfortunately, this also means you will lose the benefit of warming the entire printer up before the first print of the day. I am working on a solution to still provide a reasonable warmup.

  • Line 17 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 18 sets the bed temperature.

    • If you are using this gcode on a Mk3s/Mk3s+ printer, the bed will be set to the temperature set in the filament settings profile.

    • If you are not running a Mk3s/Mk3s+ printer, the bed temperature will be set 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 set the bed to 80C due to cold weather. See the PINDA warmup notes for details.

  • Line 20 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 squish if it hits the PEI print surface.

Listing 7 PrusaSlicer start g-code initial warmup temps
15
16
17
18
19
20
; Set initial warmup temps
M117 Nozzle preheat
M104 S160 ; set extruder no-ooze temp
M140 S{if printer_model=~/.*MK3S.*/}[first_layer_bed_temperature]{else}{max(first_layer_bed_temperature[0],80)}{endif}  ; set bed PINDA warmup temp
; 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

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

Listing 8 PrusaSlicer start g-code initial homing
21
22
23
24
; Home
M300 S40 P10 ; chirp
M117 Homing
G28 W ; home all without mesh bed level

Bed presentation

This stanza presents the bed for inspection and cleaning while waiting for the bed to come up to final printing temperature. The nozzle is moved to the center-rear portion of the bed, positioned slightly forward so the extruder is warmed by the bed.

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

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

Note

I recently moved the resting Y position closer to the bed center to improve PINDA warming.

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

Listing 9 PrusaSlicer start g-code bed presentation
25
26
27
28
; Present bed for final cleaning
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

PINDA warmup

The next stanza conditionally performs a PINDA warmup routine. If you are running a Mk3s/Mk3s+, this procedure will be skipped. This procedure will only be run if you not using this gcode as part of a Mk3s/Mk3s+ printer profile.

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

Note

This procedure has become considerably more complex due to the need to do additional checks for the printer type. It is a good example of using the PrusaSlicer conditional code checks.

  • Line 31 starts a block of gcode that will be inserted if the printer_model placeholder contains the text “MK3S”.

  • Line 32 sends a message to the printer display (M117). You can insert lines to be inserted only for a Mk3s/Mk3s+ printer here.

  • Line 33 starts the block of gcode that will be inserted if the printer_model placeholder does not contain the text “MK3S”.

  • Line 34 sends a message to the printer display (M117).

  • Line 35 inserts the command (M860 S35) 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 36 ends the block of gcode that will be inserted if the printer_model placeholder does not contain the text “MK3S”.

  • Line 37 sets the bed temp specified in the filament settings. This is done here before mesh bed leveling to let the bed cool down to close to the final print temperature as MBL completes.

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

Listing 10 PrusaSlicer start g-code PINDA warmup procedure
29
30
31
32
33
34
35
36
37
38
; Wait for PINDA warmup
M117 PINDA warmup
{if printer_model=~/.*MK3S.*/}
M117 Mk3S detected, no warmup required
{else}
M117 Mk3 Waiting for PINDA warmup
M860 S35 ; wait for PINDA temp to stabilize
{endif}
M140 S[first_layer_bed_temperature] ; set target bed temp
G0 Z3; Raise nozzle before move

Mesh bed leveling and final warmup

Now that any preparation is complete, we can perform mesh bed leveling.

  • Line 42 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 automatically to the home position.

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

Listing 11 PrusaSlicer start g-code mesh bed leveling & final warmup
39
40
41
42
43
44
; Mesh bed leveling
M300 S40 P10 ; chirp
M117 Mesh bed leveling
G80 ; mesh bed leveling
M117 Saving results
G81 ; save mesh leveling results

Final temperature settings

After all calibration and settings are done, we set final temperatures in preparation for starting the actual print.

  • Line 47 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 48 sets (M140) the first layer bed temperature set in the filament settings profile.

  • Line 49 sets (M104) the first layer print temperature set in the filament settings profile.

  • Line 50 waits for (M109) the first layer print temperature set in the slicer settings.

  • Line 51 waits for (M190) the first layer bed temperature to settle before printing.

Listing 12 PrusaSlicer start g-code final temperature settings
45
46
47
48
49
50
51
52
; Final warmup routine
M117 Final warmup
G0 Z5; Raise nozzle to avoid denting bed while nozzle heats
M140 S[first_layer_bed_temperature] ; set bed final temp
M104 S[first_layer_temperature] ; set extruder final temp
M109 S[first_layer_temperature] ; wait for extruder final temp
M190 S[first_layer_bed_temperature] ; wait for bed final temp
; Prime line routine

Prime line

Once the nozzle and bed come up to temperature, a custom prime line is printed. I’ve made some tweaks to the bog-standard line.

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

  • Line 56 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 57 resets the current extruder position. This is done periodically when extruder moves are set to relative. It ensures that the amount of filament extruded does not drift over time.

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

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

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

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

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

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

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

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

  • Line 66 de-retracts (pushes) 0.6mm of filament (E0.6) to re-prime after the previous retraction. Note that this is slightly less than was retracted in line 63 to avoid ooze as the nozzle moves into final printing position. If filament doesn’t flow at the start of a print, either use a skirt to prime the flow, or increase this to 0.8mm.

Listing 13 PrusaSlicer start g-code prime line procedure
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
; Prime line routine
M300 S40 P10 ; chirp
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. I’m not doing anything here. Adjust for your printer.

  • Line 72 is commented out. It can be used to adjust the extrusion rate (M221). In this example, I set the rate to 90% for layer heights over 0.32mm. I find this is helpful when using large nozzles with very high layers. Generally, you want to set this in the extrusion multiplier for each filament profile. See my notes on the PrusaSlicer system preset for the Mk3-series for more detail.

Listing 14 PrusaSlicer start g-code final print adjustments
68
69
70
71
72
73
; Final print adjustments
M300 S40 P10 ; chirp
M117 Preparing to print
; Adjust extrusion rate if desired
; M221 S{if layer_height >= 0.32}90{else}100{endif} ; compensate for thick layer heights
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 15 PrusaSlicer 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
; PrusaSlicer start gcode for Prusa i3 Mk3
; Last updated 20210316
M300 S60 P10 ; chirp
M862.3 P "[printer_model]" ; printer model check
M862.1 P[nozzle_diameter] ; nozzle diameter check
M115 U3.9.0 ; tell printer latest fw version
M117 Initializing
; Set coordinate modes
G90 ; use absolute coordinates
M83 ; extruder relative mode
; Reset speed and extrusion rates
M200 D0 ; disable volumetric e
M220 S100 ; reset speed
M221 S100 ; reset extrusion rate
; Set initial warmup temps
M117 Nozzle preheat
M104 S160 ; set extruder no-ooze temp
M140 S{if printer_model=~/.*MK3S.*/}[first_layer_bed_temperature]{else}{max(first_layer_bed_temperature[0],80)}{endif}  ; set bed PINDA warmup temp
; 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
; Home
M300 S40 P10 ; chirp
M117 Homing
G28 W ; home all without mesh bed level
; Present bed for final cleaning
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
{if printer_model=~/.*MK3S.*/}
M117 Mk3S detected, no warmup required
{else}
M117 Mk3 Waiting for PINDA warmup
M860 S35 ; wait for PINDA temp to stabilize
{endif}
M140 S[first_layer_bed_temperature] ; set target bed temp
G0 Z3; Raise nozzle before move
; Mesh bed leveling
M300 S40 P10 ; chirp
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[first_layer_bed_temperature] ; set bed final temp
M104 S[first_layer_temperature] ; set extruder final temp
M109 S[first_layer_temperature] ; wait for extruder final temp
M190 S[first_layer_bed_temperature] ; wait for bed final temp
; Prime line routine
M300 S40 P10 ; chirp
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
M300 S40 P10 ; chirp
M117 Preparing to print
; Adjust extrusion rate if desired
; M221 S{if layer_height >= 0.32}90{else}100{endif} ; compensate for thick layer heights
M117 Print in progress

Thanks /Urban for catching the paste error!

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 edited on Apr 03, 2021. Last build on Apr 03, 2021.