Setting XYZ Probe Offsets in Marlin Firmware with M851

While an automatic leveling probe, such as the BLTouch, does indeed handle the bed leveling process automatically for you, there are some prerequisites for the probe to be able to work as intended, with one of them being configuring the X, Y, and Z-axis offsets correctly.

In this guide, we will explain the purpose of the M851 G-code command in Marlin Firmware, take you through the process of setting the X, Y, and Z probe offsets with M851, and take a look at the signs that can indicate your X, Y, and Z probe offsets are incorrectly configured.

What Is the Purpose of the M851 (XYZ Probe Offsets) G-Code in Marlin Firmware?

The M851 G-code command in Marlin Firmware allows you to set the X-axis, Y-axis, and Z-axis offsets for the bed leveling probe, which we can practically describe as the X, Y, and Z distances between your 3D printer’s nozzle and the probe, with the BLTouch and CR Touch being some of the most widely used examples.

As there’s no system that allows your 3D printer to understand where the probe is located relative to the nozzle automatically, manually inputting these values is the only way for the firmware to have access this information, which makes it a critical step for configuring your automatic bed leveling probe.

For instance, when you home the X and Y axes and move the X-axis and Y-axis positions to X0 Y0, your 3D printer will know that the nozzle’s current location is the front-left corner of the print bed.

That being said, as the probe isn’t directly on top of the nozzle on the X and Y axes, which is what the 3D printer will assume if both the X and the Y probe offsets are 0, ensuring that the X and Y probe offset values are configured correctly is vital for the 3D printer to be able to bring the probe to the correct spots on the print bed.

x probe offset explained

Similarly, when you home the Z-axis, your 3D printer will consider the point where the automatic bed leveling probe comes into contact with the print bed to be the Z0 position.

Naturally, this would also be wrong due to the nozzle and the probe not being on the same height level, which is what your 3D printer would assume if the Z probe offset value is 0, and correcting this would require setting the Z probe offset to the actual distance between the probe and the nozzle, so that the 3D printer can adjust the nozzle position accordingly during the print.

z probe offset explained

Considering that the firmware will have to rely on the values you have specified to determine both the nozzle and the probe’s position, depending on the axis where the movement is taking place, it goes without saying that misconfiguring any of these values can lead to various problems, which we will cover in detail in later sections.

Setting the Z Probe Offset with M851 in Marlin Firmware

The Z probe offset value is the one that determines the Z-axis distance between the probe and the nozzle, which is what makes it possible for your 3D printer to calculate the nozzle Z-axis position correctly once the probe finds Z0 after homing.

When starting the process of setting the Z probe offset value with the M851 G-code command, resetting your 3D printer’s current Z probe offset value to 0 by sending the M851 Z0 command through your G-code terminal is the very first step we recommend taking, as this will make things easier moving forward.


Once you ensure that the Z probe offset is at 0, the next step you will need to take is to auto-home the axes by using the G28 G-code command, center the X and Y axes (it’s not necessary for it to be exact), and bring the Z-axis to a point where it’s very close to the print bed, but not touching, such as a Z-axis value of 5.

octoprint g28 auto home

preparing axes for probe offset calc


Now, slide a standard piece of paper under the nozzle, and feel free to bring up the Z-axis higher if there isn’t enough space between the build plate and the nozzle for the paper to fit in.

printhead positioned close to the bed with a piece of paper in between


Once the paper is in place, deactivate the software endstops by using the M211 S0 G-code command, which will make it possible to move the Z-axis beyond the Z_MIN_POS value (which is usually 0) if it becomes necessary during the calibration process.

octoprint m211 disable software endstops


With all the preparation done, now is the time to find the optimal probe Z offset value, which will require you to move the nozzle down 0.1 mm at a time (for instance, if the current Z-axis position is Z3, use the G-code command G0 Z2.9 to move 0.1 mm down), check whether you can still slide the paper in and out smoothly, and repeat this process until you find the spot where you can still slide the paper out in one piece without any ripping or tearing, but with some resistance that requires you to apply some pull to be able to get the paper out.

Now that you have the optimal probe Z offset value at hand, set it by using the command M851 Z<value>, such as M851 Z-2 if the Z-axis value you’re reading on the screen is -2 at the point where you started feeling resistance when trying to slide the paper out.

octoprint m851 z-2 example


Finally, re-enable the software endstops by sending the M211 S1 command, and save the new probe Z offset value to the EEPROM with M500.

octoprint m211 s1 m500


As an extra step, if you would like to verify things, you can restart your 3D printer to force it to load EEPROM data and use the M851 G-code command without any parameters, which should print the current X, Y, and Z probe offset values on the screen.

octoprint verify offsets with m851


Setting the X and Y Probe Offsets with M851 in Marlin Firmware

The X and Y probe offsets determine the X-axis and Y-axis distances between the probe and the nozzle, making it possible for the 3D printer to bring the probe to the correct locations on the bed when building the bed-leveling mesh.

For this process, you will need to find a tool that allows you to measure small distances accurately, such as a digital caliper (most convenient & reliable), a ruler, or a measuring tape, as measuring the X-axis and Y-axis distance between the probe and the nozzle is how we will find the X and Y probe offset values.

Next up, you will need to measure the X-axis distance between the tip of the automatic bed leveling probe and the tip of the nozzle, note this value down, and additionally, put a minus (-) next to it if the probe is positioned to the left of the nozzle.

measuring x probe offset


So, for instance, if the X-axis distance between the probe and the nozzle is 40 millimeters, with the probe positioned on the left side of the printhead, the value you will need to note down is -40, which will be the probe X offset.

Once the X-axis is done, the next step is to measure the Y-axis distance between the tip of the automatic bed leveling probe and the tip of the nozzle, note the value down once again, and additionally, put a minus (-) next to the value if the probe is positioned toward the front of the nozzle on the Y-axis.

As an example, if the Y-axis distance between the probe and the nozzle is 10 millimeters, and the probe is closer to the front edge of the build plate than the nozzle, the value you will need to note down is -10, which will be the probe Y offset.

measuring y probe offset


Now that you have both the X probe offset and the Y probe offset values ready, the last step is to set the X and Y probe offsets with the M851 X<X offset> Y<Y offset> G-code command, such as M851 X-40 Y-10 for an X probe offset of -40, and a Y probe offset of -10.


Finally, if you want to verify things, you can restart your 3D printer to force it to load EEPROM data and use the M851 G-code command without any parameters, which should print the current X, Y, and Z probe offset values on the screen.

octoprint verify offsets with m851


Signs That Show Your Z Probe Offset Is Configured Incorrectly

While the signs you will notice when the Z probe offset value is configured incorrectly will show differences based on whether the value is lower or higher than it’s supposed to be, either scenario will usually end up with your prints failing.

When the Z probe offset value is higher than it should be, the primary sign you will notice is poor bed adhesion, as the distance between the print bed and the nozzle being too much will prevent the plastic from getting enough “squish” for it to adhere to the print bed strongly enough, which often results in the print peeling off the build plate as the printing process goes on.

Additionally, in more severe cases, the usage of a Z probe offset value that’s way too high can also cause your 3D printer to end up visibly printing in the air, where the plastic does not stick to the build plate at all and creates the issue known as spaghetti monster in the community, where the extruded filament takes the form of a jumbled mess that looks like spaghetti.

3d print spaghetti monster example
Source: Jim @ Stack Exchange (CC BY-NC-SA 4.0)

Alongside poor bed adhesion, another common sign you will notice when printing with a probe Z offset value that’s way too high is the lines of the initial layer having gaps between them, as not “squishing” the lines into the build plate will cause the lines to end up thinner than they actually should be.

3d print first layer gaps example
Source: openyk @ Stack Exchange (CC BY-NC-SA 4.0)

On the other hand, if your Z probe offset value is lower than it should be, the primary sign you will notice is a messy initial layer that looks damaged with random holes & plastic dragged across the surface, as the distance between the print bed and the nozzle being way too little will cause both under-extrusion by not giving the filament enough room, and also cause the nozzle to scrape through the printed areas and drag molten plastic.

3d print first layer damage example
Source: GusOst @ Stack Exchange (CC BY-NC-SA 4.0)

In more severe cases where the nozzle ends up being in full contact with the print bed due to there practically being no gap at all, you can also observe the more serious problem of the nozzle scraping the build plate as it moves around, which can permanently damage both the build plate and the nozzle and effectively create a scenario where it becomes necessary to replace both of these components.

Signs That Show Your X and Y Probe Offsets Are Configured Incorrectly

Discovering whether your X and Y probe offsets are misconfigured is usually more challenging than finding out whether your Z probe offset is misconfigured, as it will create print quality issues that aren’t too easily observed unless the misconfiguration is severe.

When the X and Y probe offsets are not configured correctly, the bed leveling mesh that the probe generates will be all wrong, since where the 3D printer thinks the probe is won’t reflect the probe’s actual position when it’s taking the readings, which will result in the Z distance between the nozzle and the print bed becoming incorrect for all points where bed leveling correction is applied.

The primary signs you will notice in such a case is the nozzle getting too close to the print bed in some areas, and too far from the print bed in other areas, based on how the bed leveling mesh is generated, which can create some of the issues we have talked about in the previous section in a more random and inconsistent manner, whether it’s poor bed adhesion the first layer becoming messy, or the nozzle scraping the bed.

Additionally, if you ever come across a scenario where the probe attempts to take readings outside the bounds of the print bed during the bed leveling mesh generation process, the usage of incorrect X and Y probe offsets is a factor that you should put into consideration as well, which is something to keep in mind.

Conclusion

While setting the X, Y, and Z probe offsets with the M851 G-code command is a pretty straightforward process for the most part, ensuring that the measurements you have taken are correct is critical for your automatic bed leveling probe to work as intended.

As misconfiguring any of these values can create a plethora of issues ranging from the probe not being able to generate a reliable bed leveling mesh to the nozzle crashing into the bed, taking your time to get things right will ensure that you don’t end up having problems down the road.