Gcode Guide

Ultimately, your prints will be controlled via G-Code. G-Code is used in many CNC and 3D Printer situations. A proper wikipedia page can be found for it here

You shouldn't need to ever write your own G-Code files by hand, but it can be very useful to know the basics so that you can analyze problems that are coming up with your print path.

Understanding G-Code is vital to a full understanding of the Print Cycle

Introduction To G-Code

G-Code Syntax
G-Code operates on a very simple Syntax, and dates back to the early 1960s. It is simple to comprehend line by line, but impossible to visualize the final product. Here is a sample section of G-Code from a realization of the Stanford Bunny found on [www.thingiverse.com Thingiverse]

G21
G91
G1 X200.0 F3000
G1 Y200.0 F3000
G1 X-82.0 Y-76.0 F3000
G1 Z-200.0 F500
G1 Z5.0 F500
G1 Z-10.0 F250
G90
G92 X0 Y0 Z0 E0
G90
G21
 S1.0
 S2.1
M104 S190.0
M104 S188.004
 S0.004175
G1 X-20.31 Y-11.06 Z0.2 F2400.0
G1 F600.0
G1 E0.65
G1 F2400.0
G92 E0
G1 X-20.27 Y-10.75 Z0.2 F5.9648 E0.0132
G1 X-20.39 Y-10.54 Z0.2 F5.9648 E0.023
G1 X-20.5 Y-10.49 Z0.2 F5.9648 E0.0282
G1 X-20.49 Y-10.69 Z0.2 F5.9648 E0.0366
G1 X-20.53 Y-10.8 Z0.2 F5.9648 E0.0416
G1 X-20.41 Y-10.96 Z0.2 F5.9648 E0.0501
G1 X-20.34 Y-11.15 Z0.2 F5.9648 E0.0585
G1 X-20.31 Y-11.12 Z0.2 F5.9648 E0.0602
G1 X-20.31 Y-11.06 Z0.2 F5.9648 E0.0626
G1 F600.0
G1 E-0.5374
G1 F5.9648
M104 S190.0
 S2.1
G1 X-8.71 Y-6.17 Z0.5 F3000.0
G1 F600.0
G1 E0.1126
G1 F3000.0
G92 E0
G1 X-9.2 Y-5.42 Z0.5 F3000.0 E0.0377
G1 X-9.5 Y-5.27 Z0.5 F3000.0 E0.0515
G1 X-9.7 Y-4.93 Z0.5 F3000.0 E0.0683
G1 X-9.7 Y-4.72 Z0.5 F3000.0 E0.077
G1 X-9.75 Y-4.59 Z0.5 F3000.0 E0.0827
G1 X-10.33 Y-3.68 Z0.5 F3000.0 E0.1282

This may be a little bewildering at first, as I am reasonably sure you do not see a bunny. Soon you will understand how this code will come together to form beautiful prints.

G-Code is given in the Syntax COMMAND ARGUMENTS FREQUENCY. Multiple commands can be placed in one line, though this does not always make sense. Some arguments support variables. For the purposes of this tutorial, we will assume that you will not be using variables. G-Code variables will be discussed in the [slic3r-tutorial | slic3r tutorial]

Let's take a look at one of the G-Code lines in the above code snippet.

G1 X-9.2 Y-5.42 Z0.5 F3000.0 E0.0377

G1

The first statement part of the statement is the command. In this case we have G1. G1 simply means a move. What follows are the instructions for the movement.

X-9.2 Y-5.45 Z0.5
These are the arguments for the command. These give commands to the X,Y, and Z Axises. In this case it is saying "Move the X 9.2 millimeters to the left, The Y 5.42 millimeters forward, and the Z 0.5 millimeters downward."

It is worth noting that these arguments are defined in the firmware and therefore are user modifiable. This is crucial to setting up multiple extruders.

F3000

For the purposes of 3D printing these F codes refer to the frequency the motor is moving at. In the older CNC world they referred to the Feed Rate. The Feed rate is expressed in mm/minute. Therefore, in this case we are working at 3000 mm/minute. The Feedrate for the stepper motors will vary considerably over the course of the print.

E0.0377

The E code controls the amount of extrusion going on. In this case no feed rate is given, the speed is taken at default.

The start.gcode

A vital piece of G-Code to understand is the start.gcode. The start.gcode file describes the initial conditions of every print, and defines such necessities as homing behavior and coordinate systems. Here is a typical start.gcode.

G21
G91
G1 X200 F3000
G1 Y200 F3000
G1 X-82 Y-76 F3000
G1 Z-200 F500
G1 Z5 F500
G1 Z-10 F250
G90
G92 X0 Y0 Z0 E0

The start.gcode is always prepended to the g-code of the sliced file in question. The above is the start.gcode for Skeinforge as of October 3rd 2012. The command G21 sets units to millimeters, while G91 switches the printer to relative positioning mode. These are necessary for any of the following commands to work.

G1 X200 F3000
G1 Y200 F3000

These commands set in motion the homing sequence. You will notice that even though the print only has a total length and height of 150mm, we are sending the carriage 200mm to the right. This is a strategy to ensure that the print head engages the [parts-of-the-printer | Limit Switch]. The print head will move to the sides of the printer until it hits a limit switch. At this point the limit switch engages, preventing further motion and readying the printer for the next step.

G1 X-82 Y-76 F3000
G1 Z-200 F500
G1 Z5 F500
G1 Z-10 F250

This flurry of commands does the real work of homing. They relate the relative distance from the end stops to the center position. These commands also send the Z axis home to its end stop. The Final line backs the Z axis 10mm away from the end stop for smooth final flourish.

G90
G92 X0 Y0 Z0 E0

G90 Resets the printer to absolute positioning, and G91 sets the printer back to relative positioning while setting all coordinate to 0. We have now homed.

There is no real reason why the start.gcode should be altered, but some of our most notable users have suggested alterations. Feel free to add any suggested improvements you might have to the wiki.

G-Code Reference

For a more thorough G-Code reference check out the one made by RepRap community here

Improvements needed for printer convenience and function

SirBoss#1 reports that it is probable that files should contain G-Code to cause a cool down of the part after the part has finished printing. Similarly the G-Code and the PronterFace probram should be altered in order to automatically heat up the print area and when it reaches within about 7 degrees of the set temperature, the interface should execute a warm up of the print extruder head. Once the temperatures are up to optimal, the print should execute.

This is profoundly important for the needed protection against clogs and damage to the extruder. It is also important for the use convenience as well.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License