Marlin Firmware M109 & M104 G-Code Commands – Explained

As heating the hotend up to the correct target temperature is one of the very first tasks that the firmware has to perform before starting the printing process, you will always find either the M104 or the M109 G-code command at the start (sometimes both) of any G-code file.

In this article, we will explain the functionalities of the M109 (Wait for Hotend Temperature) and M104 (Set Hotend Temperature) G-code commands in Marlin Firmware, which are effectively the two commands that offer two different ways to modify the hotend temperature of your 3D printer.

What Is the M109 (Wait for Hotend Temperature) G-Code Command in Marlin Firmware?

The M109 G-code command in Marlin firmware instructs the firmware to set the hotend temperature to the value that you have specified and also to wait until the hotend reaches the target temperature before running the following G-code command in the queue.

The most standard way to use the M109 G-code command is by using the S parameter alone, which allows you to pass the target temperature value of your choice to M109, which tells your 3D printer to wait until the hotend reaches the target temperature but only when heating, and not cooling.

So, for instance, if your hotend is already at 150 degrees Celsius, and you use the M109 S180 G-code command, your 3D printer won’t process any more G-code commands until the hotend reaches the target temperature of 180 degrees Celsius.

m109 s180 gcode in octoprint


On the other hand, if you send the M109 S120 G-code command instead, which would effectively mean that you’re cooling the hotend by bringing the temperature down to 120 degrees Celsius from 150 degrees Celsius, your 3D printer will keep processing the following G-code commands in the queue without waiting.

m109 s120 gcode in octoprint


If you would like M109 to wait for the hotend to reach the target temperature, regardless of whether it’s heating up or cooling down, the parameter you will want to use instead is R, which allows you to pass the target temperature to M109 in the same way.

This time, following our example from before where the initial hotend temperature is 150 degrees Celsius, sending either M109 R180 or M109 R120 will result in your 3D printer not processing any G-code commands in the queue until the hotend reaches the target temperature, as whether it’s heating up or cooling down won’t matter in this case.

m109 r180 gcode in octoprint

m109 r120 gcode in octoprint


Alongside the S and R parameters, one last parameter that allows you to set the hotend temperature is I, which makes it possible to pass the index of a material preset that you have created with the M145 G-code command beforehand; which contains the hotend temperature, bed temperature, and fan speed information for a particular type of filament you commonly use.

For instance, let’s assume that you have created a material preset for PLA filament by sending M145 S0 H200 B60 F255, which would effectively mean that you’re saving a material preset at the 0th index (S0) with a hotend temperature of 200 degrees Celsius (H200), a bed temperature of 60 degrees Celsius, and a 100 percent fan speed (F255).

m145 s0 h200 b60 f255 gcode in octoprint


Once you use the command M109 I0, meaning that you’re loading the data from the 0th index, M109 will automatically use the hotend temperature information found in the material preset, which will be 200 degrees Celsius based on our example, and start heating the hotend accordingly.

m109 i0 gcode in octoprint


If you have a 3D printer with multiple hotends, you will also require the T parameter when setting hotend temperatures with the M109 G-code command, which is how you select the hotend that you want the M109 command to affect.

Omitting this parameter when using M109 on a 3D printer with multiple hotends will prompt the firmware to select the currently active hotend by default.

So, as an example, if you would like to set the first hotend to 200 degrees Celsius with M109, you can use the M109 T0 S200 G-code command, which would mean that you’re telling the firmware to set the hotend with the index 0 (second hotend would be index 1) to 200 degrees Celsius.

m109 t0 s200 gcode in octoprint


Finally, the last two parameters you can use with M109 are F and B, where the former enables the auto-temperature (AUTOTEMP) feature, and the latter allows you to pass the maximum auto-temperature value of your choice to the command.

As an example, if you send the command M109 F S200 B220, you would effectively be telling the firmware to wait until the hotend reaches the target temperature of 200 degrees Celsius and to enable the auto-temperature feature with a maximum temperature limit of 220 degrees Celsius.


Provided that the firmware you’re using has EMERGENCY_PARSER enabled in the configuration, you can use the M108 G-code command to break out of the wait caused by M109, which won’t cancel the heating but will cause your 3D printer to process the G-code commands regardless of whether the hotend has reached the target temperature.

What Is the M104 (Set Hotend Temperature) G-Code Command in Marlin Firmware?

The M104 G-code command in Marlin firmware also tells the firmware to set the hotend temperature to the value you have specified, but unlike M109, where the firmware waits until the hotend reaches the target temperature before running the following G-code command, the command queue will continue as usual as the hotend is heating up.

Similar to M109, the standard way of using the M104 G-code command is also to utilize the S flag to pass the target temperature value of your choice to M104, which practically tells your 3D printer to start heating the hotend up to the target temperature while also allowing you to send other G-code commands to it, whether it’s moving the printhead or starting to heat the print bed as well.

For instance, if you start out with a hotend temperature of 150 degrees Celsius and use the M109 S180 G-code command, your 3D printer will start heating the hotend up to 180 degrees Celsius and keep running any other tasks in the command queue as the hotend is heating up to the target temperature.

m104 s180 gcode in octoprint


For more information about the rest of the parameters that M104 accepts, which are practically all the parameters that you can use with M109, with the exception of R (leaving B, F, I, and T), we recommend referring to the previous section where we have explained everything in detail, as the behaviors of these parameters are entirely the same for both M104 and M109.

As an example, if you use the command M104 I0 T0, you will be telling the firmware to set the first hotend temperature to the target temperature value found in the material preset 0, just as how it works for the M109 G-code command, but with the exception of the 3D printer not waiting for the hotend to reach the target temperature.

m104 i0 t0 gcode in octoprint


Similarly, if you use the command M104 F S200 B220, the same as our M109 example from the last section, you will be telling the firmware to heat the hotend up to 200 degrees Celsius and to enable the auto-temperature feature with a maximum temperature limit of 220 degrees Celsius, but once again, with the the 3D printer not waiting for the hotend to reach the target temperature to process the following G-code commands in the queue.


Conclusion

While both the M104 and the M109 G-code command serve the purpose of modifying the hotend temperature, the fact that one of them causes the G-code command queue to wait while the other doesn’t gives the two commands different usage areas.

While M109 alone is technically enough by itself to get the hotend print-ready, M104 makes it possible to write a more time-optimized start G-code block where your 3D printer can get other preparation tasks out of the way before having to wait for the hotend to be heated up and ready for extrusion.