Specifying Z offset in Marlin firmware



I need to set a Z offset for the Flying bear P902. I calculated the offset (-2.98). But, every time when I try to input this using the LCD screen of my 3D printer, the value jumps to either -2.99 or -2.97. As -2.97 is just a little bit too far from the bed and -2.99 is just a little bit too close to the bed (and -2.98 is perfect), I really want to input this specific value. I have tried many times on the LCD screen and also in the firmware itself.

But, even after uploading the firmware, it still displays -2.97.

This is the line of code I was changing:

#define Z_PROBE_OFFSET_FROM_EXTRUDER -2.98 // Z offset: -below +above  [the nozzle]

Is there a way I can input -2.98?

Rosalie W

Posted 2019-04-30T02:39:39.480

Reputation: 373

I really doubt that 1/100 of a mm would make that effect on adhesion, the deviation of the positioning accuracy is most probable even higher than that! – 0scar – 2019-04-30T06:32:01.987



Z-offset persitently stored in memory?

Maybe the value of -2.97 for the Z_PROBE_OFFSET_FROM_EXTRUDER is retained in the EEPROM memory when you upload new firmware.

You could try to send the G-code M502 to the machine to re-load the values from the firmware overwriting currently stored values.

Alternative Z-offset using G-code commands

Note that there is a different (and more common) solution to set the Z-offset using G-code M851, you can do this after you uploaded the firmware to the printer. Sending G-code commands can be done using printer software and a USB connection to the printer through a so-called terminal interface. This can be done in OctoPrint, Repetier-Host, Pronterface (Printrun software suite), and probably many more. Alternatively, you could make seperate G-code (basically text files with extension .g) files with each step in a single file and "print" the files through the SD interface of the printer menu.

The following strategy must be followed to specify the Z offset:

  • Heat your printer up to your printing temperature and allow a few minutes for it to expand and settle
  • Reset the existing Z-offset to zero M851 Z0
  • Home all axes G28
  • Move the nozzle to the middle of the bed G1 X110 Y110 (if your bed is 220 x 220)
  • Turn off the software endstops with M211 S0
  • Move the nozzle down so it is just gripping a piece of standard printer paper
  • Set the Z-offset to the displayed value. E.g. if the printer displays a Z-Value of -1.23 enter M851 Z-1.23
  • Store it to the EEPROM M500
  • Important notice! Enable the endstops again with M211 S1 or the printer head will collide with the bed on the next G28 command


Posted 2019-04-30T02:39:39.480

Reputation: 25 570

1Thank you very much. This helped. I used Repetier-Host and was able to calculate the new z offset and store it. After that, I printed something and it was successful! – Rosalie W – 2019-05-01T19:10:33.357