G-code is a language that humans use to tell a machine how to do something. With 3D printing, g-code contains commands to move parts within the printer. G-code consists of G- and M-commands that have an assigned movement or action.
The Ultimaker Github page has a list of these commands and their corresponding movements. You create a g-code by slicing a file in Cura and saving it. The saved file will be converted to g-code, the language the printer understands and uses to create a 3D print.
How are g-codes built?
A g-code contains a lot of information. If you open the g-code in a text editor, you could read the information but it would be difficult to make sense of it. You can get a better understanding of g-code by using a program such as Repetier Host. This type of program allows you to open a g-code and see the paths the print head will take to produce the print. Repetier Host uses color to indicate the code function. A free download can be found here.
11 → Indicates the line of code and is used for reference
G/M → Blue Text is a G- or M-command
Red Text defines certain parameters
F → Speed
X/Y/Z → Coordinates
E → Feeder movement
; → A semicolon behind the code is used for comment information. The comment is not part of the code.
Most g-code is automatically generated by a slicing program such as Cura. Because there are hundreds or thousands of movements involved in producing a 3D print, the g-code can be hundreds of pages long. Writing all this code manually would take many hours. Cura slices the STL files to contain all the information needed to create a 3D print. Once a file is saved, Cura converts the STL file to g-code, automating the process for you.
Programs such as Repetier Host can be used to write G-codes to create plugins for use in Cura.
Warning: Writing your own G-code can result in damage to your machine!
Every g-code is unique to the machine for which it was written. The instruction set is based on the machine. Different g-code flavors are used for different Ultimaker models. The flavors used are as follows:
- Ultimaker Original and Original+: RepRap (Marlin/Sprinter)
- Ultimaker 2 and Ultimaker 2+: UltiGCode
- Ultimaker 3: Griffin
- Ultimaker S-line: Griffin