3dSynth

Tutorials / Custom G-code

Open in the interactive tutorials reader

---
title: Tutorial 4 Extrusion Basics
description: Understanding the E axis and controlling plastic flow.
---

Tutorial 4 Extrusion Basics

1. Lesson Header

2. Concept Introduction (Why It Matters)

Purpose: The "Fourth Dimension" of printing.

So far, we have moved the nozzle in 3D space (X, Y, Z). But a 3D printer isn't just a robot arm; it's a hot glue gun on a robot arm.

The E Axis (Extruder) controls the motor that pushes filament into the heater.
- Positive E: Pushes filament out (Extrude).
- Negative E: Pulls filament back (Retract).

Crucially, E is just another coordinate. When you tell the printer G1 X100 E10, you are saying: "Move the nozzle to X=100 while simultaneously pushing the E motor to position 10."

The synchronization is automatic. If the move takes 5 seconds, the extruder spreads that 10mm of filament evenly over those 5 seconds. This is what creates a smooth line.

3. Machine State Explanation

Hotend Temperature is Critical.
Most firmware prevents "Cold Extrusion." If the nozzle is below ~170°C, the E motor will simply refuse to move to prevent grinding the filament or breaking the gear.

For this lesson, we will simulate the extrusion or assume the printer is pre-heated. (We cover heating commands in Lesson 8).

Absolute vs. Relative Extrusion
This is the biggest source of confusion in G-code.
- Absolute E (M82): "Push filament until the counter reads 100mm."
- Relative E (M83): "Push 5mm more filament than where you are now."

Most modern slicers (like PrusaSlicer) prefer Relative E (M83) because it's easier to calculate. However, older styles use Absolute. We will focus on Relative for simplicity in hand-coding.

4. Command Breakdown

Set Extruder to Relative Mode (M83)

Tells the machine to treat E values as "increments." - Syntax: M83 - Opposite: M82 (Absolute Extrusion).

The Extrusion Move (G1 ... E[value])

Adds the E parameter to a standard move. - Syntax: G1 X100 Y100 E5 - Meaning: Move to 100,100 while pushing 5mm of filament.

Reset Extruder Position (G92 E0)

Used in Absolute mode to say "Current position is now 0." - Syntax: G92 E0 - Use: Often seen at the start of layers in absolute mode files.

5. Minimal Working Example

Let's draw a single line of plastic.

; Lesson 4 - The Prime Line
G21        ; Millimeters
G90        ; Absolute Positioning (for X/Y/Z)
M83        ; Relative Extrusion (for E)
G28        ; Home

; Prepare
G0 Z0.3    ; Go to "First Layer Height"
G0 X10 Y10 ; Start position

; The Extrusion
; Move 100mm to the right, extruding 5mm of filament
G1 X110 Y10 E5 F1500

Line-by-Line:
1. M83: We tell the printer "Every E number is how much more to push."
2. G0 Z0.3: We need to be close to the bed to squish the plastic.
3. G1 X110 Y10 E5:
- Distance moved: 100mm (from X10 to X110).
- Filament used: 5mm.
- Result: A thin line of plastic deposited on the bed.

6. Visual Representation

Interactive preview is available in the interactive reader.

The E motor turns at a constant rate matched to the X movement.

7. Build Exercise

Task: Create a "L" shape extrusion.
1. Start at X20 Y20.
2. Draw a line to X120 Y20 using 10mm of filament.
3. Draw a line to X120 Y120 using 10mm of filament.

Assume M83 (Relative E) is set.

...

Solution:

G21
G90
M83 ; Relative E
G28

G0 Z0.3
G0 X20 Y20   ; Start

; First Leg
G1 X120 Y20 E10 F1500

; Second Leg
G1 X120 Y120 E10

8. Deep Insight Section

How much E is correct?

"Why E10? Why not E50?"
This depends on the Volumetric Flow.
- Filament Diameter: 1.75mm
- Nozzle Diameter: 0.4mm
- Layer Height: 0.2mm

The math is: Volume of Line = Volume of Filament.
Slicers calculate this precisely. For hand-coding, a good rule of thumb for a 0.4mm nozzle at 0.2mm height is:
*E ≈ 0.033 Distance**
(e.g., for 100mm move: 100 * 0.033 = 3.3mm of filament).

In our examples, we used E5 or E10 which is quite "fat" (over-extruded) just to ensure you see it working.

9. Common Failure Modes

  1. Cold Extrusion Prevention: If you run this code on a cold printer, the X/Y will move, but the E motor will stay still. The printer protects itself. You must heat it up first (via LCD or M104).
  2. Wrong E Mode: If you are in Absolute Mode (M82) but write code thinking you are in Relative (M83), the first line works, but the second line might retract!

10. Real-World Application

The "Purge Line"

Almost every slicer adds a "Start G-code" script that draws a line at the edge of the bed.
This is exactly what we wrote in the Example. Its purpose is to prime the nozzle pressure so the actual print starts cleanly.

Look at your slicer settings -> Start G-code. You will find something like:
G1 Y200.0 F1500.0 E15 ; Draw the first line

11. Final Clean Version

Save this as lesson4.gcode.

; Lesson 4 - The Prime L
; Setup
G21        ; Millimeters
G90        ; Absolute Positioning
M83        ; Relative Extrusion
G28        ; Home

; Safety Check: Ensure nozzle is hot (Manual check required for now)

; Move to Start
G0 Z0.3    ; First layer height
G0 X20 Y20 ; Start corner

; Draw
G1 F1500     ; Set Speed
G1 X120 Y20 E4  ; Leg 1 (Calculated for ~0.4 nozzle)
G1 X120 Y120 E4 ; Leg 2

; Finish
G0 Z10       ; Lift
G0 X0 Y200   ; Park

12. Stretch Challenge

Challenge: Write a program that draws a square, but Retracts (pulls back) filament at the corners so it doesn't ooze while turning.

Hint: Use a negative E value to retract, then a positive E value to "un-retract" (prime) before moving again.

Answer Key:

; Move to Corner 1
G1 X100 Y20 E4
G1 E-1 F2400 ; Retract 1mm fast
G1 E1 F2400  ; Prime 1mm fast

; Move to Corner 2
G1 X100 Y100 E4
G1 E-1
G1 E1
; ... etc