What Is the M112 G-Code in Marlin? (How to Fix M112 Errors?)

G-code is the most widely used programming language used in 3D printer firmware, responsible for having instructions for all the actions the printer can perform, ranging from heating the extruder up to moving the printhead.

Even if you don’t regularly use G-code, furthering your knowledge about it is a fantastic way to have more control over the 3D printing process, especially when you need to deal with an issue that causes your prints to fail.

Today, our topic will be the M112 G-code in Marlin firmware, a command often associated with the printer experiencing unexpected errors.

So, what is the M112 G-code in Marlin firmware?

M112 is the Emergency Stop G-code in Marlin firmware, which immediately shuts the printer down and turns the heaters, the steppers, and the power supply off.

When the printer is shut down using the M112 G-code, it needs to be reset before it can become operational again.

Moving forward, we will analyze the M112 G-code in greater detail, find out the factors that can trigger an M112 shutdown, and what you can do to fix the M112 shutdown problem.

What Is the M112 G-Code in Marlin Firmware?

The M112 G-code is slightly different from most G-code commands we are familiar with, as it’s not a command that belongs in the standard process of 3D printing.

M112 (Emergency Stop) is a G-code command that instantly halts the printing process and completely shuts the 3D printer down by turning the heaters, the steppers, and the power supply off.

When your 3D printer is shut down due to the M112 G-code being issued, the only way to make your printer operational again is to reset it restart the printing process.

The fastest way to shut a printer down through G-code is with the M112 G-code, as when combined with the EMERGENCY_PARSER flag in Marlin firmware, the firmware won’t even wait for the command queue to be clear before executing the command.

That being said, M112 isn’t a command that you should use but rather one that the firmware issues when it runs into an error that it can’t recover from, as the only choice in such a case is to reset the 3D printer, and hence, reinitialize the firmware.

What Causes an M112 Shutdown?

While an M112 shutdown is a surefire sign that something has gone wrong with the 3D printing process, finding the culprit that triggered the shutdown isn’t always straightforward.

An M112 shutdown is a result of the 3D printer firmware encountering an error that it cannot prevent, where the firmware immediately shuts the printer down to avoid damage to the printer or its surroundings.

Even though many factors can trigger an M112 shutdown, we highly recommend taking it as a serious (even though it may also be something very simple) sign and finding the culprit before continuing to print with your 3D printer.

Here are some of the things that can cause an M112 shutdown to take place:

  • Incorrectly configured end-stop switches
  • Auto bed leveling failure
  • Nozzle or bed heating failure
  • Incorrectly installed auto bed leveling sensor (such as BLTouch)
  • Bugs within the firmware
  • Mechanical problems with the 3D printer

As you can see, the common theme between these errors is that the 3D printing process cannot continue, and even though this list isn’t even close to being exhaustive by any means, it should give you an idea of how the M112 shutdown works.

How to Fix an M112 Shutdown?

While fixing an M112 shutdown is primarily about finding the root cause, the process can become hopeless sometimes, especially if you have no prior experience.

While we can’t give any guarantees, here are some of the cookie-cutter solutions that cover the most common culprits behind M112 shutdowns, which should hopefully resolve your issue:

  • Remove the auto bed leveling sensor if you use one, and try printing without it.
  • Update and re-flash the firmware.
  • Check and ensure that you have configured the endstop switches correctly.
  • Level the build plate manually.
  • Undo any changes you have made to the hotend or the board.

Can an Auto Bed Leveling Probe (BLTouch) Cause an M112 Shutdown?

We have noticed that many members of the community experience M112 shutdown issues after installing an auto bed leveling probe, such as the BLTouch.

An incorrectly configured auto bed leveling probe, such as BLTouch, is one of the primary culprits behind an M112 shutdown, with many members of the community reporting similar problems.

As the culprit can range anywhere from the probe not being plugged in properly to setting the offsets wrongly, we highly recommend running a test print without the auto bed leveling probe and observing if an M112 shutdown takes place.

While removing the probe is not a solution, it will help you understand whether it was the culprit or not and narrow the list of culprits that may be causing the issue.

Octoprint Triggers M112 Shutdowns Frequently – What to Do?

There are many reports from OctoPrint users about experiencing M112 shutdowns very frequently, which actually has a simple explanation and solution.

OctoPrint’s error handling settings are by default configured to cancel the printing process and issue an M112 shutdown for any error (including false positives at times), even if it’s not a fatal one.

To change the error handling settings and instruct OctoPrint to stay connected to the printer unless the error is fatal, follow the steps below:

  1. Navigate to the Serial Connection page in the Printer menu.
  2. Switch to the Behavior tab.
  3. Choose the Cancel any ongoing prints but stay connected to the printer option instead of Disconnect from the printer.

With the error handling set to the Cancel any ongoing prints but stay connected to the printer option, a non-fatal error will only cause OctoPrint to cancel the task without issuing an M112 shutdown.

Wrapping Up

There is no denying that experiencing an M112 shutdown can be highly disappointing due to its vagueness, with the possibility of so many factors being responsible for the issue.

To quickly recap, M112 is the G-code command for triggering an emergency shut down of the 3D printer, where the steppers, the heaters, and the power supply will be immediately turned off.

If your printer has shut down with the M112 G-code, you will need to reset it to make it operational once again.

Please note that M112 isn’t the default way to shut a 3D printer down and is only issued when an error that the printer cannot recover from is present.

Happy printing!