10

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

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 = &cmd[4]; *c; c++) *c = tolower(*c);
    enqueue_and_echo_command(cmd);
    enqueue_and_echo_commands_P(PSTR("M24"));
}

and changed it to

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 = &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"));
}

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

Please help me solve this.

I'm using Marlin Firmware 1.1.0.

0scar
  • 37,708
  • 12
  • 68
  • 156
Hadi Barak
  • 201
  • 1
  • 2
  • 4

5 Answers5

6

Rather than modifying the firmware to handle this, have you considered a pre-processing script on your computer, greping for a G29 in the G-code, then adding a G28/G29 pair at the start of the file if no G29 is found?

Greenonline
  • 6,748
  • 8
  • 40
  • 68
Nikkoura
  • 178
  • 1
  • 7
5

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 Raspberry Pi (a small and affordable computer). One such application described here further is OctoPrint (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 GCODE scripts (intently spelled this way to match the option in the Octoprint settings menu); this screenshot shows some details:

GCODE scripts menu options item

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.


Please note that in the image you will find strange G-code commands like OCTO100 and OCTO110 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.

0scar
  • 37,708
  • 12
  • 68
  • 156
4

With Marlin 1.1.0, you can automatically run a G-Code file when powering on the printer with a SD card already present.

Add a file named auto0.g at the root of your card, containing the following G-Code:

G28 ;Auto-homing
G29 ;Bed leveling

Normally the bed leveling map should be reused for all subsequent prints, until the printer is turned off.

It is possible to provide up to 10 files, from auto0.g to auto9.g.

Nikkoura
  • 178
  • 1
  • 7
4

Rather than placing the G28 (Home) and G29 (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.

Trish
  • 22,760
  • 13
  • 53
  • 106
0

I'm not that fluent in G-code, but at Modern Machine Shop: Understanding G27, G28, G29 and G30 I found these descriptions of the G28 and G29 codes you added:

  • G28: 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.

  • G29: 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 G28 command. Second, it causes the machine to move to the position included in the G29 command.

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.

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.

Hope that's helpful despite my limited fluency...

Greenonline
  • 6,748
  • 8
  • 40
  • 68
TextGeek
  • 3,227
  • 2
  • 17
  • 32