3dSynth

Tutorials / Custom G-code

Open in the interactive tutorials reader

---
title: Tutorial 12 Build Your First Complete File
description: Putting it all together. A fully printable object.
---

Tutorial 12 Build Your First Complete File

1. Lesson Header

2. Concept Introduction

The Full Stack.
We have learned movement (G0/G1), extrusion (E), temperature (M104), and homing (G28).
Now we combine them into a single file that can be sent to a printer without any slicer help.

3. Machine State Explanation

Layer Height & Width.
- Layer Height: Typically 0.2mm.
- Line Width: Typically 0.4mm (for a 0.4mm nozzle).
- Flow: If we move 100mm, how much E do we push?
- Volume = Width Height Length = 0.4 0.2 100 = 8mm³.
- Filament Area = Pi r² = 3.14 (1.75/2)² ≈ 2.4mm².
- Extrusion Length = Volume / Area = 8 / 2.4 ≈ 3.3mm of filament for 100mm of travel.
- Rule of Thumb: E ≈ 0.033 * Distance (for 0.2mm layer). Or simplified: E ≈ Distance / 30.

4. Command Breakdown

Review:
- G28: Home.
- M104 S200: Heat Nozzle.
- M140 S60: Heat Bed.
- G1 Z0.2: First Layer Height.
- G1 X... Y... E...: Print Move.
- G1 Z...: Layer Change.
- M104 S0: Cool Down.

5. Minimal Working Example

A Single Layer Square.

G28
G1 Z0.2
G1 X10 Y10 F3000
G1 X30 Y10 E0.6
G1 X30 Y30 E1.2
G1 X10 Y30 E1.8
G1 X10 Y10 E2.4

6. Visual Representation

The Cube Structure:

Interactive preview is available in the interactive reader.

7. Build Exercise

Task: Write a G-code file for a 20mm x 20mm hollow square tower, 5mm tall (25 layers).
1. Start G-code (Heat/Home).
2. Loop (or manual copy-paste) for 25 layers.
3. End G-code (Cool/Park).

The Math:
- Side Length: 20mm.
- Extrusion per side: 20 / 30 = 0.66mm E.
- Total E per layer: 0.66 * 4 = 2.64mm.

Solution:

; Setup
M140 S60
M104 S200
G28
M190 S60
M109 S200

; Layer 1
G1 Z0.2
G1 X100 Y100 F3000 ; Move to start
G92 E0
G1 X120 Y100 E0.66
G1 X120 Y120 E1.32
G1 X100 Y120 E1.98
G1 X100 Y100 E2.64

; Layer 2
G1 Z0.4
G92 E0
G1 X120 Y100 E0.66
; ... repeat

8. Deep Insight Section

Why Slicers Exist.
Writing this by hand is tedious. A slicer automates the geometry calculations, infill, supports, and cooling logic.
However, knowing how to write it lets you debug why a slicer might be failing, or write custom calibration scripts that slicers can't generate (like changing temperature every layer).

9. Common Failure Modes

  1. First Layer Too High: If Z=0.2 is actually 0.5mm above the bed (due to bad leveling), the plastic won't stick. It will drag around a "spaghetti monster".
  2. Too Much Extrusion: If you push E10 for a 20mm line, the nozzle will plow through plastic, creating a mess.
  3. Too Little Extrusion: The lines won't touch, and the part will be weak.

10. Real-World Application

Calibration Towers.
Temp towers, Retraction towers, Speed towers.
These are often generated by scripts or modified G-code, not standard slicing, because they change parameters every layer.

11. Final Clean Version

Save this as lesson12.gcode. A 5-layer test print.

; Lesson 12 - First Print
G21 ; Metric
G90 ; Absolute
M82 ; Absolute E
M104 S200
M140 S60
G28
M109 S200
M190 S60

; Prime
G1 Z0.2 F3000
G1 X0 Y0
G1 X100 E10 F1000 ; Prime line
G92 E0

; Move to Start
G1 X100 Y100 F5000

; Layer 1 (Z=0.2)
G1 Z0.2
G1 X120 Y100 E0.7
G1 X120 Y120 E1.4
G1 X100 Y120 E2.1
G1 X100 Y100 E2.8

; Layer 2 (Z=0.4)
G1 Z0.4
G92 E0 ; Reset Extruder
G1 X120 Y100 E0.7
G1 X120 Y120 E1.4
G1 X100 Y120 E2.1
G1 X100 Y100 E2.8

; Layer 3 (Z=0.6)
G1 Z0.6
G92 E0
G1 X120 Y100 E0.7
G1 X120 Y120 E1.4
G1 X100 Y120 E2.1
G1 X100 Y100 E2.8

; End
M104 S0
M140 S0
G91
G1 Z10
G28 X0 Y0
M84

12. Stretch Challenge

Challenge: Add a "skirt" around the object.
Draw a square 5mm larger than the object (25mm x 25mm) before starting the main object, to ensure flow is consistent.

Answer Key:

; Skirt
G1 X95 Y95
G1 X125 Y95 E...
G1 X125 Y125 E...
; ...