What Is the M82 G-Code in Marlin Firmware? (How to Use?)

There is no denying that G-code knowledge is an essential part of 3D printing knowledge, as every single action that the firmware of your 3D printer supports is essentially a G-code command, meaning that even the 3D printing process itself is a long list of G-code commands lined one after the other.

On the other hand, even though it’s a simple one, G-code is practically a programming language and, as a result, is not the most user-friendly thing to deal with for many 3D printing enthusiasts who aren’t familiar with programming in general, which causes most enthusiasts to be hesitant when it comes to learning it.

In today’s article, our topic will be the M82 G-Code in Marlin, in particular, which is one of the commands that we can consider to be relatively advanced, as there is some technical complexity behind the explanations of what it actually does, and why it would be necessary to use it.

So, what is the M82 G-Code command in Marlin firmware?

The M82 G-Code command in Marlin firmware sets the E-axis (extruder axis) to absolute mode, making it possible to utilize absolute positioning for all the commands related to extrusion while the X, Y, and Z axes remain in relative mode.

Moving forward, we will go through the purpose of the Marlin M82 G-code command more comprehensively, find out how to use the M82 G-code, and finally, discuss the scenarios where it would be suitable to utilize the M82 G-code command for the benefit of the 3D printing process.

What Is the M82 (E Absolute) G-Code in Marlin Firmware?

Even though the M82 G-code command isn’t one that you will need to utilize frequently, as it’s a utility command with a fairly specific purpose, there are definitely cases where knowledge about it can come in handy, making it a good idea to familiarize yourself with it.

The M82 G-code command in Marlin changes how the 3D printer interprets the values that are passed to the E value (E-axis) from relative mode to absolute mode.

When the E-axis is in absolute mode, all the values passed to the E parameter are interpreted relative to the origin point, meaning that the value should always correspond to the total amount of plastic required to be extruded at that point.

Unlike the G90 G-code command, which sets all the axes to absolute mode, the M82 G-code command only affects the E-axis and acts as an override that prevents the E-axis from going back into relative mode even when the G91 (Relative Positioning) is utilized.

To better understand how absolute mode for the E-axis exactly works, let’s start by looking at the three lines of G-code below, which are some of the first extrusion commands for a simple calibration cube when printing in E Relative mode:

G1 X101.126 Y98.551 E0.03119

G1 X101.912 Y98.039 E0.0312

G1 X102.739 Y97.597 E0.03119

Now, let’s convert these three lines to E Absolute mode:

G1 X101.126 Y98.551 E0.06237

G1 X101.912 Y98.039 E0.09357

G1 X102.739 Y97.597 E0.12476

In the first example, you will notice that the E value is always roughly 0.0312 mm, and since these lines of commands are written with the assumption that the E Relative mode is used, the 3D printer will extrude 0.0312 mm of plastic in each step.

On the other hand, in the second example, where E Absolute mode is used, you will notice that the E value increases with steps of 0.0312 mm instead, as the 3D printer will practically be subtracting the current E value from the amount of plastic that has been extruded so far to find the amount of plastic that will be extruded for the current step.

How to Use the M82 (E Absolute) G-Code in Marlin Firmware?

Even though there is some technical complexity involved in its purpose, invoking the M82 G-code command is pretty straightforward as it does not require any parameters at all.

To use the M82 G-Code command, all you will need to do is to insert “M82” in a new line that comes before the commands you require to utilize absolute positioning for the E-axis, as this will cause the E-axis to remain in the absolute mode until explicitly changed back to relative.

Since changing the mode from relative to absolute will completely change how your 3D printer interprets the value of the E parameter (amount of plastic extruded) in each extrusion command that follows, it’s vital to ensure that values are written with absolute positioning in mind.

Finally, to set the E-axis back into the relative positioning mode whenever necessary, you will need to explicitly issue the M83 (E Relative) command, as the M82 G-code overrides the G91 (Relative Positioning) command that sets all axes to relative mode and makes it ignore the E-axis if the E-axis has been set to absolute positioning with M82.

When to Use the M82 (E Absolute) G-Code in Marlin Firmware?

Having an expert understanding of when to use the M82 G-code command is practically where the difficulty comes in, as the fact that it modifies how the 3D printer interprets some G-code commands means that misusing it can easily cause your print to fail.

Technically speaking, you should never have to issue the M82 G-code command yourself (unless it’s for testing purposes), as your slicer should automatically handle this step based on whether it generated the G-code file for absolute or relative extrusion.

On that note, it’s worth mentioning that almost all modern slicers allow you to choose between relative and absolute extrusion (for instance, you can find this setting in Cura by searching for “Relative Extrusion”), and create the G-code file according to your preferences.

While there shouldn’t be any major differences between these two modes in terms of the end product, we can say that the relative mode is usually preferable for producing G-code files that are easily editable manually, whereas the absolute mode is the best option to avoid under or over-extrusion due to errors in rounding.

Wrapping Up

Even though the M82 G-code command is one that you don’t really need to know for a successful 3D printing process, understanding how it works will definitely be beneficial in expanding your 3D printing knowledge, specifically regarding reading G-code.

To quickly recap, you can use the M82 G-code command to set the E-axis to absolute mode, which will cause your 3D printer to interpret the values that are passed to the E parameter relative to the origin point of the printing process.

Alternatively, if you would like to set all of the axes to absolute mode, you will need to use the G90 G-code command instead and ensure that the E-axis isn’t overridden to be in relative mode with the M83 command.

Happy printing!