Jump to content

PCB Milling: Difference between revisions

From base48
imported>Rmarko
debug, adjusting depth size
Klubko (talk | contribs)
No edit summary
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Project
{{Project
  |founder=[[user:rmarko]]
  |founder=[[user:rmarko]]
  |status=active
|coops=[[User:Lubko|Lubko]]
  |status=operational
  |shortdesc=Milling and drilling PCB's on LinuxCNC
  |shortdesc=Milling and drilling PCB's on LinuxCNC
|image=Millingatbase.jpg
}}
}}


Step-by step PCB milling tutorial.
Tutorial for milling PCBs on the [[Small CNC]].


= Board preparation =
== Prepare the GCode ==
This part is done on your computer. The objective is to get GCode files for milling, drilling and outline cut and copy them to the controlling machine.


== Required software ==
=== Export from KiCAD ===
 
Up to date versions of KiCAD provide a command line tool to conveniently export Gerber and drill files.
Make sure you have following tools installed:
 
* Kicad or Eagle
* pcb2gcode - conversion of Gerber files to G-code
* pcb2gcodeGUI - GUI for pcb2gcode
* Camotics - G-code simulator for verification (optional)
* hacked_cnc - control, visualization and G-code leveling (optional, installed on linuxcnc host)
 
On Fedora pcb2gcode(GUI) can be installed from packages:
{{cmd|code=
{{cmd|code=
dnf install pcb2gcode pcb2gcodeGUI
kicad-cli pcb export gerbers --layers F.Cu,B.Cu,Edge.Cuts MyBoard.kicad_pcb
kicad-cli pcb export drill MyBoard.kicad_pcb
}}
}}


== Kicad export ==
=== Generate GCode ===
Use  [https://github.com/pcb2gcode/pcb2gcode pcb2gcode] to produce the GCode.


Note: it's better to export gerbers and gcode to separate folder, sometimes you need
Below is an example of a single-sided board drilled from the back side. It uses speeds, distances and feed rates that are known to work well with out machine and utilizes auto-leveling to compensate for deformation in clamping and the slight bent in Y-axis.
to re-export stuff to correct for errors and you don't want to mix files between revisions.


To export Gerber files from Kicad
Consult pcb2gcode manual to tune details or use utilize other features of the tool such as double-sided milling or tiling.
* choose File -> Plot
* set ''Plot'' format to ''Gerber'' (default)
* set ''Exclude PCB edge from other layer''
* select layers to export - depending on your design this is either F.Cu or B.Cu and Edge.Cuts layers
* click ''Plot'' on the bottom of the window
* click ''Generate Drill file'' next to ''Plot''
* set ''Drill Units'' to ''Millimeters''
* set ''Drill Origin'' to ''Absolute''
* click ''Drill File'' button on the right side of the window


== G-Code conversion ==
One-sided board (called "MyBoard") drilled from back:
{{cmd|code=
kicad-cli pcb export gerbers --layers F.Cu,B.Cu,Edge.Cuts MyBoard.kicad_pcb
kicad-cli pcb export drill MyBoard.kicad_pcb


To convert Gerbers to G-code use either pcb2gcode from command line
pcb2gcode \
or pcb2gcodeGUI.
  --back=MyBoard-B_Cu.gbl \
 
  --drill=MyBoard.drl \
Make sure to '''set correct drill side''', if your design is on F.Cu you want to drill from the front side (--dril-side=front) and vice versa.
  --outline=MyBoard-Edge_Cuts.gm1 \
 
  \
If you don't want to switch tools for drilling choose One drill option (--onedrill=true) which merges all drill operations to one
  --drill-output=MyBoard-drill.ngc \
file (bit size).
  --front-output=MyBoard-front.ngc \
  --back-output=MyBoard-back.ngc \
  --outline-output=MyBoard-outline.ngc \
  \
  --software=linuxcnc \
  --metric=true \
  --metricoutput=true \
  --zero-start=true \
  \
  --al-probe-on='(MSG, Probe on)' \
  --al-probe-off='(MSG, Probe off)' \
  --al-back=true \
  --al-x=5 \
  --al-y=5 \
  --al-probefeed=50 \
  \
  --zchange=20.0000 \
  --zsafe=2.0000 \
  --extra-passes=3 \
  --mill-feed=450 \
  --mill-speed=24000 \
  --offset=0.1500 \
  --zwork=-0.1000 \
  --drill-feed=250 \
  --drill-side=back \
  --drill-speed=12000 \
  --zdrill=-3.0000 \
  --bridges=0.8000 \
  --bridgesnum=4 \
  --cut-feed=200 \
  --cut-infeed=1.0000 \
  --cut-side=back \
  --cut-speed=24000 \
  --cutter-diameter=3.1750 \
  --zbridges=-0.0500 \
  --zcut=-1.7000
}}


== Simulation / preview ==
If pcb2gcode prints warnings, look into the *.svg files generated in working directory. They will contain visual indication of what is the problem.
 
You can verify if everything is correct by importing all files to Camotics G-code simulator.
 
Ideally your board should start at positive X, Y coordinates with lower left corner near X0/Y0.
 
== File upload ==


=== File upload ===
Upload folder to LinuxCNC machine:
Upload folder to LinuxCNC machine:
{{cmd|code=
{{cmd|code=
Line 63: Line 83:
}}
}}


= Machining =
== Machining ==
 
The following steps are done at the CNC milling machine.
== Machine preparation ==


* Start linuxcnc machine (reachable at linuxcnc.base48.cz)
You will be operating machine a machine that spin things very fast, moves with a lot of power and doesn't stop for meat. Avoid complacency and double-check things.
* Start machine controller
* Start cooling pump
* Pick a V-shaped tool from the box and install it


== Clamping ==
=== Safety essentials ===
* The '''big red button''' is an E-stop
* E-stop cuts power to motors when idle and in emergency
* F1 in LinuxCNC also acts as an E-stop
* Erroneous Z-axis movement or failed probe will break and eject the sharp tip of the tool
* '''Safety goggles are needed to protect eyes from flying debris'''
* Errors happen. Double-check commands and have an emergency plan!


Make sure to clamp PCB blank as good as possible as it's critical for the outcome of the leveling and milling.
=== Clamping ===
Make sure to clamp PCB blank as good as possible as it's '''critical''' for the outcome of the leveling and milling.


* Clamp PCB blank on top of piece of wood with at least 4 clamps
* Clamp PCB blank on top of piece of wood with at least 4 clamps
* Make sure RED wire is touching the PCB, it has to be put under one of the clamps so it won't come loose
* Attach the RED probe crocodile clip is attached to the PCB
* Double-check the proble clip. '''The tool will break during probing if there's no contact!'''


== LinuxCNC ==
=== Starting up ===
* '''Find the E-stop and make sure it's pressed'''
* Find a pair of safety goggles
* Power on the extension cord
* Make sure you hear the spindle cooling water pump operate
* Power on linuxcnc machine (the PC, reachable at linuxcnc.base48.cz)
* Power on machine controller


=== Starting CNC control ===
* Start LinuxCNC by running base_mill shortcut on the desktop
* Start LinuxCNC by running base_mill shortcut on the desktop
* Enable machine control by disabling emergency stop (F1) and enabling power (F2)
* '''Put on the safety goggles'''
* Position the machine with arrow keys to a starting point (bottom left corner of your future pcb)
* Depress the E-stop
* Enable power (F2)
* Position the machine with arrow keys to a starting point (bottom left corner of your future PCB)
 
=== Homing and preparing to mill ===
* Pick a V-shaped tool from the box and install it
* Home each axis of the machine, don't forget to home A axis as well
* Home each axis of the machine, don't forget to home A axis as well
* Load F.Cu or B.Cu G-code file
* Load mill file (e.g. ''MyBoard-back.ngc'')
* Try moving machine around displayed job to make sure it can actually reach all sides of the job without collisions
* Try moving machine around displayed job to make sure it can actually reach all sides of the job without collisions
* Switch to MDI tab (F5) (all the required commands in the following section should be present in the history)
* Switch to MDI tab (F5) (all the required commands in the following section should be present in the history)
Line 92: Line 128:
** Go back to manual tab and '''re-home Z axis'''
** Go back to manual tab and '''re-home Z axis'''


== Leveling ==
=== Milling ===
 
* Make sure you're wearing eye protection
* Switch to workspace 3, open terminal and find a directory with your jobs G-code files
* Run pcb2gcode_postproc.py in that folder
* Switch to workspace 4, find terminals with hacked_cnc directories
* In the first terminal (''~/hacked_cnc'') run
{{cmd|code=
./hcc server --linuxcnc
}}
* In the second terminal (''~/hacked_cnc/hc/ui/probe/'') run
{{cmd|code=
./probe.py
}}
* Open postprocessed file in probe GUI e.g. ''proj_front_post.ngc''
* Check if there are enough probe points for the size of your board and andjust if not
* Probing first goes to '''-margin''' which means it will start at '''X-3''' (default margin of 3mm) if your board stars at '''X0''', make sure there's enough free space for this move if you're tight on the space of the blank PCB - the margin has to be at least 1mm for leveling to work
* Run '''Run Probe'''
* When probing is done run '''Process'''
* File is automatically saved with ''lvl_'' prefix when processing is done
* Now switch back to LinuxCNC window and load suffixed file
 
== Milling ==
 
* Start job with blue arrow button
* Start job with blue arrow button
* Hope for the best, abort with F1 if stuff goes wrong
* Hope for the best, abort with F1 or E-stop if stuff goes wrong
* When asked to install or remove probe, just continue. Probing will run with the V-shaped milling tool


== Adjusting milling depth ==
=== Drilling ===
 
* Load drill file (e.g. ''MyBoard-drill.ngc'')
If your board is not milled deep enough
* Stop job with F1
* Disable safety stop by pressing F1 again
* In MDI tab
** Move machine to Z1 with '''G0 Z1'''
** Set machine position to e.g. Z1.1 to add 0.1mm with '''G92 Z1.1'''
 
== Drilling ==
 
* Load drill file
* Install correct drill bit
* Install correct drill bit
* To re-establish Z height again
* To re-establish Z height again
Line 137: Line 143:
* Start drilling job
* Start drilling job


== Outline ==
=== Outline ===
 
* Load outline file (e.g. ''MyBoard-outline.ngc'')
* Load 3.175mm endmill
* Load 3.175mm endmill
* Go to manual tab a re-establish Z height again by positioning tool slightly over the board
* Go to manual tab a re-establish Z height again by positioning tool slightly over the board
Line 144: Line 150:
* Start job
* Start job


= Post-processing =
== After milling ==
 
* '''Find the E-stop and make sure it's pressed'''
* Shut off the controller, PC and extension cord
* Vacuum the debris
* Clean your board with sandpaper and alcohol
* Clean your board with sandpaper and alcohol
* Use flux spray
* Use flux spray
* Leave a board on a warm place for a while
* Leave a board on a warm place for a while
* Clean-up and power down the machine meanwhile, remove tool from tool holder
* Take pictures
* Solder components
* Solder components
* Profit
* Profit
==== Oldstuff mov to git ====
=== pcb2gcode ===
  git clone https://github.com/pcb2gcode/pcb2gcode
sample make_gcode script
{{cmd|code=
#!/bin/bash
pcb2gcode \
--front=front-gerber-F.Cu.gtl \
--back=back-gerber-B.Cu.gbl \
--drill=drill.drl \
--outline=Edge.Cuts.gm1 \
--output-dir=gcode \
--dpi=1000 \
--metric=true \
--metricoutput=true \
--mirror-absolute=false \
--optimise=true \
--tile-x=1 --tile-y=1 \
--vectorial=false \
--zchange=20.0000 \
--zero-start=true \
--zsafe=2.0000 \
--extra-passes=3 \
--mill-feed=450 \
--mill-speed=24000 \
--offset=0.1500 \
--zwork=-0.0500 \
--drill-feed=250 \
--drill-side=back \
--drill-speed=12000 \
--milldrill=false \
--nog81=false \
--onedrill=false \
--zdrill=-3.0000 \
--bridges=0.8000 \
--bridgesnum=4 \
--cut-feed=200 \
--cut-infeed=1.0000 \
--cut-side=back \
--cut-speed=24000 \
--cutter-diameter=3.1750 \
--fill-outline=true \
--outline-width=0.2000 \
--zbridges=-0.0500 \
--zcut=-1.7000
}}

Latest revision as of 14:43, 17 September 2026


Tutorial for milling PCBs on the Small CNC.

Prepare the GCode

This part is done on your computer. The objective is to get GCode files for milling, drilling and outline cut and copy them to the controlling machine.

Export from KiCAD

Up to date versions of KiCAD provide a command line tool to conveniently export Gerber and drill files.

kicad-cli pcb export gerbers --layers F.Cu,B.Cu,Edge.Cuts MyBoard.kicad_pcb
kicad-cli pcb export drill MyBoard.kicad_pcb

Generate GCode

Use pcb2gcode to produce the GCode.

Below is an example of a single-sided board drilled from the back side. It uses speeds, distances and feed rates that are known to work well with out machine and utilizes auto-leveling to compensate for deformation in clamping and the slight bent in Y-axis.

Consult pcb2gcode manual to tune details or use utilize other features of the tool such as double-sided milling or tiling.

One-sided board (called "MyBoard") drilled from back:

kicad-cli pcb export gerbers --layers F.Cu,B.Cu,Edge.Cuts MyBoard.kicad_pcb
kicad-cli pcb export drill MyBoard.kicad_pcb

pcb2gcode \
  --back=MyBoard-B_Cu.gbl \
  --drill=MyBoard.drl \
  --outline=MyBoard-Edge_Cuts.gm1 \
  \
  --drill-output=MyBoard-drill.ngc \
  --front-output=MyBoard-front.ngc \
  --back-output=MyBoard-back.ngc \
  --outline-output=MyBoard-outline.ngc \
  \
  --software=linuxcnc \
  --metric=true \
  --metricoutput=true \
  --zero-start=true \
  \
  --al-probe-on='(MSG, Probe on)' \
  --al-probe-off='(MSG, Probe off)' \
  --al-back=true \
  --al-x=5 \
  --al-y=5 \
  --al-probefeed=50 \
  \
  --zchange=20.0000 \
  --zsafe=2.0000 \
  --extra-passes=3 \
  --mill-feed=450 \
  --mill-speed=24000 \
  --offset=0.1500 \
  --zwork=-0.1000 \
  --drill-feed=250 \
  --drill-side=back \
  --drill-speed=12000 \
  --zdrill=-3.0000 \
  --bridges=0.8000 \
  --bridgesnum=4 \
  --cut-feed=200 \
  --cut-infeed=1.0000 \
  --cut-side=back \
  --cut-speed=24000 \
  --cutter-diameter=3.1750 \
  --zbridges=-0.0500 \
  --zcut=-1.7000

If pcb2gcode prints warnings, look into the *.svg files generated in working directory. They will contain visual indication of what is the problem.

File upload

Upload folder to LinuxCNC machine:

scp -r project/ base@linuxcnc.base48.cz:<your_nick>/

Machining

The following steps are done at the CNC milling machine.

You will be operating machine a machine that spin things very fast, moves with a lot of power and doesn't stop for meat. Avoid complacency and double-check things.

Safety essentials

  • The big red button is an E-stop
  • E-stop cuts power to motors when idle and in emergency
  • F1 in LinuxCNC also acts as an E-stop
  • Erroneous Z-axis movement or failed probe will break and eject the sharp tip of the tool
  • Safety goggles are needed to protect eyes from flying debris
  • Errors happen. Double-check commands and have an emergency plan!

Clamping

Make sure to clamp PCB blank as good as possible as it's critical for the outcome of the leveling and milling.

  • Clamp PCB blank on top of piece of wood with at least 4 clamps
  • Attach the RED probe crocodile clip is attached to the PCB
  • Double-check the proble clip. The tool will break during probing if there's no contact!

Starting up

  • Find the E-stop and make sure it's pressed
  • Find a pair of safety goggles
  • Power on the extension cord
  • Make sure you hear the spindle cooling water pump operate
  • Power on linuxcnc machine (the PC, reachable at linuxcnc.base48.cz)
  • Power on machine controller

Starting CNC control

  • Start LinuxCNC by running base_mill shortcut on the desktop
  • Put on the safety goggles
  • Depress the E-stop
  • Enable power (F2)
  • Position the machine with arrow keys to a starting point (bottom left corner of your future PCB)

Homing and preparing to mill

  • Pick a V-shaped tool from the box and install it
  • Home each axis of the machine, don't forget to home A axis as well
  • Load mill file (e.g. MyBoard-back.ngc)
  • Try moving machine around displayed job to make sure it can actually reach all sides of the job without collisions
  • Switch to MDI tab (F5) (all the required commands in the following section should be present in the history)
    • To get to the starting point run G0 X0 Y0
    • To home Z-axis use G38.2 Z-100 F30
    • Go back to manual tab and re-home Z axis

Milling

  • Make sure you're wearing eye protection
  • Start job with blue arrow button
  • Hope for the best, abort with F1 or E-stop if stuff goes wrong
  • When asked to install or remove probe, just continue. Probing will run with the V-shaped milling tool

Drilling

  • Load drill file (e.g. MyBoard-drill.ngc)
  • Install correct drill bit
  • To re-establish Z height again
    • Go to Manual tab (F3) and position a head outside of the milled PCB near clamp with probing wire attached so probing is possible, then few millimeters on top of the spot but don't try to make contact
    • Go to MDI tab (F5) and issue probing command G38.2 Z-100 F30
    • Go back to manual tab and re-home Z axis
  • Start drilling job

Outline

  • Load outline file (e.g. MyBoard-outline.ngc)
  • Load 3.175mm endmill
  • Go to manual tab a re-establish Z height again by positioning tool slightly over the board
  • re-home Z axis
  • Start job

After milling

  • Find the E-stop and make sure it's pressed
  • Shut off the controller, PC and extension cord
  • Vacuum the debris
  • Clean your board with sandpaper and alcohol
  • Use flux spray
  • Leave a board on a warm place for a while
  • Take pictures
  • Solder components
  • Profit