<p>As Mark said, Marlin supports a number of menu items in it's advanced configuration. These items are meant to run custom G-code, which in this case (adding a preheat action with custom target extruder and bed temp) is enough to fill your needs. So, let's see that advanced configuration file: Configuration_adv.h. The section we are looking for is almost at the end of the file, you can ctrl+f for "CUSTOM_USER_MENUS" to find it.</p>

<pre><code>#define CUSTOM_USER_MENUS
#if ENABLED(CUSTOM_USER_MENUS)
  #define USER_SCRIPT_DONE "M117 User Script Done"
  #define USER_SCRIPT_AUDIBLE_FEEDBACK
  //#define USER_SCRIPT_RETURN  // Return to status screen after a script

  #define USER_DESC_1 "Do the trick"
  #define USER_GCODE_1 "G91\nG0 z5\nG0 y10"

  #define USER_DESC_2 "Park"
  #define USER_GCODE_2 "G27 P2"

  //#define USER_DESC_2 "Preheat for PLA"
  //#define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND)

  //#define USER_DESC_3 "Preheat for ABS"
  //#define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND)

  //#define USER_DESC_4 "Heat Bed/Home/Level"
  //#define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29"

  //#define USER_DESC_5 "Home &amp; Info"
  //#define USER_GCODE_5 "G28\nM503"
#endif
</code></pre>

<p>The source code downloaded from the official repo actually comes with some examples (the ones commented) and I added two more just for fun. 
To get your custom preheat menu item working you'll make use of the following Gcodes:</p>

<ul>
<li>M140: set target bed temperature (visit
<a href="http://marlinfw.org/docs/gcode/M140.html" rel="nofollow noreferrer">http://marlinfw.org/docs/gcode/M140.html</a> for some more data)</li>
<li>M104: set hot end target temperature (visit
<a href="http://marlinfw.org/docs/gcode/M104.html" rel="nofollow noreferrer">http://marlinfw.org/docs/gcode/M104.html</a> for some more data)</li>
</ul>

CC BY-SA 4.0
2019-11-25T13:15:13.563Z
2019-11-27T08:41:16.547Z
2019-11-27T08:41:16.547Z
Marcelo Nicolás Obachi
<p>The supplement on how to proceed with custom menus in practice:</p>
<p>Enable (uncomment) this line in <code>configuration_adv.h</code>:</p>
<pre><code>#define CUSTOM_USER_MENUS  
</code></pre>
<p>Below there are 5 sample entries, later you can change them or remove/comment out.
You can add new, for example:</p>
<pre><code>  #define  USER_DESC_6 &quot;Home Z (0.2)&quot;
  #define USER_GCODE_6 &quot;G28 Z\nG0 Z0.2&quot;

  #define  USER_DESC_7 &quot;Fan on&quot;
  #define USER_GCODE_7 &quot;M106 S255&quot;

  #define  USER_DESC_8 &quot;Fan off&quot;
  #define USER_GCODE_8 &quot;M107&quot;
</code></pre>
<p>Marlin currently (v2.0.7.2) supports up to 25 menu items (see menu_custom.cpp). There may be gaps in these numbers, so you can comment out some unnecesary options without fixing numbering of others, which could be really convenient.</p>
<p>Custom commands can be executed in runtime (when already printing). I could use the above &quot;home Z&quot; after manually tuning Z endstop to correct first layer's height quickly, without restarting the print. So you can actually make harm to ongoing print as well.</p>

CC BY-SA 4.0
2021-01-05T22:29:52.713Z
2021-01-06T08:05:07.270Z
2021-01-06T08:05:07.270Z
octopus8
<p>There might be a better solution. </p>

<p>Marlin supports custom user menus, in <code>configuration_adv.h</code>, you probably should try to keep your changes limited to the <code>configuration*.h</code> files.  </p>

<p>The menu code is kind of ugly and you can easily break things.  </p>

CC BY-SA 4.0
2019-10-22T18:11:00.170Z
Hi Mark and welcome to SE.3DP! That sounds like a good point to be made. Could you provide a snippet of the code? I haven't looked myself, and maybe it is too large to summarise, but if you could edit your answer and show a part of the code and illustrate how/where to insert, that would be a great addition to the answer.
Greenonline
CC BY-SA 4.0
2019-10-22T15:16:24.030Z
2019-10-22T16:57:25.470Z
2019-10-22T16:57:25.470Z
Mark
<p>Preheat Constants - Up to 5 are supported without changing the code just add a new one and then build</p>
<pre><code>#define PREHEAT_1_LABEL       &quot;PLA&quot;
#define PREHEAT_1_TEMP_HOTEND 215
#define PREHEAT_1_TEMP_BED     70
#define PREHEAT_1_TEMP_CHAMBER 35
#define PREHEAT_1_FAN_SPEED     0 // Value from 0 to 255

#define PREHEAT_2_LABEL       &quot;PETG&quot;
#define PREHEAT_2_TEMP_HOTEND 235
#define PREHEAT_2_TEMP_BED    70
#define PREHEAT_2_TEMP_CHAMBER 35
#define PREHEAT_2_FAN_SPEED     0 // Value from 0 to 255

#define PREHEAT_3_LABEL       &quot;ABS&quot;
#define PREHEAT_3_TEMP_HOTEND 270
#define PREHEAT_3_TEMP_BED    100
#define PREHEAT_3_TEMP_CHAMBER 35
#define PREHEAT_3_FAN_SPEED     0 // Value from 0 to 255

#define PREHEAT_4_LABEL       &quot;NYLON&quot;
#define PREHEAT_4_TEMP_HOTEND 260
#define PREHEAT_4_TEMP_BED     65
#define PREHEAT_4_TEMP_CHAMBER 35
#define PREHEAT_4_FAN_SPEED     0 // Value from 0 to 255
<span class="math-container">```</span>
</code></pre>

CC BY-SA 4.0
2022-04-05T18:06:29.960Z
Hi Bruce welcome to 3DPrinting.SE! Thanks for revisiting the question, yes, it is much easier now in Marlin 2.x as other answers have already pointed out. The question is raised for Marlin 1.1.9, so this answer doesn't technically answer the question for the OP, please [edit] the question to include that in Marlin 2 it is much easier to add custom preheat menu items. Also link to the code section where the preheat examples are found. Thanks!
0scar
CC BY-SA 4.0
2022-04-05T15:05:29.620Z
2022-04-05T17:51:21.770Z
2022-04-05T17:51:21.770Z
Bruce Falkenstein
<p>The answer to your question (baring in mind that the question is raised for Marlin 1.1.9) is the file <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/ultralcd.cpp" rel="nofollow noreferrer">ultralcd.cpp</a>. Nowadays, you can also enable extra option through the <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/Configuration_adv.h#L1546" rel="nofollow noreferrer">Configuration_adv.h</a> file, just enable:</p>
<pre><code>#define CUSTOM_USER_MENUS
</code></pre>
<p>and edit the options beneath it to your needs (otherwise it will use the preset values from the <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/Configuration.h#L1255" rel="nofollow noreferrer">Configuration.h</a> file).</p>
<hr />
<p><strong>Add custom items using ultralcd.cpp</strong></p>
<p>This is how I used to do it if you want to add items to the menu in Marlin Firmware through the ultralcd.cpp. It is best to first look at the current implementation of the menu items. As you already mention <code>Preheat PLA</code>, that would be the first to search for. Searching in files is easy when you go to the github website with the Marlin firmware sources, functionality is available for searching in the files. Alternatively, download a copy of the firmware and use a free &quot;grep&quot; utility to search in files.</p>
<p>Searching for <code>Preheat PLA</code> will show you a bunch of language translation files. These point to the use of a constant <code>MSG_PREHEAT_1</code> which finds its presence in <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/ultralcd.cpp" rel="nofollow noreferrer">ultralcd.cpp</a>. This hints to function <code>lcd_preheat_m1_menu</code> that is called by <code>MENU_ITEM</code> which adds menu items to LCD. You could start there to add your own option.</p>
<hr />
<p><strong>Demonstration</strong></p>
<p>As a quick demonstration, I've added a <code>CUSTOM PREHEAT</code> item by copying the <code>lcd_preheat_m2_menu</code> function in <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/ultralcd.cpp" rel="nofollow noreferrer">ultralcd.cpp</a> and renamed this <code>lcd_preheat_m3_menu</code> (a full functional item needs changes within the <code>lcd_preheat_m3_menu</code> as it now uses the constants from the ABS preheat option).</p>
<p>You then add the item to the menu by changing this part of the code:</p>
<pre>
      //
      // Preheat for Material 1 and 2
      //
      #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || HAS_HEATED_BED
        MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
        MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
        // ADD THIS LINE:
        MENU_ITEM(submenu, "CUSTOM PREHEAT", lcd_preheat_m3_menu);
      #else
        MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
        MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
      #endif
</pre>
<p>After compiling and uploading to the printer board, enter the <code>Prepare</code> menu and scroll down to see:</p>
<p><a href="https://i.sstatic.net/X5eUD.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/X5eUD.jpg" alt="LCD showing custom preheat option" /></a></p>

CC BY-SA 4.0
2018-12-22T07:43:31.107Z
2022-04-05T18:24:40.420Z
2022-04-05T18:24:40.420Z
0scar
<p>Where is the correct Marlin firmware file and location to add code that I want to shop up in the LCD menu of my printer, and then execute the function I write when the button is pressed?</p>

<p>For example I want to add a menu item that says "Preheat Custom" that is in the same menu as "preheat PLA" and "preheat ABS" and then runs code to heat to values I specify.</p>

<p><em>I'm running Marlin Firmware version 1.1.9 on a Creality Ender 3.</em></p>

<marlin><firmware>
How to add menu options to the (Marlin firmware) LCD menu?
cds333
# How to add menu options to the (Marlin firmware) LCD menu?

(Asked by: username_0 on 2018-12-17)

Where is the correct Marlin firmware file and location to add code that I want to shop up in the LCD menu of my printer, and then execute the function I write when the button is pressed?

For example I want to add a menu item that says "Preheat Custom" that is in the same menu as "preheat PLA" and "preheat ABS" and then runs code to heat to values I specify.

*I'm running Marlin Firmware version 1.1.9 on a Creality Ender 3.*

**Tags:** marlin, firmware

---

## 5 answers

### Answer by username_6 on 2018-12-22. Score: 9 | Accepted answer

The answer to your question (baring in mind that the question is raised for Marlin 1.1.9) is the file ultralcd.cpp. Nowadays, you can also enable extra option through the Configuration_adv.h file, just enable:
#define CUSTOM_USER_MENUS

and edit the options beneath it to your needs (otherwise it will use the preset values from the Configuration.h file).

Add custom items using ultralcd.cpp
This is how I used to do it if you want to add items to the menu in Marlin Firmware through the ultralcd.cpp. It is best to first look at the current implementation of the menu items. As you already mention Preheat PLA, that would be the first to search for. Searching in files is easy when you go to the github website with the Marlin firmware sources, functionality is available for searching in the files. Alternatively, download a copy of the firmware and use a free "grep" utility to search in files.
Searching for Preheat PLA will show you a bunch of language translation files. These point to the use of a constant MSG_PREHEAT_1 which finds its presence in ultralcd.cpp. This hints to function lcd_preheat_m1_menu that is called by MENU_ITEM which adds menu items to LCD. You could start there to add your own option.

Demonstration
As a quick demonstration, I've added a CUSTOM PREHEAT item by copying the lcd_preheat_m2_menu function in ultralcd.cpp and renamed this lcd_preheat_m3_menu (a full functional item needs changes within the lcd_preheat_m3_menu as it now uses the constants from the ABS preheat option).
You then add the item to the menu by changing this part of the code:

      //
      // Preheat for Material 1 and 2
      //
      #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || HAS_HEATED_BED
        MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
        MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
        // ADD THIS LINE:
        MENU_ITEM(submenu, "CUSTOM PREHEAT", lcd_preheat_m3_menu);
      #else
        MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
        MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
      #endif

After compiling and uploading to the printer board, enter the Prepare menu and scroll down to see:


---

### Answer by username_1 on 2019-11-25. Score: 2

As Mark said, Marlin supports a number of menu items in it's advanced configuration. These items are meant to run custom G-code, which in this case (adding a preheat action with custom target extruder and bed temp) is enough to fill your needs. So, let's see that advanced configuration file: Configuration_adv.h. The section we are looking for is almost at the end of the file, you can ctrl+f for "CUSTOM_USER_MENUS" to find it.
#define CUSTOM_USER_MENUS
#if ENABLED(CUSTOM_USER_MENUS)
  #define USER_SCRIPT_DONE "M117 User Script Done"
  #define USER_SCRIPT_AUDIBLE_FEEDBACK
  //#define USER_SCRIPT_RETURN  // Return to status screen after a script

  #define USER_DESC_1 "Do the trick"
  #define USER_GCODE_1 "G91\nG0 z5\nG0 y10"

  #define USER_DESC_2 "Park"
  #define USER_GCODE_2 "G27 P2"

  //#define USER_DESC_2 "Preheat for PLA"
  //#define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND)

  //#define USER_DESC_3 "Preheat for ABS"
  //#define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND)

  //#define USER_DESC_4 "Heat Bed/Home/Level"
  //#define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29"

  //#define USER_DESC_5 "Home & Info"
  //#define USER_GCODE_5 "G28\nM503"
#endif

The source code downloaded from the official repo actually comes with some examples (the ones commented) and I added two more just for fun. 
To get your custom preheat menu item working you'll make use of the following Gcodes:

M140: set target bed temperature (visit
http://marlinfw.org/docs/gcode/M140.html for some more data)
M104: set hot end target temperature (visit
http://marlinfw.org/docs/gcode/M104.html for some more data)


---

### Answer by username_2 on 2021-01-05. Score: 2

The supplement on how to proceed with custom menus in practice:
Enable (uncomment) this line in configuration_adv.h:
#define CUSTOM_USER_MENUS  

Below there are 5 sample entries, later you can change them or remove/comment out.
You can add new, for example:
  #define  USER_DESC_6 "Home Z (0.2)"
  #define USER_GCODE_6 "G28 Z\nG0 Z0.2"

  #define  USER_DESC_7 "Fan on"
  #define USER_GCODE_7 "M106 S255"

  #define  USER_DESC_8 "Fan off"
  #define USER_GCODE_8 "M107"

Marlin currently (v2.0.7.2) supports up to 25 menu items (see menu_custom.cpp). There may be gaps in these numbers, so you can comment out some unnecesary options without fixing numbering of others, which could be really convenient.
Custom commands can be executed in runtime (when already printing). I could use the above "home Z" after manually tuning Z endstop to correct first layer's height quickly, without restarting the print. So you can actually make harm to ongoing print as well.


---

### Answer by username_3 on 2019-10-22. Score: 1

There might be a better solution.

Marlin supports custom user menus, in `configuration_adv.h`, you probably should try to keep your changes limited to the `configuration*.h` files.

The menu code is kind of ugly and you can easily break things.

> **Comments:**
> **username_4**: Hi Mark and welcome to SE.3DP! That sounds like a good point to be made. Could you provide a snippet of the code? I haven't looked myself, and maybe it is too large to summarise, but if you could edit your answer and show a part of the code and illustrate how/where to insert, that would be a great addition to the answer.  

---

### Answer by username_5 on 2022-04-05. Score: 0

Preheat Constants - Up to 5 are supported without changing the code just add a new one and then build
#define PREHEAT_1_LABEL       "PLA"
#define PREHEAT_1_TEMP_HOTEND 215
#define PREHEAT_1_TEMP_BED     70
#define PREHEAT_1_TEMP_CHAMBER 35
#define PREHEAT_1_FAN_SPEED     0 // Value from 0 to 255

#define PREHEAT_2_LABEL       "PETG"
#define PREHEAT_2_TEMP_HOTEND 235
#define PREHEAT_2_TEMP_BED    70
#define PREHEAT_2_TEMP_CHAMBER 35
#define PREHEAT_2_FAN_SPEED     0 // Value from 0 to 255

#define PREHEAT_3_LABEL       "ABS"
#define PREHEAT_3_TEMP_HOTEND 270
#define PREHEAT_3_TEMP_BED    100
#define PREHEAT_3_TEMP_CHAMBER 35
#define PREHEAT_3_FAN_SPEED     0 // Value from 0 to 255

#define PREHEAT_4_LABEL       "NYLON"
#define PREHEAT_4_TEMP_HOTEND 260
#define PREHEAT_4_TEMP_BED     65
#define PREHEAT_4_TEMP_CHAMBER 35
#define PREHEAT_4_FAN_SPEED     0 // Value from 0 to 255
```

> **Comments:**
> **username_6**: Hi Bruce welcome to 3DPrinting.SE! Thanks for revisiting the question, yes, it is much easier now in Marlin 2.x as other answers have already pointed out. The question is raised for Marlin 1.1.9, so this answer doesn't technically answer the question for the OP, please [edit] the question to include that in Marlin 2 it is much easier to add custom preheat menu items. Also link to the code section where the preheat examples are found. Thanks!  

---

