Automated Probe Z-Offset measurement

Basic Information:

Printer Model: Sapphire Pro / Panda Cube
MCU / Printerboard: Skr 1.4 and Arduino Nano
klippy(3).log (1.3 MB)

klippy.log

Fill out above information and in all cases attach your klippy.log file (use zip to compress it, if too big). Pasting your printer.cfg is not needed
Be sure to check our “Knowledge Base” Category first. Most relevant items, e.g. error messages, are covered there

Describe your issue:

I want to use a 3D-Beacon probe in the future. Because I want everything as automated and reliable as possible, I want my printer to measure the exact z-offset before every print.
Here for I’m using the hotend as a switch. I want it to move down until it hits a bare aluminium plate on the front of the bed. When the nozzle hits the metal plate, a circuit gets closed and triggers for example a gcode_button. Then the beacon measures its distance to the metal plate and compares it to the nozzle, which is currently at zero. This difference is the new exact z-offset, which will be used for the current print. This whole process should be somewhat similiar to how z_tilt_adjust works. I have already tried a lot of different versions of this project, but I don’t get it to fully work. I have lots of trouble coding in Jinja2. I need the part where it moves down as long as the switch is open, then stops and holds the current position as long as the beacon makes its reading. Then this value needs to be stored until the next restart.
For this process all the axis have to be homed (so the printhead can move to its needed position) and the z-tilt has to be adjusted. So the beacon probe has to be used before it could make its exact z-offset reading. So I actually have to use two different z-offsets. One permanently stored for when I need to home the axis and z-tilt adjust for the first time after a restart and one which replaces this z-offset with the much more accurate read one.

Example code of my first tries:

[gcode_macro TEST_OFFSET_READING]
description: Reads z-offsets and probe offset, compares and sets new z-offset
gcode:
G1 F2000 X0 Y0 # first move to 0,0 to ensure afterwards only y-axis moves
G1 F2000 X0 Y-130 # move to aluminium plate
G1 F5000 X-50 Y-130 # wipe nozzle
G1 F5000 X0 Y-130
G91 # Set to relative positioning
{% for 0 in trigger_state %} # as long as trigger_state is 0 execute movement
G1 F200 X0 Y0 Z-0.1 # slowly lower z-axis
M400 # wait until movement is finished
{% endfor %}
G90 # Set to absolute positioning
M400 # wait until movement is finished

Hello @Toni !

Sounds interesting.

One technical question: Do you have a low voltage heated bed or one that runs on mains supply?

I have a custom heated bed that runs on mains voltage. But I want to mount the alumium plate electricaly isolated from the rest, because the 5V on the plate wouldn’t work with the grounded bed.

This is not an attempt to help answering your question.

Cool thing, interesting but too expensive (just my opinion).

https://docs.beacon3d.com/faq/
You might read “What Bed Surfaces Work with Beacon?”

I think aluminium is the wrong material to go with that probe.

That thing is an “Eddy-current sensor” Eddy-current sensor - Wikipedia
A big disadvantage (in my eyes) is the need of an USB cable. Since the probe is attached to the extruder, you 'll have another heavy and inflexible cable going to your host.

Here is an informing video (sorry German language) https://www.youtube.com/watch?v=F5BD71Wvm5c

In fact, only conductive surfaces like aluminum or steel will work with such a sensor. For example, a bubble/missing spot in the PEI sheet will go unnoticed.

@Toni
Interesting idea. I’m not sure if your concept can be realized with macros. My gut feeling is no, but there are far more knowledgeable macro wizards than me.

I agree.

@Toni
…sorry, that was wrong.

Thanks for the answer. Do you know any one or any place, where I can find myself a macro Gandalf? Or do I need to become one myself?

It is never wrong to learn how to write macros for Klipper.
I’m following this probe but the price is still high and shipping to Germany as well.
There are IDM knock-offs in AliExpress and even one with a smaller head and outsourced electronics and no restricted area.

But nevertheless your project looks cool.

No problem. I mean your right, the probe doesn’t really matter. At the moment I’m running a 3D-Touch and the shown concept would pretty much work the same.

Can I like send you my current macro and you tell me what might be wrong with it?

In my opinion, one of the issues your example above is suffering from is detailed here: Help with Macro: SET_GCODE_VARIABLE doesnt set my variable - #12 by theophile

Do you mean the issue with the recalling of a changed variable state?

This is the full version:

[gcode_macro global]
variable_trigger_state: 0
gcode:
M115 ; must provide something

[gcode_macro TEST_OFFSET_READING]
description: Reads z-offsets and probe offset, compares and sets new z-offset
gcode:
G1 F2000 X0 Y0 # first move to 0,0 to ensure only y-axis moves
G1 F2000 X0 Y-130 # move to aluminium plate
G1 F5000 X-50 Y-130 # wipe nozzle
G1 F5000 X0 Y-130
G91 # Set to relative positioning
{% for 0 in trigger_state %} # as long as trigger_state is 0 execute movement
G1 F200 X0 Y0 Z-0.1 # slowly lower z-axis
M400 # wait until movement is finished
{% endfor %}
G90 # Set to absolute positioning
M400 # wait until movement is finished

[gcode_button my_gcode_button]
pin: arduino:PB3
; The pin on which the button is connected. This parameter must be
; provided.
press_gcode:
SET_GCODE_VARIABLE MACRO=global VARIABLE=trigger_state VALUE={1}
; A list of G-Code commands to execute when the button is pressed.
; G-Code templates are supported. This parameter must be provided.
release_gcode:
SET_GCODE_VARIABLE MACRO=global VARIABLE=trigger_state VALUE={0}
; A list of G-Code commands to execute when the button is released.
; G-Code templates are supported. The default is to not run any
; commands on a button release.

I’m honestly suprised how hard it is to code smth like this. I only have expierence when it comes to programming Arduinos and there it would actually seem like such an easy task :slight_smile:

Exactly, the trigger_state is only evaluated once when you call this macro. Any subsequent changes are lost.

I didn’t have much time today, but this setup works for the first part of lowering the z-axis until the switch triggers and then the axis stops moving. Let’s see where this solutions is going in the future. If you have any advice, feel free to tell me.

[gcode_macro TEST_OFFSET_READING]
description: Reads z-offsets and probe offset, compares and sets new z-offset
gcode:
G1 F2000 X0 Y0 # first move to 0,0 to ensure only y-axis moves
G1 F2000 X0 Y-130 # move to aluminium plate
G1 F3000 X-50 Y-130 # wipe nozzle
G1 F3000 X0 Y-130
UPDATE_DELAYED_GCODE ID=TEST_LOOP DURATION=1 # start the loop for lowering the z-axis

[delayed_gcode TEST_LOOP]
gcode:
G91 # Set to relative positioning
G1 F100 Z-0.05 # lower the z-axis
UPDATE_DELAYED_GCODE ID=TEST_LOOP DURATION=0.5 # restart loop in 0.5 seconds

[gcode_button my_gcode_button]
pin: arduino:PB3
; The pin on which the button is connected. This parameter must be
; provided.
press_gcode:
UPDATE_DELAYED_GCODE ID=TEST_LOOP DURATION=0 # stop the loop when nozzle touches aluminium plate

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.