Autoleveller and Mach 3 + BL-UsbMach-V22

Help for setting up and using
Post Reply
aislanmds
Posts: 1
Joined: Mon May 18, 2020 10:33 pm

Autoleveller and Mach 3 + BL-UsbMach-V22

Post by aislanmds »

Good evening for all.
I did some research here on the forum, but I couldn't solve my problem with Autoleveller. I saw that several users had problems with the Autoleveller and USB Card.

I'm using a Chinese USB card, and controller BL-UsbMach-V22.dll I'm having trouble probing the plate. I did a test using 2-stage to be able to view the log file, and on all lines it has the same information as the x, y, z coordinate.

I appreciate any help.

Thank you.

.nc File:
(This GCode script was designed to adjust the Z height of a CNC machine according)
(to the minute variations in the surface height in order to achieve a better result in the milling/etching process)
(This script is the output of AutoLevellerAE, 0.9.5u2 Changeset: ...2d0387 @ http://autoleveller.co.uk)
(Author: James Hawthorne PhD. File creation date: 17-05-2020 12:56)
(This program and any of its output is licensed under GPLv2 and as such...)
(AutoLevellerAE comes with ABSOLUTELY NO WARRANTY; for details, see sections 11 and 12 of the GPLv2 @ http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)

(The following is a checklist which can be used before the probe routine starts)
(The checklist may not be entirely correct given your machine, therefore you should make your own adaptations as appropriate)
(1. Make sure wires/clips are attached and the probe is working correctly)
(Test probe connections within control software before starting)
(2. Home all axis)
(3. Load GCode file that contains the probe routine into your software controller)
(4. Jog tool tip close to surface and touch off Z)
(5. Jog Z up a fraction to make sure surface is cleared)
(6. Jog to and touch off X and Y at the desired bottom left corner of the probe area)
(Note: The first probe will touch off Z to 0.0 when it first touches to the surface,)
(all other probe values are relative to this first point)

G90 G21 S20000 G17

M0 (Attach probe wires and clips that need attaching)
(Initialize probe routine)
G0 Z5 (Move clear of the board first)
G1 X0.27 Y0.27 F2500 (Move to bottom left corner)
G0 Z2 (Quick move to probe clearance height)
G4P1
G31 Z-15 F100 (Probe to a maximum of the specified probe height at the specified feed rate)
M2002
G92 Z0 (Touch off Z to 0 once contact is made)
M100
G0 Z2 (Move Z to above the contact point)
G4P1
G31 Z-15 F50 (Repeat at a more accurate slower rate)
M2002
G92 Z0
M100
G0 Z2

M40
G0 Z2
G1 X0.27 Y0.27 F2500
G4P1
G31 Z-15 F100
M2002
G0 Z2
G1 X10.59667 Y0.27 F2500
G4P1
G31 Z-15 F100
M2002
G0 Z2
G1 X20.92334 Y0.27 F2500
G4P1
G31 Z-15 F100
M2002
G0 Z2
G1 X31.25001 Y0.27 F2500
G4P1
G31 Z-15 F100
M2002
G0 Z2
G1 X41.57668 Y0.27 F2500
G4P1
G31 Z-15 F100
M2002
G0 Z2
G1 X51.90335 Y0.27 F2500
G4P1
G31 Z-15 F100
M2002
G0 Z2
G1 X62.23002 Y0.27 F2500
......
log File:
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
87.08814,52.40875,-21.79750
........
ngochoangimsat
Posts: 2
Joined: Mon Jul 07, 2025 6:50 am

Re: Autoleveller and Mach 3 + BL-UsbMach-V22

Post by ngochoangimsat »

GUIDE FOR USING AUTOLEVELLER WITH MACH3 USB

https://drive.google.com/file/d/1togonx ... drive_link

Table of Contents
I. Overview of AutoLeveller 2
II. Issues with Chinese Mach3 USB Controller Boards 3
III. Tested Solutions for Each Issue 3
1. Fixing Unstable G31 Execution in G-code 3
2. Fixing the Issue of Variables #2000, #2001, #2002 Not Updating 3
3. Fixing the Issue of X–Y–Z Triplet File Not Being Written 4
IV. Implementing the Complete Solutions in MACH3 4
1. Contents of Macro M2001.M1S 4
2. Contents of Macro M2002.M1S 5
3. Contents of Macro M2003.M1S 5
V. Configuring Operating Modes in AutoLeveller 6
1. Configuring Custom Controller Options 6
2. Configuring Z Initialisation Routine 6
VI. AutoLeveller Operating Procedure 8
1. Open the Original G-code File 8
2. Generate the Probe File G-code (PFG) 11
3. Load the PFG File into Mach3 11
4. Load the Probe Result into AutoLeveller and Generate Corrected G-code 12
VII. Conclusion 13




I. Overview of AutoLeveller
AutoLeveller is a software tool that assists in CNC height compensation based on the actual surface of the workpiece. A typical example is PCB milling calibration, where the surface height of a PCB is probed at multiple points to generate a height map. This height map is then used to modify the original G-code, compensating for surface height deviations and producing a new corrected G-code file.
Thanks to this process, it becomes possible to mill extremely fine and uniform traces on thin copper layers of PCBs.
• PCB milled without AutoLeveller: traces are uneven; some areas are too deep, some too shallow, and some areas do not fully remove the copper.
• PCB milled with AutoLeveller: traces are uniform, clean, and visually consistent.

PCB milled without AutoLeveller PCB milled with AutoLeveller
Figure 1. PCB milling with and without AutoLeveller
Detailed videos explaining how AutoLeveller works can be found here and here.
In general, AutoLeveller works perfectly with standard CNC controllers such as Mach3 LPT, LinuxCNC, and TurboCNC. However, when used with Chinese-made Mach3 USB controller boards, serious issues arise. This guide exists to address those issues.
Specifically, when used with Mach3, AutoLeveller relies on the G31 probing command. Unfortunately, G31 is often buggy on Chinese Mach3 USB controllers, resulting in unstable behavior or complete failure.
________________________________________

II. Issues with Chinese Mach3 USB Controller Boards
The following problems are commonly observed:
1. G31 runs correctly in MDI mode, but hangs or fails to complete when executed inside a G-code or script file together with other commands.
2. G31 does not update system variables #2000, #2001, and #2002, which should store the precise X, Y, and Z coordinates at the moment the probe is triggered.
3. According to Mach3 design, G31 should write the X–Y–Z triplet to a file opened by macro M40. However, in practice, the Mach3 USB plugin fails to write any data.
The file containing the X–Y–Z triplets is critical input data for AutoLeveller to generate the height map. Therefore, this issue is severe and must be addressed.
________________________________________
III. Tested Solutions for Each Issue
1. Fixing Unstable G31 Execution in G-code
An attempt was made to add delays before and after the G31 command using macros:
Sleep 500
While IsMoving()
Sleep 200
Wend
This code creates:
• A fixed delay
• A wait loop until all axes stop moving
However, in practice, G31 still behaved unpredictably.
The only reliable solution is to require manual user confirmation:
' Ask user to confirm axes are idle before starting G31
StartG31 = Question("Start G31?")
' Ask user to confirm G31 has completed before continuing
FinishG31 = Question("Finished G31?")
2. Fixing the Issue of Variables #2000, #2001, #2002 Not Updating
After G31 completes, manually update the variables using DRO values:
' G31 does not update variables 2000, 2001, and 2002
SetVar(2000, GetDro(0))
SetVar(2001, GetDro(1))
SetVar(2002, GetDro(2))
3. Fixing the Issue of X–Y–Z Triplet File Not Being Written
Instead of using the file opened by macro M40, a custom file is created and written manually:
' Read X, Y, Z values
x = GetDro(0)
y = GetDro(1)
z = GetDro(2)
' Open heightmap file and append data
Open "C:\heightmap.txt" For Append As #1
Write #1, x, y, z
Close #1
This file will be used directly by AutoLeveller instead of the default triplet file.
________________________________________
IV. Implementing the Complete Solutions in MACH3
Use Mach3’s built-in Script Editor or a standard text editor such as Notepad or Notepad++ to create the following macro files:
• M2001.m1s
• M2002.m1s
• M2003.m1s
Place them in the directory:
C:\Mach3\macros\Mach3Mill\
1. Contents of Macro M2001.M1S
'====================================================
' File location: C:\Mach3\macros\Mach3Mill\M2001.M1S
' M2001 - PRE PROBE ROUTINE
' Function:
' - Wait for axis stabilization
' - Require user confirmation before G31
'====================================================
Const DELAY_START = 500
Const DELAY_WAIT = 200
Sleep(DELAY_START)
While IsMoving()
Sleep(DELAY_WAIT)
Wend
StartG31 = Question("Start G31 probing now?")

2. Contents of Macro M2002.M1S
'====================================================
' File location: C:\Mach3\macros\Mach3Mill\M2002.M1S
' M2002 - POST PROBE ROUTINE
' Function:
' - Wait for G31 completion
' - Read X,Y,Z from DRO
' - Update variable #2002
' - Append data to heightmap file
'====================================================
Const DELAY_START = 500
Const DELAY_WAIT = 200
Const HEIGHTMAP_FILE = "G:\heightmap.txt"
Sleep(DELAY_START)

While IsMoving()
Sleep(DELAY_WAIT)
Wend
ProbeDone = Question("Finished G31 probing?")
Dim x, y, z
x = GetDro(0)
y = GetDro(1)
z = GetDro(2)
SetVar(2000, x)
SetVar(2001, y)
SetVar(2002, z)
Open HEIGHTMAP_FILE For Append As #1
Write #1, x, y, z
Close #1
3. Contents of Macro M2003.M1S
'====================================================
' File location: C:\Mach3\macros\Mach3Mill\M2003.M1S
' M2003 - INITIALIZE HEIGHTMAP FILE
' Function:
' - Wait for axis stabilization
' - Manual confirmation
' - Reset variable #2002
' - Create new heightmap file
'====================================================
Const DELAY_START = 500
Const DELAY_WAIT = 200
Const HEIGHTMAP_FILE = "C:\heightmap.txt"
Sleep(DELAY_START)
While IsMoving()
Sleep(DELAY_WAIT)
Wend
FinishG31 = Question("Initialize new heightmap file?")
SetVar(2000, GetDro(0))
SetVar(2001, GetDro(1))
SetVar(2002, GetDro(2))
Open HEIGHTMAP_FILE For Output As #1
Close #1
________________________________________
V. Configuring Operating Modes in AutoLeveller
This configuration only needs to be done once. AutoLeveller will remember the settings for future use.
________________________________________
1. Configuring Custom Controller Options
From the AutoLeveller menu:
• Select Options
• Select Custom Controller Options
Set:
• Pre-probe command: M2001
• Post-probe command: M2002

Figure 2. Configuration for user-defined custom controller options
________________________________________
2. Configuring Z Initialisation Routine
Z initialisation defines the probing initialization process and sets Z = 0 at the first probe point, which is then used as the reference for calculating surface deviations across the probing grid.
Steps:
1. In AutoLeveller, go to Options → Z initialisation routine
2. Enable Use default block and copy the default code
3. Enable Use custom block and paste the copied code
4. Replace M2002 with M2003
5. Click Apply to save
Repeat the same steps for both the PFG File and AL File tabs.

Enable Use default block and copy the default code Enable Use custom block and paste the copied code. Replace M2002 with M2003

Figure 3. Z initialisation configuration

________________________________________

VI. AutoLeveller Operating Procedure
1. Open the Original G-code File
The Original G-code File (OGF) is the file that needs height correction before actual milling.
In this example, the file is spindle.top.etchm3mm.tap.
This file is typically generated by PCB-to-G-code software such as:
• CopperCAM (commercial, paid or limited free version)
• FlatCAM (powerful and completely free)
Steps:
a. Click Load OGF in AutoLeveller
b. Select the original G-code file
c. When prompted to adjust the probing grid to the G-code extents, select YES
d. The screen displays the loaded G-code

a. Click Load OGF in AutoLeveller b. Select the original G-code file

c. When prompted to adjust the probing grid to the G-code extents, select YES d. The screen displays the loaded G-code
Figure 4. Opening the original G-code file
You may then adjust probing parameters if desired.

Figure 5. Adjust probing parameters if desired
________________________________________
AutoLeveller Parameter Descriptions
Controller
Select the appropriate controller:
• Mach3 → for Mach3 LPT systems
• Custom → for Mach3 USB controllers using this guide
Starting X / Starting Y
Starting coordinates of the probing grid
X Width / X Length
Dimensions of the probing area
XY feed
Feed rate for X–Y movement during probing (mm/min)
Z feed
Z-axis feed rate during probing (mm/min)
Probe depth
Maximum allowed Z probing depth.
For 3D probes, -1 mm is recommended to avoid probe damage.
Probe clearance
Height above the surface where slow probing begins
Point space
Distance between probing points
Probe safe height
Safe Z height for rapid movement between probe points
Total points / Points per row / Rows
Automatically calculated probing grid parameters

Figure 6. 3D probe
________________________________________

2. Generate the Probe File G-code (PFG)
After loading the OGF:
• Click GENERATE PFG
• Choose the save location and filename
• Example: PFG~100x80.nc

Figure 7. Generating the probe G-code file
________________________________________
3. Load the PFG File into Mach3
Load PFG~100x80.nc into Mach3.

Figure 8. Loading the PFG file into Mach3
Ensure the probe is functioning correctly before running the program.
Press Cycle Start to begin probing.
During execution, Mach3 will request manual confirmation:
• Before starting G31
• After completing G31
Although inconvenient, this method is reliable.
After completion, the file C:\heightmap.txt will be created, containing the surface height map.
Macros M40 and M41 are still present, so Mach3 may request a triplet file name, but this file is no longer used.
________________________________________
4. Load the Probe Result into AutoLeveller and Generate Corrected G-code
After probing:
• Go to File → Raw Probe File
• Select C:\heightmap.txt
AutoLeveller will use this file to generate the corrected G-code.

Figure 9. Actual surface height map
Click AutoLevel to generate the final corrected G-code file.
Use this file for actual CNC milling.
________________________________________
VII. Conclusion
This solution enables AutoLeveller to work reliably with Chinese Mach3 USB controller boards that have defective G31 behavior. Although manual confirmation before and after each G31 command is inconvenient, it ensures stable and accurate probing, allowing AutoLeveller to function correctly.
Post Reply