<h3><code>ultralcd.cpp</code></h3>
<p>Maybe, just <em>maybe</em>, this <a href="https://github.com/MarlinFirmware/Marlin/issues/10394#issuecomment-381153626" rel="nofollow noreferrer">post</a> from <a href="https://github.com/MarlinFirmware/Marlin/issues/10394" rel="nofollow noreferrer">how to add a physical button to extruder motor control? #10394</a> could help (the emphasis is mine):</p>
<blockquote>
<p>rather than directly work on stepper.cpp, <em><strong>I would rather suggest to take a look at the LCD control part</strong></em>, and integrate an emulation of the prepare/move/Z-axis code. As for accessible pins, perhaps use any unused endstop ones ?</p>
</blockquote>
<p>This would make sense, as it is similar to the location (i.e. file(s)) that required changing for 0scar's question <a href="https://3dprinting.stackexchange.com/q/6778/4762">Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?</a>. The file in that case was <code>ultralcd.cpp</code> (see my <a href="https://3dprinting.stackexchange.com/a/6801/4762">answer</a>).</p>
<p>However, <code>ultralcd.cpp</code> seems to have been either removed, moved or renamed to <a href="https://github.com/MarlinFirmware/Marlin/blob/2.0.x/Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp" rel="nofollow noreferrer"><code>ultralcd_st7920_u8glib_rrd_AVR.cpp</code></a>. It doesn't look hopeful. Previously it was in a 3rd part bugfix, see <a href="https://3dprinting.stackexchange.com/a/10783/4762">this answer</a>, and the link of <em>that</em> <code>ultralcd.cpp</code> is now dead.</p>
<h3>Keypads code</h3>
<p>Alternatively, this <a href="https://github.com/MarlinFirmware/Marlin/issues/10394#issuecomment-468987287" rel="nofollow noreferrer">post</a> helpfully suggests:</p>
<blockquote>
<p>This is not a feature we would add. But it's possible to do movement with buttons by hooking into the LCD code and following the technique currently used for the KEYPADs.</p>
</blockquote>
<p>So, that would seem to be a promising place to start. I'm not (currently) sure which file(s) that is though. It might be the code that handles the RepRapWorld keypad (see below).</p>
<h3>RepRapWorld keypad</h3>
<p>This could also be useful, the RepRapWorld <a href="https://reprap.org/wiki/Keypad" rel="nofollow noreferrer">Keypad</a>:</p>
<blockquote>
<p>Hook it up to your RAMPS AUX-2 port. Configure the firmware to use the keypad. The keypad is fully supported in Marlin Firmware.</p>
</blockquote>
<p>You could emulate (i.e. reverse engineer) this piece of simple hardware (the most complex IC on it is just a shift register) and use the already built in code.</p>
<p>FWIW, a similar sounding (9 button) keypad is referenced here, <a href="https://www.reddit.com/r/Reprap/comments/g0z940/adding_custom_keypad_marlin/" rel="nofollow noreferrer">Adding custom keypad, marlin</a></p>
<p>However, upon further reading, it is unclear whether the RepRapWorld keypad is still supported, see <a href="https://github.com/MarlinFirmware/Marlin/issues/1142" rel="nofollow noreferrer">Feature request: add suppport for reprapworld keypad #1142</a>. Apparently RepRapWorld didn't (6 years ago) support it nor supply the source and expected the Marlin coders to support it for free.</p>
<h3>Other references and links</h3>
<p>Nevertheless, the following <a href="https://github.com/MarlinFirmware/Marlin/issues/10394#issuecomment-465536635" rel="nofollow noreferrer">post</a> also suggests other sources of information that could be of use:</p>
<blockquote>
<p>For best results getting help with configuration and troubleshooting,
please use the following resources:</p>
<ul>
<li>RepRap.org <a href="http://forums.reprap.org/list.php?415" rel="nofollow noreferrer">Marlin Forum</a></li>
<li><a href="https://discuss.toms3d.org/" rel="nofollow noreferrer">Tom's 3D Forums</a></li>
<li>Facebook Group <a href="https://www.facebook.com/groups/1049718498464482/" rel="nofollow noreferrer">&quot;Marlin Firmware&quot;</a></li>
<li>Facebook Group <a href="https://www.facebook.com/groups/3Dtechtalk/" rel="nofollow noreferrer">&quot;Marlin Firmware for 3D Printers&quot;</a></li>
<li><a href="https://www.youtube.com/results?search_query=marlin%20configuration" rel="nofollow noreferrer">Marlin Configuration</a> on YouTube</li>
<li>Marlin Discord server. Join link: <a href="https://discord.gg/n5NJ59y" rel="nofollow noreferrer">https://discord.gg/n5NJ59y</a></li>
</ul>
<p>After seeking help from the community, if the consensus points to to a
bug in Marlin, then you should post a bug report.</p>
</blockquote>
<p>It should be noted that, as a rule, the Marlin people prefer potential issues to be discussed on the Firmware Forum <strong>first</strong>, <em>before</em> any bug report or feature request is submitted to Github. This is to stop their Github issues page for getting too cluttered.</p>
<p>Also note that <em>Tom's 3D Forums</em> are now dead.</p>
<p>See also <a href="https://reprap.org/forum/read.php?146,181251" rel="nofollow noreferrer">Marlin/ LCD-Keypad Code Mod</a>, although the thread seems to consist mostly of posts bemoaning software maintenance and life-cycles, and then sort of loses steam and dies at the end. However, this <a href="https://reprap.org/forum/read.php?146,181251,269518#msg-269518" rel="nofollow noreferrer">post</a> mentions <code>uiconfing.h</code> or <code>ui.h</code>.</p>

CC BY-SA 4.0
2021-09-05T20:15:05.337Z
It should be easy to add a button according to https://www.thingiverse.com/thing:4932876, it uses a button and macros to (un)load filament. Although this is for RepRap firmware, it might work for Marlin also.
0scar
CC BY-SA 4.0
2021-09-05T17:38:57.083Z
2021-09-06T04:56:42.507Z
2021-09-06T04:56:42.507Z
Greenonline
<p>I have a 3D printer with MKS Robin mainboard + TMC2209.</p>
<p>How do I add a piece of code to Marlin, for example, to make a physical button to start preheating, etc. I would like to use the existing mainboard, I don't want to use OctoPrint.</p>
<p>I have basic knowledge of Arduino programming. I could easily write the software to run the function on a button press but I cannot find how to integrate it into Marlin.</p>

CC BY-SA 4.0
2021-09-05T15:02:29.473Z
Hi and a very warm welcome to SE.3DP! Personally, as a keen Arduino tinkerer myself, I *really* like your question and I would like to know the answer as well. However, unfortunately, I think that this may be off-topic here as it is more about SW dev than 3D printing related. It'd be better to ask on the [Marlin firmware forum](https://reprap.org/forum/list.php?415), or raise a feature request on [Github repository](https://github.com/MarlinFirmware/Marlin). However, the latter might be either very slow or not elicit much of a response as they are very busy people - it's worth a try though.
Greenonline
CC BY-SA 4.0
2021-09-05T15:04:15.360Z
Alternatively, you could take a few weeks out and try to become familiar with the Marlin source code yourself, and code it yourself - which is certainly not within the realms of impossibility.  I would also say that SE.Arduino probably isn't the place to ask either. Maybe the Arduino forums, but again, it might not get much of a response, although probably a better response than on Stack Exchange - the reason being that adding code to firmware is not a simple Q&A issue, but rather a long winded discussion. All in all, the Marlin forum is probably the best place to start. Good luck..! :-)
Greenonline
CC BY-SA 4.0
2021-09-05T17:23:54.827Z
I thought that this (firmware modification) had already been asked but I can't *really* find the question that I remember... It might have been 0scar's question, [Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?](https://3dprinting.stackexchange.com/q/6778/4762), and also of interest (although it recommends OctoPrint) is [How to make physical buttons send G-code?](https://3dprinting.stackexchange.com/q/7713/4762)
Greenonline
<marlin><software><mks>
How to add custom physical buttons to a 3D printer in Marlin software
Piotr
# How to add custom physical buttons to a 3D printer in Marlin software

(Asked by: username_0 on 2021-09-05)

I have a 3D printer with MKS Robin mainboard + TMC2209.

How do I add a piece of code to Marlin, for example, to make a physical button to start preheating, etc. I would like to use the existing mainboard, I don't want to use OctoPrint.

I have basic knowledge of Arduino programming. I could easily write the software to run the function on a button press but I cannot find how to integrate it into Marlin.

**Tags:** marlin, software, mks

> **Comments:**
> **username_1**: Hi and a very warm welcome to SE.3DP! Personally, as a keen Arduino tinkerer myself, I *really* like your question and I would like to know the answer as well. However, unfortunately, I think that this may be off-topic here as it is more about SW dev than 3D printing related. It'd be better to ask on the [Marlin firmware forum](https://reprap.org/forum/list.php?415), or raise a feature request on [Github repository](https://github.com/MarlinFirmware/Marlin). However, the latter might be either very slow or not elicit much of a response as they are very busy people - it's worth a try though.  
> **username_1**: Alternatively, you could take a few weeks out and try to become familiar with the Marlin source code yourself, and code it yourself - which is certainly not within the realms of impossibility.  I would also say that SE.Arduino probably isn't the place to ask either. Maybe the Arduino forums, but again, it might not get much of a response, although probably a better response than on Stack Exchange - the reason being that adding code to firmware is not a simple Q&A issue, but rather a long winded discussion. All in all, the Marlin forum is probably the best place to start. Good luck..! :-)  
> **username_1**: I thought that this (firmware modification) had already been asked but I can't *really* find the question that I remember... It might have been username_2's question, [Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?](https://3dprinting.stackexchange.com/q/6778/4762), and also of interest (although it recommends OctoPrint) is [How to make physical buttons send G-code?](https://3dprinting.stackexchange.com/q/7713/4762)  

---

## 1 answers

### Answer by username_1 on 2021-09-05. Score: 1

### `ultralcd.cpp`

Maybe, just *maybe*, this [post](https://github.com/MarlinFirmware/Marlin/issues/10394#issuecomment-381153626) from [how to add a physical button to extruder motor control? #10394](https://github.com/MarlinFirmware/Marlin/issues/10394) could help (the emphasis is mine):

> rather than directly work on stepper.cpp, ***I would rather suggest to take a look at the LCD control part***, and integrate an emulation of the prepare/move/Z-axis code. As for accessible pins, perhaps use any unused endstop ones ?

This would make sense, as it is similar to the location (i.e. file(s)) that required changing for username_2's question [Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?](https://3dprinting.stackexchange.com/q/6778/4762). The file in that case was `ultralcd.cpp` (see my [answer](https://3dprinting.stackexchange.com/a/6801/4762)).

However, `ultralcd.cpp` seems to have been either removed, moved or renamed to [`ultralcd_st7920_u8glib_rrd_AVR.cpp`](https://github.com/MarlinFirmware/Marlin/blob/2.0.x/Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp). It doesn't look hopeful. Previously it was in a 3rd part bugfix, see [this answer](https://3dprinting.stackexchange.com/a/10783/4762), and the link of *that* `ultralcd.cpp` is now dead.

### Keypads code

Alternatively, this [post](https://github.com/MarlinFirmware/Marlin/issues/10394#issuecomment-468987287) helpfully suggests:

> This is not a feature we would add. But it's possible to do movement with buttons by hooking into the LCD code and following the technique currently used for the KEYPADs.

So, that would seem to be a promising place to start. I'm not (currently) sure which file(s) that is though. It might be the code that handles the RepRapWorld keypad (see below).

### RepRapWorld keypad

This could also be useful, the RepRapWorld [Keypad](https://reprap.org/wiki/Keypad):

> Hook it up to your RAMPS AUX-2 port. Configure the firmware to use the keypad. The keypad is fully supported in Marlin Firmware.

You could emulate (i.e. reverse engineer) this piece of simple hardware (the most complex IC on it is just a shift register) and use the already built in code.

FWIW, a similar sounding (9 button) keypad is referenced here, [Adding custom keypad, marlin](https://www.reddit.com/r/Reprap/comments/g0z940/adding_custom_keypad_marlin/)

However, upon further reading, it is unclear whether the RepRapWorld keypad is still supported, see [Feature request: add suppport for reprapworld keypad #1142](https://github.com/MarlinFirmware/Marlin/issues/1142). Apparently RepRapWorld didn't (6 years ago) support it nor supply the source and expected the Marlin coders to support it for free.

### Other references and links

Nevertheless, the following [post](https://github.com/MarlinFirmware/Marlin/issues/10394#issuecomment-465536635) also suggests other sources of information that could be of use:

> For best results getting help with configuration and troubleshooting,
> please use the following resources:
>
> * RepRap.org [Marlin Forum](http://forums.reprap.org/list.php?415)
> * [Tom's 3D Forums](https://discuss.toms3d.org/)
> * Facebook Group ["Marlin Firmware"](https://www.facebook.com/groups/1049718498464482/)
> * Facebook Group ["Marlin Firmware for 3D Printers"](https://www.facebook.com/groups/3Dtechtalk/)
> * [Marlin Configuration](https://www.youtube.com/results?search_query=marlin%20configuration) on YouTube
> * Marlin Discord server. Join link: <https://discord.gg/n5NJ59y>
>
> After seeking help from the community, if the consensus points to to a
> bug in Marlin, then you should post a bug report.

It should be noted that, as a rule, the Marlin people prefer potential issues to be discussed on the Firmware Forum **first**, *before* any bug report or feature request is submitted to Github. This is to stop their Github issues page for getting too cluttered.

Also note that *Tom's 3D Forums* are now dead.

See also [Marlin/ LCD-Keypad Code Mod](https://reprap.org/forum/read.php?146,181251), although the thread seems to consist mostly of posts bemoaning software maintenance and life-cycles, and then sort of loses steam and dies at the end. However, this [post](https://reprap.org/forum/read.php?146,181251,269518#msg-269518) mentions `uiconfing.h` or `ui.h`.

> **Comments:**
> **username_2**: It should be easy to add a button according to https://www.thingiverse.com/thing:4932876, it uses a button and macros to (un)load filament. Although this is for RepRap firmware, it might work for Marlin also.  

---

