3dSynth

Tutorials / Custom G-code

Open in the interactive tutorials reader

---
title: Tutorial 30 Time as a First-Class Parameter
description: Controlling the 4th dimension of printing.
---

Tutorial 30 Time as a First-Class Parameter

1. Lesson Header

2. Concept Introduction

The Clock is Ticking.
Usually, we think of G-code as spatial (X, Y, Z).
But time is critical for:
- Cooling: Plastic needs time to solidify.
- Photography: Cameras need time to focus.
- Chemical Reactions: Some materials (foaming filaments) expand over time.

We can control time explicitly using Dwell (G4).

3. Machine State Explanation

G4 (Dwell).
Pause the machine buffer.
- G4 P1000: Wait 1000 milliseconds (1 second).
- G4 S1: Wait 1 second (Standard G-code, but Marlin prefers P).

The Buffer:
Normally, the printer reads ahead. G4 forces it to empty the buffer and wait. This ensures synchronization.

4. Command Breakdown

5. Minimal Working Example

The Pause.
Move, Wait, Move.

G1 X10
G4 P2000 ; Wait 2 seconds
G1 X20

6. Visual Representation

Interactive preview is available in the interactive reader.

7. Build Exercise

Task: Create a "Minimum Layer Time" script.
If a layer is too small (e.g., the tip of a cone), the plastic doesn't cool.
We must slow down or wait.
Method:
1. Print Layer.
2. Move Nozzle Away (Park).
3. Wait (G4 P5000).
4. Return and Print Next Layer.

This is better than just slowing down F because it moves the hot nozzle away from the part.

8. Deep Insight Section

Timelapse Triggers.
"Octolapse" works by inserting G-code at every layer change:
1. Retract.
2. Move to specific X/Y (Park).
3. Wait for stability (G4 P500).
4. Trigger Camera (M240 or external pin).
5. Wait for shutter (G4 P200).
6. Return and Resume.

9. Common Failure Modes

  1. Oozing: While waiting (G4), the nozzle is hot. Gravity pulls plastic out. You MUST retract before a G4.
  2. Blobs: When returning after a wait, the nozzle might need a "Prime" (un-retract) or it might have a blob on the tip.

10. Real-World Application

Foaming Filament.
"ColorFabb LW-PLA" foams when heated.
The longer it stays in the nozzle, the more it expands.
You can vary the density by changing speed (Time in nozzle).
Slow = More foam (Lighter).
Fast = Less foam (Heavier).

11. Final Clean Version

The Timelapse Script:

; Lesson 30 - Timelapse Trigger
G21
G90
M83
G28

; --- Layer 1 ---
G1 X100 Y100 E5 ; Print...
G1 X110 Y100 E5 ; Print...

; --- SNAPSHOT ---
G1 E-5 F3000 ; Retract 5mm
G0 X0 Y200 F9000 ; Park Head
M400 ; Wait for move to finish
G4 P500 ; Stabilize (500ms)
M240 ; Trigger Camera (or M42 P5 S255 if using pins)
G4 P200 ; Wait for photo
G0 X110 Y100 F9000 ; Return to last position
G1 E5 F3000 ; Un-retract
; ----------------

; --- Layer 2 ---
G1 Z0.4
G1 X100 Y100 E5
; ... Repeat Snapshot ...

12. Stretch Challenge

Challenge: Write a script that pauses for a different duration based on layer height.
Layer 1: Wait 1s.
Layer 10: Wait 10s.
This simulates a "variable cooling" requirement for a material that gets hotter as it builds up.