LinuxCNC07. Jul '16

Introduction

LinuxCNC is a Debian based distribution which includes realtime kernel for running stepper drivers connected to a parallel port, EMC2 the graphical user interface for working with CNC machines. This howto assumes you have already produced Gerber files, eg by plotting your KiCad PCB layout.

Converting Gerbers to toolpaths

Utility for converting Gerber files to .ngc files which are understood by LinuxCNC.

Plot Gerber pcb2gcode design-B.Cu.gbl design-F.Cu.gtl design.drl Generate Drill File back.ngc front.ngc drill.ngc LinuxCNC/EMC2 Kicad PCB layout

To install pcb2gcode on Fedora 25:

dnf install pcb2gcode

To install pcb2gcode on LinuxCNC itself or a Ubuntu workstation:

apt install pcb2gcode

Following generates front.ngc, back.ngc, drill.ngc toolpath files with coordinates reset to resulting toolpaths instead of original PCB layout coordinates. All drilling is squashed into single tool path, in our case we used only 1mm drill. The design will not be tiled, increase tile-x and tile-y to cut multiple identical copies of the design.

pcb2gcode \
    --zero-start \
    --onedrill \
    --software linuxcnc \
    --tile-x 1 \
    --tile-y 1 \
    --front *-F.Cu.g* \
    --back *-B.Cu.g* \
    --drill *.drl \
    --front-output front.ngc \
    --back-output back.ngc \
    --drill-output drill.ngc \
    --metric \
    --zwork 0 --offset 0.2 \
    --zsafe 3 --zchange 40 \
    --mill-feed 500 \
    --mill-speed 6000 \
    --zdrill -3 \
    --drill-feed 500 \
    --drill-speed 6000

Milling depth is set to 0mm, make sure you home Z axis to desired cutting depth before executing the toolpath. Milling offset is 0.2mm, that is to compensate for the milling bit cut width. When moving between paths tool is raised 3mm above the surface. Drilling depth is set to 5mm, make sure you home Z axis before drilling to the surface of the PCB. Milling and drilling feed is set to 500mm/minute. Milling and drilling speed is set to 6000rpm if your setup supports setting spindle speed.

Installing LinuxCNC

To use LinuxCNC in production you need realtime capable kernel. Folks at LinuxCNC have packaged it up and it's installable as a separate ISO file. To download it and copy to a memory stick, make sure you replace sdz with the device corresponding to the block device of your memory stick:

wget http://www.linuxcnc.org/linuxcnc-2.7-wheezy.iso
cat linuxcnc-2.7-wheezy.iso | pv > /dev/sdz

Install it to a PC which has parallel port, USB-parallel port converters we tried didn't have drivers for the rather outdated realtime kernel included with LinuxCNC.

Assembling CNC machine

Following is not going to go in depth with CNC frame construction. CNC frames can be ordered from AliExpress for reasonable price, 3020T has (trapezoidal) lead screw and can be ordered for around 500USD. Note that lead screw is cheaper and requires less torque to hold the position whereas ball screw is more precise but expensive and might need more powerful stepper motors to hold position, see pros and cons here.

Use a breakout board to make it easier to connect stepper drivers to the parallel port. Note that the breakout board does not include any essential functionality, it simply makes things more convenient, has a relay for turning the spindle on and off and as a cherry on the top uses optocouplers to electrically separate parallel port from the rest of the machinery to protect the PC in case of a disaster.

http://www.sunrom.com/media/content/493/images/cnc-wiring.gif

Wiring diagram for breakout board

Poor man's solution is to simply use a printer cable, connect individual wires to the stepper drivers. In our case we used Toshiba TB6600 based stepper drivers:

https://d1j1kxp9fqehmk.cloudfront.net/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/0/1/01_95.jpg

TB6600 based stepper drivers

For 3020T the NEMA 23 stepper motors were suitable, NEMA 17 steppers were also tested but didn't deliver enough torque to drive the CNC. Note that NEMA 17 and NEMA 23 in reality refer to the mounting hole dimensions, there are variety of motors made by different manufacturers and slightly different dimensions and electrical characteristics.

https://www.poscope.com/wp-content/uploads/2016/02/nema23.jpg

NEMA 23

Note that in certain configurations the CNC frame comes without stepper mounting bracket. You can try your luck with threaded rod or use a 3D printer to print one. Also shaft couplers are required to connect NEMA motors to the CNC frame's lead screws:

http://cdn.shopify.com/s/files/1/1625/4675/products/24_1_ae9403e7-3f4b-4488-a508-ce81b12dafd2_grande.jpg?v=1492328443

Note that it is probably easier to purchase whole kit which includes at least steppers and spindle.

Milling and drilling bits

Most PCB milling and drilling bits have 1/8 inch (3.175mm) diameter shank, that's the end mounted to spindle.

After experimenting with 90°, 60°, 30°, 10° mill bits and different drill bits it eventually boiled down to two.

For milling traces 60° carbide mill bit is suitable:

https://img1.banggood.com/thumb/view/upload/2015/07/SKU234361%20(1).jpg

For most drilling holes 1mm drill bit is enough:

https://s-media-cache-ak0.pinimg.com/736x/48/e0/c8/48e0c86e341af43aa2418bcf77afe091.jpg

The pcb2gcode command example merges all drill tool paths so you can leave the machine unattended during the drilling job, otherwise tool change is requested while moving to a drilling hole of different size.

Milling PCB with LinuxCNC

Place PCB on the sacrificial material and use paper tape to fix it to the board. Make sure spindle is stopped and insert 60 degree mill bit. Press F1 to toggle Emergency Stop and press F2 to turn on stepper drivers. Use up, down, left, right arrow and Page Up/Down buttons to drive the CNC head along X, Y and Z axes. Slide Jog speed to the max to move faster.

Important

Press Shift-1 to switch between imperial (inch) and metric systems (mm).

Move the head along X and Y axes to the starting point. Select X axis hit Home button, select Y axis and hit Home again. Press Page Down to drive the mill bit into the copper layer into desired cutting depth. Select Z axis and hit Home button. Press Page Up to drive mill bit away.

Open front.ngc, press R to begin executing the current file:

img/linuxcnc-front.png

LinuxCNC milling front layer

Once the milling is ready do not power down the steppers as you would lose the X and Y axis alignment. If you have manually controlled spindle simply stop the spindle. Replace the mill bit with drill bit. Use Page Up and Page Down to drive the drill bit near the copper surface, but not into it. Select Z axis and hit Home button to rehome Z axis for drill bit.

img/linuxcnc-drill.png

LinuxCNC drilling holes

Move the head away while making sure you don't accidentally run into the frame limits as this would again lose the X and Y alignment.

Use cordless drill to cut though some of the mounting holes into the sacrificial material, preferably the ordermost ones. Remove mounting tapes, flip the PCB along Y axis. Use bolts to align flipped PCB to the holes in sacrificial material. Retape the PCB and remove bolts.

img/linuxcnc-back.png

LinuxCNC milling back layer

EMC2 on Ubuntu or Fedora

It might become handy to run EMC2 the graphical user interface of LinuxCNC on your daily driver distro simply to test your *.ngc files, but there are no packages available for Ubuntu or Fedora. The graphical user interface can still be fortunately compiled from source.

System Message: WARNING/2 (./posts/./linuxcnc.rst, line 227); backlink

Inline emphasis start-string without end-string.

To install dependencies on Fedora 25:

dnf install libudev-devel libmodbus-devel libusb-devel gtk2-devel bwidget \
    tkimg-devel tclx boost-devel libXmu-devel autoconf git gcc-c++ \
    readline-devel pygtk2

To install dependencies on Ubuntu 14.04:

apt install libudev-dev libmodbus-dev libusb-1.0-0-dev tcl-dev tk-dev \
    bwidget libtk-img tclx  libboost-python-dev libxmu-dev libreadline-dev \
    freeglut3-dev libglib2.0-dev libgtk2.0-dev autoconf git

Fetch source code:

git clone https://github.com/LinuxCNC/linuxcnc
cd linuxcnc/

Compile from source:

cd src/
./autogen.sh
./configure --enable-non-distributable=yes
make -j4
cd ..

Run from source tree without installing to system:

./scripts/rip-environment linuxcnc

In the menu select axis and click OK.

LinuxCNC Gerber PCB KiCad CNC