Automated Z-Axis Zero on Tool Change With Shapeoko 2 or X-Carve.




Introduction: Automated Z-Axis Zero on Tool Change With Shapeoko 2 or X-Carve.

I built my Shapeoko 2 in January of 2015.

While this might work on other controllers, I personally have only make this work with the Grbl v0.9 or later available at

I wanted to create a way to have the spindle move to a convenient location to change the tool, wait for the change then set the zero location on the tip of the tool bit.

I have accomplish this and it was way easier then I thought it would be.

This Instructable will lead you through this process.

I make 2 assumptions.

1. You have setup the your machine with homing switches.

2. You have at least some knowledge of wiring and connecting the controllers.

Lets get started!

Step 1: Installing the Switch.

For this process I used a micro-switch.

Locate and mount your micro-switch directly under your homing position of your spindle.

So if you move the z-axis down it will hit the switch perfectly.

Mine is mounted like the picture that on the side of the board just above the aluminum.

I show another option for mounting, just in case you are homing to the back of your machine.

Step 2: Connecting / Wiring Up the Switch.

On Grbl v0.9 or later they have a probe input on A5.

Connect GND to the Common location on the switch.

Connect A5 to the N.O. connection on the switch.

Thats all for the wiring.

Step 3: Getting Your Switch Point Height Difference.

I use paper under the tool method.

1. Load a thin tool into the spindle.

2. Home your machine using $H or (Home) on your sender.

3. Move the spindle down to just touch the switch

4. be sure the tool is centered on the switch, if not then adjust the switch position.

5. Set the Z-Axis to zero, (G92 Z0) or zero button on sender.

6. Set the feed rate very slow (F10). (About 10 inches per min or 250 mm per min.)

7. Using the G38.2 Z-(??) G-code - Example. (G38.2 Z-6.25) This will move the bit down until the switch activated.

8. Set your Z-Axis to zero again. (G92 Z0)

9. Using your sender or controller, move the machine over your waist board in the cutting area.

10. Set the height of the tool so a piece of paper is just touching the tool. (We can adjust for +/- later)

11. Take note of the height of Z on your sender. (Mine is -6.5mm)

12. Now you know the offset of the switch point to your table top.

13. You can call (G92 Z[your offset inverted]) example (G92 Z2.5)

Keep this offset number we will use it in the next step.

Step 4: The G-Code.

G21 ------------------ Set to metric, as I use MM
$H ------------------ Home the spindle
M00 ----------------- Pause for tool change
G92 Z0 -------------- Set z to 0 G01 Z-20
F100 ----- Feed down to -20 mm (about 3/4") at 100mm per min. to save time.
F50 ----------------- Slow things down to 50mm per min.
G38.2 Z-60 ----------- Send the spindle down max -60mm to zero tool tip.
G92 Z0 --------------- Set switch point to 0
G01 Z5 --------------- Move spindle up 5mm to release switch
F50 ------------------ Slow things way down to make an accurate zero point.
G38.2 Z-7 ------------ Send the spindle down to -7mm at
G92 Z??? ------------- This is the number from the previous step. Use caution, as this could send the bit into the table. Offset the switch point Z to the actual height of your table Z.

G01 Z30 F500 ------ Raise the bit to 30mm above my surface.
G01 X0 Y0 F1000 --- Move the bit to X0, Y0 (Optional)

Note: this will not reset your x,y locations.

See the next step if you want to return to the same location all of the time. And learn a bit about machine positions.

Step 5: Machine Location Movements.

As a standard, when you home your machine $H it will not mess with the axis zero locations.

So the X0 and Y0 should stay the same after homing the machine.

That said, we can use this time to send the machine to a position we always use for X0, Y0.

Look at the picture and in the blue circles, this is the machine position or location for X,Y,Z.

The main reason for this is that after the machine homes,it sets the machine location to zero at the home spot.

So if we call a G53 to move the machine to a machine location, we then can duplicate this after every homing or tool change.

So the last 2 lines of G-code below returns my machine to a machine position of X-710 Y-1466 and then sets that position to x0 y0 by using G92 X0 Y0.


G92 Z0
G01 Z-20 F1000
G38.2 Z-60
G92 Z0
G01 Z5
G38.2 Z-7
G92 Z1
G01 Z30
G53 X-710 Y-1466 F4000
G92 X0 Y0

Step 6: Finally

Some tips.

Move through all of the commands manually at first, this will help you to understand what the machine will do.

Take care in setting the machine offset, if the switch point is above the board then the the number in the G-Code will be positive. My switch point is 6.6mm above my table, so my G92 Z6.6 says exactly that. If your switch happens to be below the table top, then the number will be a negative number to say the tip is below the table top.

You can see it work in the video on YouTube

Good Luck and God Bless.


Be the First to Share


    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • CNC Contest 2020

      CNC Contest 2020
    • Secret Compartment Challenge

      Secret Compartment Challenge

    4 Discussions


    3 years ago

    If you have space for a paper is not Zero. A paper sheet has 0.1mm ;-)


    Reply 3 years ago

    If you want the tool to touch your waste board then you just set the took height .1 mm higher with the G92 command.

    Example: if G92 Z6.6 sets your tool at .1mm above your waste board then G92 Z6.7 will set it so the tool touches the table.

    I however enjoy the small bit of space and if I want to cut deeper I just tell the code to cut .1mm deeper.

    Hope that helps.

    DIY Hacks and How Tos

    Welcome to Instructables. Thank for sharing the awesome post.


    Reply 4 years ago

    Your Welcome!