3dSynth

Tutorials / Custom G-code

Open in the interactive tutorials reader

---
title: Tutorial 11 Start & End G-code
description: The "Wrapper" around your print. Safety, heating, and homing.
---

Tutorial 11 Start & End G-code

1. Lesson Header

2. Concept Introduction

The "Ritual"

Every print needs a consistent start and end.
- Start: Heat up, Home, Prime (Squirt some plastic), Move to Start.
- End: Turn off Heat, Move Head Away, Disable Motors.

Without this, your print will start mid-air, cold, or crash into the bed at the end.

3. Machine State Explanation

Why Order Matters.
- Heat First? No, because the nozzle might ooze while homing.
- Home First? Yes, but don't crash into clips.
- Prime First? Yes, to purge old material.

4. Command Breakdown

Start Sequence

1. G28: Home All Axes. 2. M140 S60 / M104 S200: Set Temps (Bed / Nozzle). 3. M190 S60 / M109 S200: Wait for Temps. 4. G1 Z...: Lift Nozzle. 5. G1 E...: Prime Nozzle.

End Sequence

1. M104 S0 / M140 S0: Turn Off Heaters. 2. G91 / G1 Z10: Relative Move Up (Clear part). 3. G90 / G1 X0 Y200: Absolute Move Away (Present part). 4. M84: Disable Steppers (Save energy, unlock motors).

5. Minimal Working Example

The "Safe Start" Block

; Start G-code
G90        ; Absolute Positioning
M82        ; Absolute Extrusion
G28        ; Home
G1 Z15.0 F6000 ; Move the platform down 15mm
; Prime the extruder
G92 E0
G1 F200 E3
G92 E0

The "Safe End" Block

; End G-code
M104 S0 ; Turn off extruder
M140 S0 ; Turn off bed
G91 ; Relative positioning
G1 E-1 F300 ; Retract filament
G1 Z+0.5 E-5 X-20 Y-20 F9000 ; Move Z up a bit and retract filament even more
G28 X0 Y0 ; Move X/Y to min endstops so the head is out of the way
M84 ; Steppers off
G90 ; Absolute positioning

6. Visual Representation

The Timeline:

Interactive preview is available in the interactive reader.

  1. Heat Bed (Wait)
  2. Home (Move)
  3. Heat Nozzle (Wait - prevents oozing during bed heat)
  4. Prime Line (Draw a line on the edge)
  5. Print (The main file)
  6. Cooldown (Safety)

7. Build Exercise

Task: Write a custom Start G-code that:
1. Heats the bed to 60C.
2. Homes.
3. Moves to X=0, Y=0, Z=0.2.
4. Draws a 100mm line along the Y-axis to prime the nozzle.
5. Wipes the nozzle (moves away quickly).

Solution:

M140 S60
M190 S60
G28
M104 S200
M109 S200
G1 Z2.0 F3000
G1 X0.1 Y20 Z0.3 F5000.0
G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line
G1 X0.4 Y200.0 Z0.3 F5000.0
G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line
G92 E0
G1 Z2.0 F3000

8. Deep Insight Section

Why Prime?
When a nozzle sits hot, plastic oozes out due to gravity and thermal expansion. This leaves an air bubble inside. If you start printing immediately, the first few mm of your skirt/brim will be missing.
The "Prime Line" forces fresh plastic into the melt zone so the pressure is correct when the real print starts.

9. Common Failure Modes

  1. Crashing into Bed Clips: If your prime line is at Y=0 or X=0, make sure it doesn't hit the clips holding the glass bed.
  2. Oozing during Homing: If you heat the nozzle fully before homing, it might drip on the bed or probe. Better to heat to 150C (standby), Home, then heat to 200C.
  3. Z-Hop at End: Forgetting G91 (Relative) before G1 Z10 at the end causes the printer to move to Absolute Z=10. If your print is 100mm tall, the nozzle crashes down into the print. Always use Relative Z for the end lift!

10. Real-World Application

Slicers use this.
In Cura/PrusaSlicer, there is a "Start G-code" and "End G-code" box.
This text is literally copy-pasted at the top and bottom of every file you slice.
Customizing this is the first step to advanced printing (e.g., adding a nozzle wipe, or playing a song).

11. Final Clean Version

Save this as lesson11.gcode (This is a template, not a print).

; --- START G-CODE ---
G90      ; Absolute Positioning
M82      ; Absolute Extrusion
G21      ; Metric
M140 S60 ; Set Bed Temp
M104 S200 ; Set Nozzle Temp
G28      ; Home
M190 S60 ; Wait for Bed
M109 S200 ; Wait for Nozzle
G1 Z5 F3000 ; Lift Nozzle
G1 X1 Y1 F3000 ; Go to corner
G1 Z0.3 ; Drop to print height
G1 Y100 E10 F1500 ; Prime Line
G92 E0   ; Reset Extruder
; --- PRINT START ---
; (Your print goes here)
; --- PRINT END ---
M104 S0 ; Turn off Hotend
M140 S0 ; Turn off Bed
G91     ; Relative Positioning
G1 Z10  ; Lift Z
G90     ; Absolute Positioning
G1 X0 Y200 ; Present Print
M84     ; Disable Motors

12. Stretch Challenge

Challenge: Modify the end code to play a song (using M300) when the print finishes.
M300 S[Frequency] P[Duration]

Answer Key:

M300 S440 P200 ; A4
M300 S880 P200 ; A5
M300 S440 P200 ; A4