Adding auto-leveling to CNC USB Controller

June 10, 2018 Maker

In my previous post, I mentioned that my 3020 CNC allows my make circuit boards like the ones below, which requires accurate control over the cut depth. In this post, I’ll go deeper into how I achieved this level of control using some software I wrote.

Limits to leveling

As mentioned before, getting the cut depth just right when using V-shaped engraving bits is essential. Too shallow, and the traces won’t get isolated from each other. Too deep and you’ll quickly end up with dull bits and with torn or overly thin traces.

In its most basic form, the cut depth can stabilized from location to location by first milling a flat area into a waste board before the copper-clad circuit board is stuck onto it. This removes any major misalignments between the axes and the bed. However, the copper layer’s height may still vary too much for V-carving as the copper-clad board (or adhesion layer) may vary in thickness or may be curved.

Auto leveling

Auto leveling is a process that tries to compensate for height differences instead of trying to prevent them. First, the CNC is used to probe the local height of the PCB in lots of places. Then, these probed heights are used to adjust any G-Code path such that they curve along with any detected imperfections.

Probing the height of a PCB locally is typically done by slowly lowering an end mill until an electric connection is made between the end mill and board’s copper layer. Getting this to work was easy for me as my CNC machine came with both the necessary hardware and software to do this. However, probing over a grid and then using this to distort G-Code to do auto-leveling was unsupported.

Obviously, I could’ve bought better electronics and software. But being a software developer, I had other options as well. In turns out that CNC USB Controller, which is the Windows control software my machine came with, can be controlled through command-line arguments as well as through a COM interface. This makes it possible to add support for auto-leveling using my own external applications.

My toolset

Here’s an example of the resulting process:

At the beginning of this clip, I’m starting my command-line tool called cnc_warp_probe. The used command-line arguments tell it to probe an area of 40 x 40 mm using 4 x 4 measurements. In turn, this tool makes CNC USB Controller take the individual measurements at all the right locations, and stores the collected probe data into a text file. When it finished probing at all 16 different locations, I then copied the G-Code onto the clipboard and called code_warp_gcode_clipboard.bat. This feeds the probe text file and the G-Code on the clipboard into a second tool called cnc_warp_gcode. This second tool takes the probe text file, fits a quadratic surface through it, and uses it to vertically adjust the G-Code. The .bat file then puts the adjusted G-Code back onto the clipboard, after which I complete the procedure by pasting that into CNC USB Controller again.

These tools have been very useful for me, and I’ve made them open source so that anyone can use them freely. Please do understand that this is just a hobby project, so I do not offer any guarantees or support, nor do I accept any kind of liability. Links to the source code and the binaries are below. The code has been written in C/C++, so anyone comfortable in Visual Studio should be able to build and extend it in any way they want. Enjoy!


  • Tool binaries [ZIP]. Last updated on Jun 16, 2018.
  • Tool source code [Bitbucket]. Last updated on Jun 16, 2018.

Previous post: CNC-ing different materials (June 5, 2018)
Next post: Reducing noise and dust (June 24, 2018)

Comments (5)

April 5, 2019

Thanks for this, unfortunately it doesn’t work on my version of the software (SW 2.10.1208.601), I get an error trying to register the DLL.

RegAsm.exe “C:\Program Files (x86)\CNC USB Controller\CNCUSBControllerAPI.dll” /codebase
Microsoft .NET Framework Assembly Registration Utility version 4.7.3190.0
for Microsoft .NET Framework version 4.7.3190.0
Copyright (C) Microsoft Corporation. All rights reserved.

RegAsm : error RA0000 : Could not load type ‘TrajBuffer’ from assembly ‘CNCUSBControllerAPI, Version=2.10.1707.1201, Culture=neutral, PublicKeyToken=null’ because it contains an object field at offset 166484 that is incorrectly aligned or overlapped by a non-object field.

I think my version is different to yours, I bought it a few weeks ago. Here’s the directory listing

Directory: C:\Program Files (x86)\CNC USB Controller

Mode LastWriteTime Length Name
—- ————- —— —-
d—– 27/03/2019 16:45 Driver
d—– 27/03/2019 16:45 Samples
d—– 27/03/2019 16:45 Scripts
-a—- 08/08/2012 01:28 8664576 CNCUSBController.exe
-a—- 27/03/2019 16:45 4667 CNCUSBController.keys
-a—- 27/03/2019 16:54 249 CNCUSBController.lic
-a—- 17/12/2011 23:21 3223299 CNCUSBController.pdf
-a—- 05/04/2019 14:16 33923 CNCUSBController.setting
-a—- 05/04/2019 13:13 33988 CNCUSBController.setting.bak
-a—- 05/04/2019 13:19 3027 CNCUSBController.var
-a—- 02/04/2019 21:53 3027 CNCUSBController.var.bak
-a—- 10/07/2017 16:04 251560 CNCUSBControllerAPI.dll
-a—- 27/03/2019 16:57 16286 unins000.dat
-a—- 27/03/2019 16:57 1174979 unins000.exe

July 27, 2019


Thanks for your soft.
I’m testing currenlty.

My CNC is home made and the hard controller is an Eleksmaker IVAxis.
I did not configure the limits in CNC USB controller and did not connect a probe.

With your sample : >cnc_warp_probe.exe probe_measurement.txt 0 0 40 40 1000 4 4 1

I see the X / Y moving but not the Z.

Did you have an idea if I have to configure something first into CNC USB Controller to have your program working ?

Tx in advanc,

Best regards


July 27, 2019


I found into the CNC USB Controller (since is like a MK1 board) ..

many thanks !

it’s works ;)

February 17, 2020

Big thanks!

I know even small beer is better but how :)

Just for users who have custom settings of the cnc with custom settings name it is better to rename it to CNCUSBController.setting, other option is probably to change it in the code and than to build.

Also for me it was the easiest way to “connect” dll-s to put cnc_warp_probe.exe in the usb cnc instalation folder (c:\Program Files (x86)\CNC USB Controller\)

once again thanks for great work

February 19, 2020

Thanks for the tips, Stevan

Leave a comment