<p>When running <a href="https://github.com/MarlinFirmware/Marlin" rel="nofollow noreferrer">Marlin Firmware</a>, is it possible to run <a href="https://reprap.org/wiki/G-code" rel="nofollow noreferrer">G-code</a> scripts/series of commands automatically when you insert the SD card?</p>

<hr>

<p>I'm running Marlin on a 3D printer board using an ATmega 2560 based board with a reprap discount LCD controller with an SD card slot. I would like to do this without the need to add another computer/board, so native from the board running the Marlin Firmware.</p>

[{'answer_id': 6801, 'author': 'Greenonline', 'author_id': 4762, 'author_profile': 'https://3dprinting.stackexchange.com/users/4762', 'pm_score': 4, 'selected': True, 'text': '<p>I am not <em>entirely sure</em> if this is what you are after, or if it will work, but from  <a href="https://github.com/MarlinFirmware/Marlin/issues/2891#issuecomment-180980733" rel="nofollow noreferrer">this post</a> on <a href="https://github.com/MarlinFirmware/Marlin/issues/2891" rel="nofollow noreferrer">Printing From SD Card when printer is turned On</a></p>\n<blockquote>\n<p>While an LCD controller is not needed for auto#.g to work, if you have an LCD controller you can use the <code>MENU_ADDAUTOSTART</code> option to add a menu command that will run the auto0.g, auto1.g, auto2.g whenever you want.</p>\n</blockquote>\n<p>This (final) post ended up closing the thread so it appears to answer the OP\'s question - however, whether it will answer your question is another matter.</p>\n<hr />\n<p><a href="https://reprap.org/forum/read.php?415,833394" rel="nofollow noreferrer">This post</a>, on the Marlin forum, replicates your question and asks about purely insertion of an SD card on a printer which is <em>already</em> powered on.</p>\n<p><a href="https://reprap.org/forum/read.php?415,833394,833489#msg-833489" rel="nofollow noreferrer">A reply</a> was received and apparently it should be possible by making a code change in <code>ultralcd.ccp</code>:</p>\n<blockquote>\n<p>It does not seem like an auto print, when inserting a SD-card, is to\nbe found in the current program code of Marlin.</p>\n<p>You might consider making a feature request here: [<a href="https://github.com/MarlinFirmware/Marlin/issues" rel="nofollow noreferrer">github.com</a>]</p>\n<p>I do not think that it would require much work to implement a\n&quot;card.autoprintfile()&quot; function in Marlin. It seems to me that a call\nto such a function could happen at line 5172 right after:</p>\n<pre><code>else\nLCD_MESSAGEPGM(MSG_SD_INSERTED);\n</code></pre>\n<p>in the file <code>ultralcd.ccp</code></p>\n</blockquote>\n<p>A subsequent feature request has been made on Marlin\'s GitHub, see <a href="https://github.com/MarlinFirmware/Marlin/issues/11815" rel="nofollow noreferrer">[FR] Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?</a></p>\n<p>However, from <a href="https://github.com/MarlinFirmware/Marlin/issues/11815#issuecomment-420791259" rel="nofollow noreferrer">this reply</a>, it appears that a feature request is already pending:</p>\n<blockquote>\n<p>I\'m not in favor of this as a general feature. We already have a\nfeature request to be able to run custom G-code in response to various\nevents, with SD card insertion being one of those events. Would that\nfeature serve your needs?</p>\n</blockquote>\n<p>However, as yet, I do not have a link to this other feature request. Will update as and when.</p>\n<hr />\n<p>As an aside, in might be worth mentioning that the SDFat related code could be the place to code this in, see <a href="https://forum.arduino.cc/index.php?topic=360754.0" rel="nofollow noreferrer">if SD card removed, how to flag and restart?</a>, although after looking at the Marlin codebase, in particular <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/SdFatUtil.cpp" rel="nofollow noreferrer"><code>SdFatUtils.cpp</code></a>, this would appear to be a <a href="https://en.wikipedia.org/wiki/Red_herring" rel="nofollow noreferrer">red herring</a>.</p>\n'}, {'answer_id': 6814, 'author': 'amra', 'author_id': 75, 'author_profile': 'https://3dprinting.stackexchange.com/users/75', 'pm_score': 1, 'selected': False, 'text': '<p>I don\'t know what you would like to achieve.</p>\n\n<p>As @typo mentioned there is similar functionality which triggers at printer startup: <a href="https://github.com/MarlinFirmware/Marlin/wiki/Autostart" rel="nofollow noreferrer">https://github.com/MarlinFirmware/Marlin/wiki/Autostart</a></p>\n\n<p>I found in Marlin\'s source code that you can enable that autostart feature to be triggered from menu. Just enable <code>MENU_ADDAUTOSTART</code> in <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/Configuration_adv.h" rel="nofollow noreferrer">Configuration_adv.h</a>. </p>\n\n<p>If you really need a g-code that start after sd-card insert then you have to adjust the marlin source code on your own. I suggest to alter file <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/cardreader.cpp" rel="nofollow noreferrer">cardreader.cpp</a>. There you have to trigger the autostart procedure after a sd-card is inserted.</p>\n'}]
['https://3dprinting.stackexchange.com/questions/6778', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/5740/']