How to Configure the BLTouch Start and End G-Codes?

It’s undeniable that proper bed leveling is one of the cornerstones of successful 3D printing, as a bed that isn’t level will throw all the calculations of the 3D printer off and cause many severe issues such as weak bed adhesion, inconsistent extrusion, and many more.

Fortunately, the wide availability of automatic bed leveling sensors, such as the BLTouch, turn the bed leveling process from something unreliable and arduous to a process that you will never have to think of again once you install and configure the probe correctly.

Today, our topic will be the configuration and optimization of start and end G-codes to activate the auto bed leveling process with a BLTouch as optimally and efficiently as possible, which will ensure that your build plate is level before each print.

So, how to configure the BLTouch start and end G-codes?

To make your start G-code routine include the activation of auto bed leveling with the BLTouch, you will need to add the G28 (Auto Home) and G29 (Bed Leveling) G-Codes, respectively, after the bed heating (M190) G-code.

As the BLTouch does not require any specific instructions after the printing process is over, adding the M400 (Finish Moves) G-Code as the first line of the end G-code should be sufficient to configure the end G-code.

In the upcoming sections, we will dive deeper into the process of configuring the BLTouch start and end G-codes, find out ways to optimize them and discuss why it’s vital to perform these optimizations.

How to Configure the BLTouch Start and End G-Codes?

Configuring the start and end G-codes for the BLTouch to operate is actually a pretty straightforward task, especially if you are familiar with G-code.

Configuring the start G-code to start the process of auto bed leveling with BLTouch requires the addition of two G-code commands after bed heating (M190) is complete; G28 (Auto Home) and G29 (Bed Leveling).

To start, let’s talk about why it’s vital to ensure that the BLTouch activates and levels the bed after the bed heating process is complete.

As the print bed undergoes thermal expansion when it heats up (which slightly changes its dimensions), it’s best to conduct the auto bed leveling process while the bed is in its heated state for the bed dimensions to be the same as the ones during printing.

The second vital point to discuss is the necessity of executing the G28 command before initiating the bed leveling process.

In a nutshell, the auto home (G28) procedure is necessary for the printer to know the printhead’s current position, making it a step that the printer needs to perform before each print.

As executing the G28 command disables bed leveling as a side-effect, running the G29 command after G28 ensures that both the auto home and the bed leveling (with BLTouch) procedures are successful.

Finally, let’s quickly talk about the end G-code configuration.

Since the job of the BLTouch is to level the bed before the printing process starts, you don’t need a specific end G-code configuration for the BLTouch to perform its tasks.

That being said, whether you use a BLTouch or not, we recommend adding the M400 (Finish Moves) command as the first line of the end G-code section to ensure that the task queue is clear before the end G-code commands start running.

Even though paying attention to these two factors for configuring the start G-code will ensure that your BLTouch will run and automatically level the bed before each print, the code won’t be fully optimized, which we will cover next.

How to Optimize the BLTouch Start G-Code?

As there are a few different ways you can set the start G-code up for the BLTouch, it’s definitely possible for your BLTouch start G-code to be unoptimized even though it functions correctly.

Optimizing the BLTouch start G-code is all about ordering the commands in a certain way to make the printer spend as little time as possible during this preparation phase, such as preheating the extruder before starting the auto bed leveling process to save time.

While unoptimized BLTouch start G-code can also perform the task of auto bed leveling without issues, as long as the code does not contain invalid syntax, reducing the print time as much as possible is a significant addition to the printing process.

Optimized BLTouch Start G-Code for Cura (Compatible with Ender 3 Pro/V2)

Since writing an optimized piece of start G-code can be difficult if you have no prior experience with it, we will be sharing the BLTouch start G-code we use, which we have tested with Cura slicer and Ender 3, Ender 3 Pro, Ender 3 V2 3D printers.

M140 S{material_bed_temperature_layer_0} ; Start heating the heated bed

M190 S{material_bed_temperature_layer_0} ; Wait until the heated bed reaches the desired temperature

M104 S160; Start heating the extruder to 160 degrees Celsius

G28 ; Auto Home

G29 ; Bed Leveling (with BLTouch)

G92 E0 ; Reset extruder origin

M104 S{material_print_temperature_layer_0} ; Start heating the extruder

G1 X0.1 Y20 Z0.3 F5000.0 ; Move printhead to the starting position

M109 S{material_print_temperature_layer_0} ; Wait until the extruder reaches the desired temperature

G1 Z2.0 F3000 ; Move Z-Axis up to avoid scratching of the build plate

G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line

G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to the side

G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line

G92 E0 ; Reset extruder origin

G1 Z2.0 F3000 ; Move Z-Axis up to avoid scratching of the build plate

*Credits to lushprojects at Reddit for the BLTouch Start G-code snippet for Cura.

Optimized BLTouch End G-Code for Cura (Compatible with Ender 3 Pro/V2)

Similar to the start G-code we have shared earlier, here is our BLTouch end G-code snippet we have tested with Cura and Ender 3, Ender 3 Pro, and Ender 3 V2.

M400 ; Finish Moves

G91 ; Set positioning to relative

G1 E-2 F2700 ; Retract the filament

G1 E-2 Z0.2 F2400 ; Retract the filament and raise Z-axis

G1 X5 Y5 F3000 ; Wipe

G1 Z10 ; Raise the Z-axis

G90 ; Set positioning to absolute

G1 X0 Y{machine_depth} ; Linear move

M106 S0 ; Disable fan

M104 S0 ; Disable hotend

M140 S0 ; Disable heated bed

M84 X Y E ; Disable all steppers except Z

As you may notice, we merely added the M400 G-code to the default end G-code snippet you can find in Cura for the Ender 3 as BLTouch itself does not require anything specific in the end G-code section.

Wrapping Up

Configuring and optimizing the BLTouch start and end G-codes is paramount for the auto bed leveling process to work as efficiently and reliably as possible, especially considering that the whole point behind using an auto bed leveling sensor is to improve reliability.

To quickly recap, the vital points to keep in mind while configuring the start G-code for BLTouch is to ensure that you add the G28 (Auto Home) command before G29 (Bed Leveling) and that these commands come after the bed heating command, M190.

On the other hand, the end G-code does not require anything special for the BLTouch to function correctly, but we recommend adding the M400 (Finish Moves) command to ensure that all actions are complete before the end G-Code routine starts.

Happy printing!