Nowadays, almost all 3D printers operate on a programming language that consists of a series of commands known as the g code. But, do you know how to write a g code for a 3D printer? It’s okay if you don’t because most of the 3D printers already have the g code automated. Through this article, we aim to give you a brief understanding of the g code and help you unlock a whole new level of 3D printing
What is g code?
G code refers to a programming language used by a computer, that communicates all the commands that are needed for movement and other important functions. Think of it as sequential lines instructing the printer to perform a specific task. The printer will execute these commands one by one until the end of the code. The g code is generated automatically in a 3D printer but if you want to dive deeper into the world of 3D printing then knowing the basics of g code is necessary.
The ‘g’ in g code stands for the general command. G command lines are in charge of the different types of motions in the 3D printer. They are also responsible for controlling the three-plus axes movement that is performed by the printhead and filament extrusion.
Another command is the Miscellaneous command. These commands are responsible for running the non-geometric tasks which include fan control, heating commands for the bed and the nozzle, etc.
Popular commands in g code
Before we begin, know that every g code follows a certain syntax. Every line corresponds to a single command. The line begins with the command code itself which can either be a G or an M code. The code is followed by a number that is unique to that command and identifies it. Also, Each command has its own unique parameters.
G0 & G1: Linear motion
G0 and G1 correspond to linear movements. G0 further represents the non-extrusion movements such as initial and travel moves. G1 includes extruding linear motion. Both these commands function in the same way. The parameters include final positions for all the axes, the intensity of extrusion during the move, and speed.
G1 X80 Y60 Z0.25 F200 E1
Will command the printer to move forward in a straight line (G1) to the final coordinates i.e., X = 80 mm, Y = 60 mm, Z = 0.25 mm. The feed rate (F) is 200 mm/min when the printer is extruding (E) with 1 mm of material in the extruder.
G90 & G91: Absolute and Relative Positioning
These commands tell the printer how to interpret the commands for movement. G90 controls absolute positioning (usually default) while G91 establishes relative positioning. These commands do not require any parameters. For example, in absolute positioning, you want to move the printhead to X=20. The code will be-
G90; sets absolute positioning
G0 X30; moves to the X = 30 coordinate
For relative positioning, we need to know the current positioning of the printhead. Let’s say it is at X = 20
G91; sets relative positioning
G0 X20; moves +10mm along the X-axis
So here G91 tells the printer that it is a relative positioning command and that the printer only needs to move 10 mm to reach 30mm.
G28 & G29 Auto Home and Bed Levelling
The G 28 command is responsible for homing i.e., setting the physical limits of axes. Homing helps the printer orient itself and prevent it from printing outside the boundaries. For example, you can home-specific axes as parameters or G28 will home all the axes.
G28 X Y; home the X Y axes only
G29 command controls the automatic bed leveling sequence. We won’t get into the details as this is usually accomplished by the firmware.
M104, M109: Set temperature
These are miscellaneous commands that don’t involve any motion. The M104 sets a specific temperature that the hot end has to reach until instructed otherwise. The parameters include the actual temperature value and the printhead to be heated. M109 is used if you want to wait until the temperature is reached before you move on to the next line.
M106 & M107: Fan control
Fan control is a crucial task for 3D printers and is controlled by miscellaneous command M106 which turns on the fan and sets its speed. The speed parameter is a value that must lie between 0 to 225.
1. What is g code in 3D printing?
G code refers to a programming language used by a computer, that communicates all the commands that are needed for movement and other important functions.
2. How to use g code for 3D printers?
G code has a certain syntax. Every line corresponds to a single command. The line begins with the command code itself which can either be a G or an M code. The code is followed by a number that is unique to that command and identifies it. Also, Each command has its own unique parameters.
3. How to write 3D printer code?
You can use text editing software like Cura or Simplify3D. This software already has some parameters written in the comments.