auto-adjust Z-offset

  • I have some spare microswitches lying around and thought about using them for adjusting the Z-Offset automagically using the switch and the inductive sensor in combination:

    • install the microswitch right next to the printbed and make it adjustable so it can be dialed in to be triggered by the nozzle exactly at the actual height of the printbed (which will be Z=0). This would have to be re-adjusted for different printbeds, but maybe multiple switches can be used for different print surfaces and linked to different toolsets?

    • mount the inductive sensor on each printhead in such a position, that it is above the printbed when the microswitch is probed, so the sensor also gets triggered by the bed when the nozzle triggers the microswitch.

    The probing process could look like this:
    after homing x+y, (and maybe after adjusting the bed level using multiple stepper motors), move the nozzle over the microswitch corresponding to the current build surface height and move the nozzle downwards/the bed upwards until the microswitch is triggered, then store the trigger height of the probe and continue with mesh compensation (using the probe).

    This procedure would automagically compensate for different printheads/tools as well as different nozzle lengths or variations when the printhead has been taken apart (relative height difference of sensor and nozzle changed).

    But can both, a probe and an endswitch be defined for Z-axis? E.g. would M574 Z1 S1 P"" work?
    Or should M574 be called from the script to re-define the endstop type after the microswitch has been triggered and Z=0 has been set?

    My crude first approach would be:

    • set endstop for Z-axis to microswitch (M574 Z1 S1 P"zstop")
    • home Z-axis via microswitch (G1 H1 Z-500)
    • set endstop for Z-axis to Z-probe (M574 + M558)
    • set Z-probe trigger value (G30 S-3)

    I've read about variables somewhere, those would be very handy to e.g. store
    the trigger height and inserting into a 'G31' command to set the Z trigger height...
    I also haven't checked/tried if the firmware loses home position for an axis if its endstop is re-defined.

    I'm sure this idea isn't new, so I'd really like to hear about other approaches or if I was just too blind to find this in the documentation or the proper (simpler) gcode for doing this...

  • While troubleshooting a weird glitch where I always got an height error of ~0.4mm when using the inductive sensor to set Z=0 with G30 and a fixed trigger offset (can be read here: ), I "accidentaly" found a way to completely automate Z-homing with Z-probe offset adjustment. 😀

    It basically boils down to only 2 simple steps:

    • set Z=0 via the endswitch (G1 H1 + G92 Z0)
    • calibrate the probe trigger distance with G30 S-3 at Z=0

    I've mounted the Z-endswitch directly next to the printbed at the far right corner. The Z-probe is still above the bed, so i only have to move a few mm to clear the endswitch and calibrate the trigger distance.
    The only caveat of this method: The bed height has to correspond exactly to the trigger height of the endswitch. This can be easily adjusted by setting Z=0 on the endswitch, then moving over the bed and manually move to Z=0 and adjusting the bed so the nozzle touches the surface at Z=0 height.

    To use the Z-endstop the axis has to be configured to use a switch, not the probe, but the probe is still defined via M558 and a trigger value but no offset is set:

    M574 Z1 S1 P"!zstop"
    M558 P1 C"!" H20 A5 F600 T18000           ; set Z probe type to unmodulated and the dive height + speeds
    G31 P500                        ; set Z probe trigger value. trigger distance is set during Z homing

    The complete Z-homing procedure looks like follows:

    ; homez.g
    M561					; cancel all bed mesh compensations
    M558 P1 C"!" H15 F300		; increase dive height to prevent crashing into a tilted bed
    ; probe and adjust the bed tilt
    G30 P0 X50 Y165 Z-99999 ; probe near a leadscrew
    G30 P1 X350 Y165 Z-99999 S2 ; probe near a leadscrew
    M558 P1 C"!" H5		; reduce dive height after adjusting the bed
    ; move over endswitch to set Z=0
    G1 X341 Y310 F18000
    G1 H1 Z-350 F600 ; move quickly to Z axis endstop and stop there (first pass)
    G1 Z5 F1200       ; move up a few mm
    G1 H1 Z-6 F300   ; move slowly to Z axis endstop once more (second pass)
    G92 Z0 			; set Z=0
    G1 Z15 F1200   ; lift printhead
    ; calibrate probe trigger distance
    G1 X341 Y313 F18000	; move directly next to the switch to calibrate the probe
    G30 S-3				; set probe trigger height
    G1 Z15 F1200		; lift printhead
    G1 X0 Y330 Z20 F18000				; move printhead to the back

    For now this gives pretty consistent results and mesh compensation is working reliably. Even with deliberately introduced errors, the nozzle is just touching the bed when moving to Z=0 at any position.

Log in to reply