Z Probe Code



 The Z Probe.


The Z Probe is used for finding the top of the work piece, and zeroing the DRO (digital read out) Z axis. They cost less than £5 to buy on Ebay.

Coding is embedded into Mach3 to actuate the probe.







The images above are taken from the Ebay website








On my machine, I only have three axis, so I used P11 for my Z probe. This would normally be used for the A axis. The wire with the white stripe is connected to earth, (this can be the machine bed) The plain black wire is connected to P11 on the break out board.

P11 Z probe
P12 X home switch
P13 Y home switch
P15 Z home switch
P10 Emergency stop

The top red connector is for the 24v cooling fan


Okay, now for the code:

 CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state

If GetOemLed (825)=0 Then 'Check to see if the probe is already grounded or faulty
DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Code "G4 P3" ' this delay gives me time to get from computer to hold probe in place
Code "G90 G31Z-50 F50" 'probing move, can set the feed rate here as well as how far to move
While IsMoving() 'wait while it happens
Wend
ZProbePos = GetVar(2002) 'get the exact point the probe was hit
Code "G0 Z" &ZProbePos 'go back to that point, always a very small amount of overrun
While IsMoving ()
Wend
Call SetDro (2, 19.30) ' change .060 to your plate thickness and then adjust for final accuracy
Sleep 200 'Pause for Dro to update.
Code "G1 Z25 F500" 'put the Z retract height you want here, must be greater than the touch plate thickness
While IsMoving ()
Wend
Code "(Z axis is now zeroed)" 'puts this message in the status bar
Code "F" &CurrentFeed 'Returns to prior feed rate
Else
Code "(Z-Plate is grounded, check connection and try again)" 'this goes in the status bar if applicable
End If
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If
If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
Code "G0"
End If  

First of all you need to measure the height of your probe. 

Find this line in the code above.    Call SetDro (2, 19.30) 
The height of mine is 19.30. So if your's for example measures 18.35, replace 19.30 with 18.35.

Copy and paste the code above onto a memory stick.

Go to > Mach3 home screen > Operator > Edit Script Editor 

You will now see several things flashing on the screen.
Click on the Auto Zero Tool button, and this will take you to the script editor where you paste in the code 

Save > Save changes to editor > YES

Bring the Z axis down at least 25 MM from the top, Click on the Auto Tool Zero button, There is a pause before the Z axis starts to move slowly down.  

Touch the probe on to the tool. The Z axis should now retract up, the DRO will read 25.000.

This is just to check that everything is working ok. If it does then place the probe on top of your work piece and click the Auto Zero Tool button again. As before, the Z axis starts to move slowly down then retract 25 MM. your tool is now set 25 MM above your work, Z zero on the top of your work piece