Featured image of 3D Printer G-Code vs CNC G-Code – What’s the Difference?

3D Printer G-Code vs CNC G-Code – What’s the Difference?

Aug 7, 2019 by Benjamin Goldschmidt

3D printers and CNC mills both use G-code, but have you ever wondered what the difference is? Dip your toes into the world of G-code and explore the differences between 3D printing and CNC milling.

Advertisement

3D Printer vs CNC G-Code A Tale of Two Technologies

A niche desktop CNC mill, the Carbide3D Nomad.
A niche desktop CNC mill, the Carbide3D Nomad. Source: Carbide3D

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.

3D Printer vs CNC G-Code Technologies Contrasted

G-code actually uses a variety of letters beyond 'G' to signify different functions.
G-code actually uses a variety of letters beyond 'G' to signify different functions. Source: www.autodesk.com

Several differences exist between 3D printing and CNC milling that affect their respective G-codes:

  • The number of axes is different. As opposed to CNC mills, which traditionally have up to five axes, most 3D printers only have three. As such, many of the commands in the G-code library aren’t even used. Of course, exceptions exist, such as the Hyrel Hydra 3D printer that can print in 5 axes.
  • 3D printer tools don’t spin. Unlike traditional CNC machines that utilize spinning mill bits, 3D printers deposit material layer by layer. Therefore, there isn’t any reason to use commands that set tool speed. Once again, there are some all-in-one machines that present exceptions, such as the ZMorph VX.
  • 3D printers typically have fixed toolheads. Most 3D printers do not have removable hot ends that can be swapped out for more complex parts, whereas CNC mills can usually swap out bits to better perform different cuts. As always, exceptions exist in the 3D printing world, this time in the form of custom toolhead mounts.
  • 3D printer G-Code consists primarily of G and M commands. Due to the relative simplicity of 3D printers, the two main command types that are used tend to be G and M codes. G-codes deal with moving motors and parts, while M-codes deal with machine-specific settings that tell the printer what to do. For example, an M-code exists for setting nozzle temperature on virtually every functional 3D printer. These M-codes vary by machine (for both 3D printing and CNC) and are therefore not standardized.

3D Printer vs CNC G-Code Why Not Use the Same Thing?

Using the wrong G-code commands can make your printer do weird things.
Using the wrong G-code commands can make your printer do weird things. Source: Maker's Muse / YouTube

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:

Advertisement

3D Printer vs CNC G-Code All-In-One Machines

The Snapmaker 2 is an iconic all-in-one machine.
The Snapmaker 2 is an iconic all-in-one machine. Source: Windows Central

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.

Subscribe to updates from All3DP

You are subscribed to updates from All3DP

You can’t subscribe to updates from All3DP. Learn more… Subscribe

You can’t subscribe to updates from All3DP. Learn more…

Advertisement

Recommended for you

Topics

Follow us


Advertisement