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.

  • 1
    $\begingroup$ 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, or raise a feature request on Github repository. 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. $\endgroup$
    – Greenonline
    Sep 5 at 15:02
  • 1
    $\begingroup$ 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..! :-) $\endgroup$
    – Greenonline
    Sep 5 at 15:04
  • 2
    $\begingroup$ 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?, and also of interest (although it recommends OctoPrint) is How to make physical buttons send G-code? $\endgroup$
    – Greenonline
    Sep 5 at 17:23


Maybe, just maybe, this post from how to add a physical button to extruder motor control? #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 0scar's question Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?. The file in that case was ultralcd.cpp (see my answer).

However, ultralcd.cpp seems to have been either removed, moved or renamed to ultralcd_st7920_u8glib_rrd_AVR.cpp. It doesn't look hopeful. Previously it was in a 3rd part bugfix, see this answer, and the link of that ultralcd.cpp is now dead.

Keypads code

Alternatively, this post 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:

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

However, upon further reading, it is unclear whether the RepRapWorld keypad is still supported, see Feature request: add suppport for reprapworld keypad #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 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:

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, 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 mentions uiconfing.h or ui.h.

  • 1
    $\begingroup$ It should be easy to add a button according to 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. $\endgroup$
    – 0scar
    Sep 5 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.