<p>I want to add auto bed leveling before each print. When I enable auto bed level in <code>configuration.h</code>, it only shows <strong>auto bed</strong> in menu. I found this code in <code>cardreader.cpp</code></p>

<pre><code>void CardReader::openAndPrintFile(const char *name) {
    char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
    sprintf_P(cmd, PSTR("M23 %s"), name);
    for (char *c = &amp;cmd[4]; *c; c++) *c = tolower(*c);
    enqueue_and_echo_command(cmd);
    enqueue_and_echo_commands_P(PSTR("M24"));
}
</code></pre>

<p>and changed it to</p>

<pre><code>void CardReader::openAndPrintFile(const char *name) {
    char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
    sprintf_P(cmd, PSTR("M23 %s"), name);
    for (char *c = &amp;cmd[4]; *c; c++) *c = tolower(*c);
    enqueue_and_echo_command("G28");
    enqueue_and_echo_command("G29");
    enqueue_and_echo_command(cmd);
    enqueue_and_echo_commands_P(PSTR("M24"));
}
</code></pre>

<p>Now before each print, the printer does auto bedding <strong>two</strong> times but when print starts the auto bedding is ignored and printer acts like before doing auto bed.</p>

<p>Please help me solve this.</p>

<p>I'm using Marlin Firmware 1.1.0.</p>

[{'answer_id': 4738, 'author': 'TextGeek', 'author_id': 40, 'author_profile': 'https://3dprinting.stackexchange.com/users/40', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m not that fluent in G-code, but at <a href="https://www.mmsonline.com/columns/understanding-g27-g28-g29-and-g30" rel="nofollow noreferrer">Modern Machine Shop: Understanding G27, G28, G29 and G30</a> I found these descriptions of the <code>G28</code> and <code>G29</code> codes you added:</p>\n\n<ul>\n<li><p><code>G28</code>: For any axis letter addresses included in the G28 command, the machine first will move (at rapid) to an intermediate position in those axes. Then, it will rapid to the zero return position in the commanded axes.</p></li>\n<li><p><code>G29</code>: G29 is also a two-step command. First, it causes the machine to move (in the axes commanded) to the intermediate position used in the most recent <code>G28</code> command. Second, it causes the machine to move to the position included in the <code>G29</code> command.</p></li>\n</ul>\n\n<p>So it sounds to me like you only need one of those two commands. It seems that the code you modified runs separately on startup, rather than for each separate print. I would first try your modification with each G command separately, so you can see exactly what the difference is on your hardware.</p>\n\n<p>I don\'t know my way around the code involved, but it looks like you\'d need to make the modification in another place, such as just before whatever loop sends successive commands to the printer.</p>\n\n<p>Hope that\'s helpful despite my limited fluency...</p>\n'}, {'answer_id': 6738, 'author': 'Nikkoura', 'author_id': 12752, 'author_profile': 'https://3dprinting.stackexchange.com/users/12752', 'pm_score': 3, 'selected': False, 'text': '<p>Rather than modifying the firmware to handle this, have you considered a pre-processing script on your computer, greping for a <code>G29</code> in the G-code, then adding a <code>G28</code>/<code>G29</code> pair at the start of the file if no <code>G29</code> is found?</p>\n'}, {'answer_id': 6740, 'author': 'Nikkoura', 'author_id': 12752, 'author_profile': 'https://3dprinting.stackexchange.com/users/12752', 'pm_score': 2, 'selected': False, 'text': '<p>With Marlin 1.1.0, you can automatically run a G-Code file when powering on the printer with a SD card already present.</p>\n\n<p>Add a file named <code>auto0.g</code> at the root of your card, containing the following G-Code:</p>\n\n<pre><code>G28 ;Auto-homing\nG29 ;Bed leveling\n</code></pre>\n\n<p>Normally the bed leveling map should be reused for all subsequent prints, until the printer is turned off.</p>\n\n<p>It is possible to provide up to 10 files, from <code>auto0.g</code> to <code>auto9.g</code>.</p>\n'}, {'answer_id': 6743, 'author': 'Trish', 'author_id': 8884, 'author_profile': 'https://3dprinting.stackexchange.com/users/8884', 'pm_score': 2, 'selected': False, 'text': '<p>Rather than placing the <code>G28</code> (Home) and <code>G29</code> (bed level) in the configuration, I would place it in the G-code generating slicer as pre-print code. This will automatically add this to the start of any G-code sliced, enforcing the homing and leveling whenever the G-code is run.</p>\n'}, {'answer_id': 6777, 'author': '0scar', 'author_id': 5740, 'author_profile': 'https://3dprinting.stackexchange.com/users/5740', 'pm_score': 3, 'selected': False, 'text': '<p>Another answer that does exactly what you want involves the use of a print server. A print server is an application that runs the instructions to the printer over a USB connection from another device, this can be your computer/laptop, or a dedicated <a href="https://www.raspberrypi.org/" rel="nofollow noreferrer">Raspberry Pi</a> (a small and affordable computer). One such application described here further is <a href="https://octoprint.org/" rel="nofollow noreferrer">OctoPrint</a> (this may very well be done with other applications, but this needs to be checked first!), this print server application allows integration of many third party plug-ins next to the extensive feature set it already has out-of-the-box. One such feature is <code>GCODE scripts</code> (intently spelled this way to match the option in the Octoprint settings menu); this screenshot shows some details:</p>\n\n<p><a href="https://i.stack.imgur.com/FZIeq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FZIeq.png" alt="GCODE scripts menu options item"></a></p>\n\n<p>As can be seen from the image, there are specific "events" available to process G-code commands at specific event occurences like e.g. just before the print starts. You could use that envent to insert your leveling commands.</p>\n\n<hr>\n\n<p>Please note that in the image you will find strange G-code commands like <code>OCTO100</code> and <code>OCTO110</code> which is a feature of the plugin called "GCODE System Commands" which allows running shell scripts to schedule the fan. I just kill the power to the fan when the printer is idle to get rid of the noise when the printer is just idling, the fan is only needed when the hotend is at elevated temperature.</p>\n'}]
['https://3dprinting.stackexchange.com/questions/4256', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/7505/']