Configuring Autoleveller with Sainsmart Genmitsu 3018-MX3 and MACH3 USB

Autoleveller is a program used to aid in the process of milling printed circuit boards by probing the surface height of the pcb and using the probe data to create a height map. which is then used to modify gcode to take account of height variations.  This allows very fine traces to be milled from the thin copper layer of pcbs.

Autoleveller uses the G31 gcode command to probe the height at several locationa. Unfortunately the G31 command implemented on Chinese MACH3 usb controllers is often found not to be fully functional.

This was the case with the usb controller card supplied with the Sainsmart Genmitsu 3018-MX3 mini cnc.

There are several problems:

  1. The g31 command will happily run from the command line, but it will fail to complete if it is run from a gcode file containing other commands.
  2. The g31 command doesn’t update the 2002 variable
  3. The g31 command should write the triple x,y,z values to a file opened with the M40 macro, unfortunately it doesn’t.

The triple file is used by autoleveller to generate the height map so this is a significant problem.

To try and fix the first problem, I used a macro to insert a delay before and after the g31 gcode command.

This introduces a fixed delay followed by a delay until the axis have stopped moving. Unfortunately the g31 command would still not operate reliably. The only reliable solution was to ask the user:

The second problem was fixed by updating the 2002 variable after the g31 command finished.

To solve the problem of the triplet file not updating correctly,  I opened an alternative file and appended the x,y,z values to it.

This could then be used by the autoleveller program instead of the file opened by the M40 macro.

The full macros were created with the MACH3 script editor and placed in the Macros directory.





Autoleveller was set to use a custom controller and the custom controller options configured with the Pre-probe command set to M2001 and the Post probe command set to M2002.

Autoleveller Custom Controller Options

The Z initialisation block was modified to use a custom block and M2002 was replaced with M2003.

Autoleveller z initialisation block MACH3 USB

Then its simply a case of loading a gcode file and GENERATE PFG

Autoleveller Mesh Screen

Load the PFG gcode into MACH3 and then you will be asked to manually confirm if the g31 commands should start or if they have finished. It is a bit annoying to do this manually but at least it works!

I left the M40 & M41 macro commands in the script, so it still asks for a file name for the triplet logging, but the resulting file is redundant.

Once the probing process has completed the new file can be selected in Autoleveller.

File – Raw probe File
Select the g:\heightmap.txt file (or whatever you have called it)

Autoleveller RPF Screen

Autoleveller should hopefully now work as intended and modify the gcode to take account of the height map.

This was a quick way of getting autoleveller to work with the Sainsmart Genmitsu 3018-MX3 and it may well work for other MACH3 usb controller cards as well.

2 thoughts on “Configuring Autoleveller with Sainsmart Genmitsu 3018-MX3 and MACH3 USB

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.