Open Source CNCing

Last year Sienci Labs finished its Kickstarter campaign for the open-source LongMill Benchtop CNC Router — its second successful open-source CNC machine Kickstarter campaign. CNC routers allow users to mill things (like parts) from raw materials (like a block of aluminum) based on a 3D-model. The LongMill is a significant improvement over the original sold-out Mill One and makes professional-quality machining based entirely on open-source technology a reality. As an owner of a LongMill, I will walk through the various open-source technologies that make this tool a cornerstone of my home workshop.

Hardware

The Sienci Labs LongMill is an impressive feat of engineering, using a combination of off-the-shelf hardware components alongside a plethora of 3D-printed parts. The machine, once assembled, is designed to be mounted to a board. This board, called a spoilboard, is a board the machine can “accidentally” cut into or otherwise suffer damage — designed to be occasionally replaced. In most circumstances, the spoilboard is the top of a table for the machine, and Sienci provides documentation on several different table builds done by the community. For builders short on space, the machine can be mounted on a wall.

The complete 3D plans for the machine are available for download, including a full bill of materials of all of the parts needed. The project also provides instructions to assemble the machine and how best to 3D print relevant components. The machine is controlled by the LongBoard CNC Controller, and Sienci Labs provides full schematics [23MB ZIP] of that as well. All mentioned materials are licensed under a Creative Commons BY-SA 4.0 license.

In addition to the open-source design of the machine itself, an open-source-minded community has formed around the project. The company’s Facebook user group has 1,600 members, and an active community forum is hosted by the company, which discusses everything from tips to machine support. Community members contribute, among other things, various modifications to improve the original design or to add new features such as a laser engraver.

Software

When it comes to a fully functional CNC, the hardware behind it is only part of the equation. There is an entire software stack needed to go from a model to a physical thing. To explain this, I thought it best to have an example to refer to. For this example, I borrowed this design for a Tux drink coaster, scaled up its size, and used it to produce this quick example of the LongMill in action:

Milled Tux
Milled Tux

There are a lot of different software options, both open source and commercial, that can be used to mill something like this. In this case, I am starting with an STL file and I need to translate that data into actions for the mill to take to carve the image. Looking at the entire process generically, the steps would be: design something, build tool paths (movements of the CNC machine), and then send tool paths to the machine. I already have the design, so I will start with generating tool paths.

The process of converting a design into a series of movements taken by a machine is called computer-aided machining (CAM). Depending on the work being done, there are many different types of CAM software available to take some sort of model and convert it into one (or more) tool paths. In the open-source world there are many choices — for example there is a list of open-source options that was compiled on Reddit. What CAM software is used depends greatly on the experience of the user and the needs of the project. In this case, I used CAMLab developed and hosted by Sienci Labs; CAMLab is based on the MIT-licensed Kiri:Moto project. CAMLab is meant to be a beginner-level tool that is easy to use; it operates directly on STL files. In other projects, such as when I am using the CNC to create my own prototype PCB circuit boards, open-source projects like FlatCAM (MIT-licensed) are a much better tool for the job. Unlike CAMLab, FlatCAM works from Gerber files generated by electronics-design tools like KiCad (GPLv3) — instead of STL files.

The job is the same regardless of the CAM software used: take the model provided, combine it with information about the material being cut along with the tool that will be used to cut it, and generate a tool path. What follows is a screenshot from CAMLab, showing the tool path generated by a 2mm cutting tool on our Tux model. In this screenshot, the tool path is indicated by the black lines, while non-cutting moves are indicated in blue:

Tool path screenshot of Tux
Tool path screenshot of Tux

Observant readers may note that the generated tool path appears to ignore portions of the model — specifically the narrow lines in Tux’s face. This is not an error, but captures that this model required making a second pass using a smaller 0.8mm tool to fill in the details that the larger tool couldn’t accomplish. This tool path would be generated and run separately from the first, with a physical change in tools in between. Ultimately three separate tool paths needed to be generated and executed to complete the carve. Two of them were for the actual relief of Tux (a 2.0mm and 0.8mm end mill), and a third to cut the circle from the wood stock using an 8.0mm end mill.

Ultimately, the tool path generated by the CAM software is saved to a file to be transmitted to the CNC machine using a language known as G-code. Different CNC machine controllers implement different dialects of G-code, depending on the software of the controller. In the case of LongMill, the LongBoard CNC Controller uses an off-the-shelf Arduino Uno as its processing unit, running the open-source G-code interpreter Grbl (GPLv3). The G-code is sent to the Arduino Uno on the controller via a serial connection.

G-code is a line-based, interpreted language (G-code reference). Below is a small G-code example that sets the current position of the tool in the CNC machine as the origin, moves up 10mm, over on the Y axis 10mm, then returns to origin:

    P0 L20 X0 Y0 Z0 ; Set current location as origin
    G0 Z10          ; Move the head up 10mm
    G0 Y10          ; Move the head on the Y-axis 10mm
    G0 X0 Y0        ; Move back to origin for X/Y
    G0 Z0           ; Lower head back to origin

A look at Grbl internals would tell you that it can only buffer, at best, sixteen G-code instructions at a time. In contrast, tool paths generated by CAM software can be hundreds of thousands of lines of G-code. Thus, for sending the G-code file generated by a CAM tool, we need a utility that can buffer the G-code instructions sent to the CNC controller. Again, there are many different open-source tools available for a job like this, but I use a project called Universal Gcode Sender (UGS — GPLv3 licensed). I selected UGS because it offers features specifically for Grbl and overall works well. In my setup, UGS runs on a Raspberry Pi 4 connected to the LongMill’s controller, where G-code files are then opened and transmitted to the CNC to do a job — in this case, carve out our Tux model.

While G-code is typically generated by CAM software, it is not uncommon for it also to be written by hand in a variety of contexts. Some CAM software offers the ability to inject custom G-code at various points in the tool path generation (for example), while almost all G-code sending platforms like UGS provide a serial console for manual G-code input — if not an entire G-code macro system. In typical usage, users often write small G-code scripts (or one-liners) by hand to do specific tasks unique to their device, situation, or preferences. For example, it is often faster to move the tool on a CNC to the desired location on the bed by a line of G-code than it would be to use the provided movement controls in an application like UGS.

Wrapping up

Working with a CNC is the subject of multitudes of books and web sites, and the number of open-source projects available in this space is probably just as large — we’ve only scratched the surface here. There are many more aspects of this space to cover, such as open-source modeling programs like OpenSCAD, that may make interesting subjects in the future. What we hope to have made clear is that CNC technology from start to finish is now available to the world in a reasonably accessible form — using nothing but gratis open-source projects. For open-source enthusiasts (or professionals), it is most welcome to see another historically proprietary space develop FOSS alternatives.