# Drilling through-hole components using a CNC machine

[[Home|/home]] ► [[Electronics|/electronics]] ► [[Circuit board fabrication|/electronics/pcbfabrication]] ► Drilling through-hole components using a CNC machine

___

**Software**

* [KiCad](http://kicad-pcb.org/)
* [FlatCam](http://flatcam.org/)
* [CAMotics](https://camotics.org/)
* [bCNC](https://github.com/vlachoudis/bCNC)

## Generating drill files

Use "Place the origin point for drill and place files" in KiCad to put the 0,0 point in a reasonable spot. Preferably on one of the holes that need to be drilled, or any other easy to find reference point on the etched board.

Go to Plot and choose Generate Drill File. Use Excellen for the File Format with Gerber as the Drill Map File Format. Select Auxiliary Axis as Drill Origin and click Generate Drill File. This will generate two files; PTH (Plated Through-Hole) and NPTH (Non-Plated Through-Hole). The PTH file will contain the locations for via's and through-hole components.

It might be useful to use "PTH and NPTH holes in single file" if you want to process all holes in one go.

If you only have a back copper layer, use "Mirror Y axis" to be able to drill the board from the copper side.


## Generating the G-code
Start FlatCam and use File - Open Excellon to select the PTH file. Now double-click the file that you've just opened in the Project tab. The tab "Selected" will now activate with "Excellen Object" in the title.

Under Tools select the items for the tool you want to use, there will be more than one if there are different diameter holes. Check the settings under "Create CNC Job": Cut Z -2, Travel Z 3, Feed rate 60. Click "Generate". Repeat if necessary for the other tool diameters.

Go back to the Project tab and double-click the newly generated drl_cnc, then click on Export G-Code.

## Previewing the result
Open CAMotics. Open the G-code file and click the Start button to get a real-time preview of the result. This is a good indicator if the FlatCam settings were correct.

## CNC
TODO: explain bCNC

Note: the spindle probably won't work until you use the Unlock button.
If you're also using the CNC for a laser, make sure to put it back into milling mode!

Useful shortcuts for positioning the tool:

Arrow keys = X / Y
Page up/down = Z
1, 2, 3 = 0,1mm, 1mm, 1cm movement