Computer numerical control, or CNC, is a method of controlling machine tools via a computer.
CNC mills and lathes are typically used when high precision or repeatability is needed. For example, this is helpful for drilling hundreds of identical holes to create an optical breadboard. To be precise, this method of creating a part is classified as “subtractive manufacturing” since the part is created by gradually removing material.
In contrast, 3D printing is an additive manufacturing process which also produces parts using computer and microcontroller control. In fact, 3D printers are also CNC machines, but given their unique popularity, they’re rarely referred to as such.
In 3D printing, a part is created through the addition of material until a full part is created. In FDM 3D printing, this is accomplished by melting and extruding filament. 3D printing is very useful for creating custom parts and prototypes before a final design is reached.
Coincidentally, both 3D printers and CNC machines are controlled using G-code, which is a set of commands beginning with the letter “G” (as well as many other letters). Each command represents a micro-step in the process of crafting the final object. Among other things, G-code commands tell machines how to move and how to adjust settings, such as nozzle temperature on a 3D printer or cutting speed on a CNC. But even though both 3D printers and CNC mills use G-code, there are some significant differences in these two applications.
Several differences exist between 3D printing and CNC milling that affect their respective G-codes:
Since CNC mills and 3D printers came about at different times, there are differences in what the same command means. Let’s look at some specific examples below.
When Interchanging G-code Works
Let’s say we need to tell a machine to move rapidly from one location to another. To do that, we could use:
G21G0 X242 Y347 Z52
G21 tells the printer to treat all numbers as if they were in millimeters, G0 instructs the machine to move to location (X, Y, Z) as fast as possible, and the numbers following X, Y, and Z indicate coordinates to move to.
On a 3D printer, this would move the print head to a location (242 mm, 347 mm, 52 mm) as rapidly as possible. On a CNC mill, the G21 and G0 commands would still work and the machine would behave like the 3D printer.
When Interchanging G-code Fails
G26 C P O2.25
On a 3D printer, this would start mesh bed leveling. Meanwhile, on a CNC, G26 turns spindle speed fluctuation detection off. There are many additional examples of the same code diverging in use from 3D printing to CNC milling. Keep in mind that this difference occurs for a particular version (1.1.0) of the Marlin firmware. For other types of 3D printing firmware, such as Repetier, code G26 isn’t even supported.
Interested in seeing more G-code? Check out our other articles on the topic:
This is where things get complicated.
When it was first developed, G-code was never meant to be used by 3D printers. Thus, only a small subset of standard commands were created. Once 3D printers came along, many of these codes were reused, such as G0 and other movement commands. This allowed for 3D printers to function well when they print objects.
But with the proliferation of multitool 3D printers that can both print and accomplish CNC machining, among other tasks, additional commands are needed. To use a laser, mill, and nozzle, the existing codes are insufficient. This makes it difficult to use standard G-code since the two types of G-code have diverged as in our example above.
Hence these all-in-one devices generally do not run on standard G-code, and instead a proprietary firmware is used. While this may solve the problem for these devices, it creates new problems. Standard slicers are unable to determine what the custom codes mean. Therefore, slicers are unable to translate models into sufficiently complex G-code to be used on the devices. This is why companies like Snapmaker and ZMorph use modified versions of G-code.
Now you know how and why CNC G-code and 3D printer G-code are different. Perhaps one day we’ll have new standards that give us a fully functional multi-axis 3D printing and CNC device that works with slicers.
Feature image source: interestingengineering.com
License: The text of "3D Printer G-code vs CNC G-code – What’s the Difference?" by All3DP is licensed under a Creative Commons Attribution 4.0 International License.