# Z Offset on autoleveling sensor setup

How does Z offset (M851) work with an auto leveling sensor? Does it add the Z offset to the offset of the G29 mesh? or the G29 value replaces the M851?

My printer is an Anet A8 with marlin firmware, I was having issues with the autoleveling sensor and reset the Z offset to 0 and let G29 get the mesh offsets and its working good now.

I was looking through marlin gcode page but couldn't figure out how G29 affects M851 or vice-versa.

My setup with level issues:

M851 Z0
G28
M211 S0 ;turned endstops off and got a paper to find the zoffset
M851 Z-0.59
M500
M211 S1


And G29 before printing.

G28 instructs the printer to home itself to the X an Y endstops and the Z sensor determines the homing of the Z axis; i.e. when the sensor triggers, this is not necessarily (and most commonly) not the position where the nozzle is at Z=0.

G29 determines the shape of the bed by probing the bed. This will set the shape of the bed with respect to the sensor trigger point as described earlier. The Z-offset (set by M851 Z-x.xx is needed to set the offset between the nozzle and the sensor trigger point (to the bed).

The sequence to determine the offset is:

M851 Z0; // Set the Z offset to zero height
G28;     // Home Z in the middle of the bed
G1 Z0;   // This will move the head to zero height;
M211 S0; // This will disable the end stops so that you
// will be able to proceed lower than Z=0


Now adjust Z height to fit a piece of paper and note the negative Z height (either through the LCD or through an application over USB)

M851 Z-1.23; // Define the Z offset
M500;        // Store the settings
M211 S1;     // Enable the end stops again


Please note that -1.23 is a fictive value that should be replaced by your own value.

You must use the sequence

G28
G29


If you do G28 after G29 it will reset bed leveling. I guess you don't want that.

On my printer deployed z-probe falls 2.3 mm lower than nozzle. In printer settings I've therefore stored static Z-offset of -2.3 mm, so after G28 and G29 I can be sure that when ever I tell Z-axis to lower to zero, it can go down -12.3 mm, coming to stop at around 0.1 mm above the bed surface (so just a single sheet of paper fits between the nozzle and the bed).

That said, I'm not worrying about sending the Z-offset via print commands, as restart restores the aforementioned -2.3 mm offset.