Marlin Firmware G0 / G1 / G2 / G3 G-Code Commands Explained

With the 3D printer constantly moving during the 3D printing process, the majority of a G-code file effectively consists of movement-related G-code commands, whether it’s for moving from one point to the other to start extruding a layer for the first time or following the extrusion path to finish the layer up.

In this guide, we will explain the functionality of the G0, G1, G2, and G3 G-code commands in Marlin Firmware, which practically make up all the commands you can find in Marlin that are responsible for getting your 3D printer to move on any of the axes.

What Are the G0 / G1 (Linear Move) G-Code Commands in Marlin Firmware?

In essence, both the G0 and G1 G-code commands in Marlin Firmware fulfill the purpose of linearly moving the X, Y, and Z axes by using the specified values, which effectively is what causes the printhead to move from one point to the other as the 3D printing process is taking place.

Alongside the X, Y, and Z axes, the G0 and G1 G-code commands are also responsible for controlling the E-axis (extruder), which makes it possible to get your 3D printer to both move to the desired location and extrude filament at the same time within the same G-code command whenever needed.

example g1 extrusion commands in g-code file


To move the printhead on any of the axes, the parameter you will need to pass to the G0 (or G1) G-code is the letter of the axis, followed by the position (or the distance, based on whether you’re using absolute positioning or relative positioning, with absolute positioning usually being the standard) that you would like to move the printhead to, with it being possible to combine parameters to make movements on multiple axes at once.

For instance, assuming that absolute positioning is currently active, sending the G-code command G0 X20 or G1 X20 to your 3D printer will perform a linear travel move where the printhead ends up at the X20 coordinate on the build area, with no extrusion and no movement taking place on the Y and Z axes.

octoprint g0 x20 example


Similarly, if you run the G0/G1 G-code command with multiple parameters, such as G0 X10 Y20 Z30 or G1 X10 Y20 Z30, you will find that the printhead performs a linear movement to the position X10 Y20 Z30 with all axes moving at the same time.

octoprint g0 x10 y20 z30 example


Finally, when you add the E parameter into the mix, such as running the command G0 Y100 E1 as an example, you will find that your 3D printer extrudes 1 millimeter of material as it’s moving to the Y100 position.

octoprint g0 y100 e1 example


While it’s not one that you will find yourself using frequently, the last parameter that the G0 G-code command accepts is F, which allows you to set the feed rate (which we can quickly describe as the speed at which the movement takes place) for all the subsequent moves (including this one) whenever necessary.

As an example, if you send the command G0 X100 Y100 E5 F2000 to your 3D printer, you will be moving the printhead to the X100 Y100 position, extruding 5 millimeters of filament throughout the movement, and also setting the feed rate value to 2000 millimeters per minute, meaning that the entirety of the movement (including the extrusion) will use this feed rate value.

What Are the G2 / G3 (Arc or Circle Move) G-Code Commands in Marlin Firmware?

While the purpose of the G2 and G3 G-code commands is also to move the X, Y, and Z axes of your 3D printer, these commands make it possible to make the movement in an arc or circle instead of linearly by making use of extra parameters that allow you to specify the position to be the center point of the arc.

Similar to the G0 and G1 G-code commands, the G2 and G3 G-code commands also allow you to control the E-axis in the same way to extrude filament as the movement is taking place, which, once again, makes it possible to control both movement and extrusion within a single G-code command whenever necessary.

On the other hand, unlike G0 and G1, where both commands effectively perform the same action, the behavior of G2 and G3 commands are slightly different, with the G2 G-code command triggering a clockwise arc movement, and G3 G-code command getting the printhead to move in a counter-clockwise arc instead.

To perform an arc movement with the G2 or G3 G-code command, the parameters you will need to pass are the letters of the axes you would like to move, followed by the positions (same rules as G0/G1 apply regarding absolute/relative movement), and additionally, either I and J, which respectively determine the X distance from the current X position to the center of the arc the Y distance from the current Y position to the center of the arc, or R, which determines the radius from the current XY position to the arc center.

As an example, if you send the G-code G2 X8 Y4 J-3 I4 or G2 X8 Y4 R5 while the printhead is currently at the position X2 Y6, you will find that the movement of the printhead corresponds to one that’s similar to the example illustration below (which is a rough representation rather than an exact diagram of the movement), where it will move in a clockwise arc to the destination of your choice by utilizing the specified arc center.

g2 arc movement example


On the other hand, if you used the G3 G-code command instead, such as an example of G2 X8 Y7 J3 I4 or G2 X8 Y7 R5, while the printhead is currently at the position X2 Y3, the movement of the printhead will look similar to the example illustration below, with the motion taking place in the form of a counter-clockwise arc instead.

g3 arc movement example


Up next, to get the printhead to move in complete circles with the G2 or G3 G-code command, you will need to pass the P parameter (which will only be usable if the firmware you have installed has ARC_P_CIRCLES defined in configuration) alongside others we have discussed so far, together with the number of repetitions, which will change the behavior of the command accordingly and get the printhead to draw the specified amount of circles between the initial position and the destination before finalizing the movement.

As an example, if you send the command G2 X150 Y150 P5 R5 while the printhead is currently at the position X100 Y100, you will find that your 3D printer draws five circles between the positions of X100 Y100 and X150 Y150 with a radius of 5 mm before ending its movement at X150 Y150.

Finally, similar to the G0 and G1 G-code commands, the G2 and G3 G-code commands also accept the F parameter for setting the feed rate, which is something to keep in mind if you ever find yourself at a position where you would like to make a feed rate modification for any of the movements your 3D printer will be performing.

Conclusion

While you will never need to manually send the G0, G1, G2, or G3 G-code command to your 3D printer for the purposes of printing, familiarizing yourself with some of the most commonly used G-code commands is still a great way to improve your 3D printing knowledge.

Such knowledge will especially come in handy when testing or calibrating your 3D printer, whether it’s finding out if the printhead is moving from one point to the other by the correct amount or manually extruding some filament for the purposes of purging it, as controlling your 3D printer with G-code commands through the terminal makes things much more convenient.