---
title: Tutorial 2 The Coordinate System
description: Understanding X, Y, and Z axes in 3D space.
---
Tutorial 2 The Coordinate System
1. Lesson Header
- Lesson Number: 2
- Level: Beginner
- Title: The Coordinate System
- Estimated Duration: 20 Minutes
- Prerequisites: Lesson 1
- What You Will Build: A program that moves the nozzle to all four corners of the bed.
2. Concept Introduction (Why It Matters)
Purpose: Understand where "Zero" is.
Your 3D printer lives in a Cartesian Coordinate System. This is just a fancy way of saying it uses three numbers (X, Y, Z) to describe any point in space.
- X: Left (-) to Right (+)
- Y: Front (-) to Back (+)
- Z: Down (-) to Up (+)
Most 3D printers place (0,0,0) at the front-left corner of the bed. This is the "Origin."
When you tell the printer G1 X100 Y100, you are telling it to go to a specific spot on the grid relative to that origin.
3. Machine State Explanation
Before we can move reliably, the machine must know where it physically is. When you turn on a printer, it has amnesia. It thinks it's at 0,0,0, even if the nozzle is in the middle of the bed!
This is why we Home (G28). Homing drives the axes until they hit limit switches (click!). Once they click, the machine knows "Ah, this is Zero."
4. Command Breakdown
The Home Command (G28)
Tells the machine to find its physical limits.
- Syntax: G28 (Home all axes)
- Syntax: G28 X Y (Home only X and Y, leave Z alone)
- Modal: No. It's an action, not a state.
The Coordinate System
Not a command, but a concept. - X Axis: Usually the gantry moving left/right. - Y Axis: Usually the bed moving forward/back (or the gantry on CoreXY). - Z Axis: The bed moving up/down (or the gantry moving up/down).5. Minimal Working Example
A safe startup sequence involves homing first.
; Lesson 2 - Safe Homing
G21 ; Millimeters
G90 ; Absolute Positioning
G28 ; Home All Axes (Find Zero)
G1 Z10 ; Lift nozzle up 10mm to avoid scratching
G1 X10 Y10 ; Move to a safe starting point
Line-by-Line:
1. G28: The printer moves to the corners until it clicks. Now 0,0,0 is set.
2. G1 Z10: We lift the nozzle immediately. Moving at Z=0 is dangerous because you might scratch the bed tape or PEI sheet.
3. G1 X10 Y10: Move slightly onto the bed.
6. Visual Representation
Imagine looking down at your printer bed.
Interactive preview is available in the interactive reader.
- Origin (0,0): Front-Left.
- Max X (200,0): Front-Right.
- Max Y (0,200): Back-Left.
- Max XY (200,200): Back-Right.
(Note: Your printer might be bigger, e.g., 220x220 or 300x300. Check your specs!)
7. Build Exercise
Task: Write a program that visits all four corners of a 100x100mm square in the center of the bed.
- Home the machine.
- Lift Z to 5mm.
- Move to
X50 Y50(Start). - Move to
X150 Y50. - Move to
X150 Y150. - Move to
X50 Y150. - Return to
X50 Y50.
Try it on paper first!
...
Solution:
G21
G90
G28 ; Home
G1 Z5 ; Safety Lift
G1 X50 Y50 ; Corner 1
G1 X150 Y50 ; Corner 2
G1 X150 Y150 ; Corner 3
G1 X50 Y150 ; Corner 4
G1 X50 Y50 ; Close loop
8. Deep Insight Section
Cartesian vs. CoreXY
You might hear about "CoreXY" printers (like Voron or Bambu Lab).
- Cartesian (Ender 3, Prusa): One motor moves X, one motor moves Y. Simple.
- CoreXY: Two motors work together to move X and Y using belts in a figure-8 pattern.
Why does this matter for G-code?
It doesn't! The G-code is exactly the same. The firmware inside the printer handles the math to turn G1 X100 into motor pulses. To you, the programmer, X100 is always X100. This abstraction is powerful.
9. Common Failure Modes
- Crashing into the Bed: If you forget
G28(Home), the printer might think Z=0 is actually 10mm below the bed. It will try to drive the nozzle through the glass. Always Home first. - Grinding Noises: If you tell a 200mm printer to go to
X300, it will hit the physical end and the motor will make a terrible grinding sound. The firmware usually prevents this ("Soft Endstops"), but don't rely on it. Know your limits.
10. Real-World Application
"Center the Print"
Slicers automatically center your model. How?
They know your bed size (e.g., 200x200). The center is (100,100).
If you slice a 20mm cube, the slicer places it from X90 to X110 and Y90 to Y110.
Next time you use a slicer, look at the "Machine Settings." You will see "Bed Size X/Y." This defines the grid you are writing code for.
11. Final Clean Version
Save this as lesson2.gcode.
; Lesson 2 - The Four Corners
; Setup
G21 ; Millimeters
G90 ; Absolute Positioning
G28 ; Home All Axes
; Safety
G1 Z10 F1000 ; Lift Z, set speed (explained next lesson)
; The Tour
G1 X10 Y10 ; Front Left
G1 X190 Y10 ; Front Right (assuming 200mm bed)
G1 X190 Y190 ; Back Right
G1 X10 Y190 ; Back Left
G1 X10 Y10 ; Return
12. Stretch Challenge
Challenge: Can you make the nozzle move in a "Zig-Zag" pattern across the bed?
Start at X10 Y10, go to X190 Y10, then move up to Y20, go back to X10, etc.
Answer Key:
G1 X10 Y10
G1 X190 Y10
G1 X190 Y20
G1 X10 Y20
G1 X10 Y30
G1 X190 Y30
; ... and so on