CNC Programming: Beginners Guide | 2023

    Last 20 years CNC technologies moved to a new era, Computers are much more powerful than before, and computational graphics had revolutionary changes. This led to new improvements in CNC motion technology and enabled new methods to program them. In this article, we will have a detailed exploration of CNC programming, its methods, how you can be a programmer, and some variables that affect the programming method selection process.

How to become a CNC programmer?

The CNC programming profession does not require any degree or diploma but having one can give you advantages in the industry while searching for higher position jobs. Basically, anyone with enough experience and skill demonstration can become a CNC programmer.

There is 3 main way to become a CNC programmer;

  1. Becoming apprentice
  2. Getting a degree, certificate, or diploma in Computerised machining and manufacturing.
  3. Self Learning

In this article, I explained very detail the ways to become a CNC programmer.

What is the difference between a CNC programmer, CNC Machinist, and CNC Operator?

To produce parts with computerized manufacturing (CNC) there are some stages we must achieve. For example;

  • Quoting jobs, parts to be machined
  • Deciding machining strategy
  • Cutting part blanks (workpieces)
  • Setting CNC machines and tools
  • Programming
  • Operating and monitoring

A CNC programmer generally works with a CAD/CAM system and uses a computer to make CNC programs, and a CNC Operator is the person who operates, sets tools, places parts on the machine, and carries out the machining operation until the end.

Here CNC machinists come into play, In the industry, CNC machinists generally know CNC Programming and Operating CNC machines very well. So they are kind of a combination of every stage. They can work on every stage very well so they are generally getting paid very well compared to those just working as CNC programmers or CNC operators.

Is CNC programming hard to learn?

 With a foundation in technical drawing, basic math, and manual machining, beginners can swiftly learn G-code and 2D-CAM programming in a week. However, mastering advanced 3 & 5-axis CAD-CAM programming demands a dedicated 1 to 3 years.

I wrote a detailed article that explains the challenges and solutions to learning CNC programming.

The Ways Of Creating CNC Programs

Programs for CNC machines can be generated in a couple of different ways, such as ;

All those methods can be used in CNC programming, every method has different usage scenarios. Before deciding on the most suitable programming method you need to check the part`s shape and machinability properties.

For harder and more complex shapes, you need to use CAM software, and easier and simpler shapes can be programmed in the controller or with G-Codes and Canned Cycles.

Before selecting a method you need to think about some important variables that lead you to the best programming option. Let us check those variables and things below.

  • The number of features on the part.
  • The complexity of the part`s features. Are they Complex or basic geometrical shapes?
  • The number of machining operations.
  • Completion time of job advised by quotation system.
  • CAM proficiency.

Those will help you to understand the nature of the programming method selection process. As you can imagine, the method of programming has a very important impact on completing the machining mission successfully. Let`s look at those variables so you can see how the CNC Programming method selection process works.

A control panel while using in built programming software.
A control panel

CNC Programming Method Selection Process

  1. The number of features on the part: The number of features determines the completion time of the job, more features mean more time and more cost, and it affects proportionally the programming time and method. Let’s think like this, the feature can be easy to program by handwritten G codes however if there are 10 of those features it can be hard to manage the program, so the best way to program this part can be using CAD/CAM software or using the machine`s inbuilt controller.
  2. Part complexity. How difficult is the part’s shape?: The shape of the part and its features can be complex or just simple planar surfaces and coordinates. For example; a square pocket can be easy to program by handwritten G-Code, however a profile with splines and circles will make it harder to program, Also those kinds of situations will consume a lot of time and money.
  3. The number of machining operations: As you may guess, in machinery there is a huge range of machines, All those machines have a special ability to machine metal parts, but traditional manual machining abilities are limited by the movement capabilities. For example; for circular parts CNC Lathe machines and planar parts Milling machines can be a solution for machining needs. However, with computerized machining so many different machining processes can be done in one machining center. In other words, circular parts and planar parts can be machined in the same CNC machine. Thanks to the CAD/CAM systems and high-precision CNC controllers a milling machine can use X and Y axes to machine a circle or hole. Incredible right? So we call a VMC( Vertical Machining Center ) a machining center, where you can do so many different operations in one center. Traditionally, you need to have a combined programming strategy which will make it very hard to use a CNC machine`s controller to program it. Also, handwritten G-Codes will make it harder, as you can see using software to program can be the best solution.
  4. Job completion time as recommended by the quotation system: Time is the most important aspect of this profession; CNC programmers may find it easy to sit in front of a computer and make programs, but in a very short time frame, you must choose the most efficient and fast way to finish parts to keep costs low. For example, machining a planar surface with a face mill is a simple task that can take a long time if you sit on a CAD-CAM station to program it, so programming by G-Codes or using canned cycles is the best option in this case.
  5. CAD-CAM proficiency: A lack of programming skills can cause you to spend hours and hours in front of a CNC controller or a computer, regardless of the geometrical complexity of the part. In a situation like this, you basically try to unravel the secrets of the programming method that you use for programming. It will result in frustration and mistakes that will harm you, the part, and the CNC machine.

Check the figures below to understand the effects of complex part geometry in CNC programming.

Understanding Geometrical complexity
Understanding Geometrical complexity
Understanding Geometrical complexity
Understanding Geometrical complexity

  Let’s move further and find out how we can program a CNC machine with those methods.

Writing G-Codes Manually In A G-Code Text Editor

       This is the most ancient CNC programming method. However simple things can be powerful sometimes. With G-codes and M-codes you can dominate the CNC machine`s X, Y, Z, A, and B axes and you can move the cutter where you want in the cartesian coordinate system. Also, you can give feed rates and spindle speeds. Pretty much you can do what can be done in a CNC.

In reality, other programming methods like Canned Cycles, inbuilt conversational programming systems, and CAM software generate G&M codes for us. This method is easy if you are just drilling a hole or just giving a finish pass on a shoulder or facing a planar surface. G-codes and M-codes are standardized for milling and turning. However, always check the machine-specific guide for your machine’s recognized G and M codes.

However, when your program gets messy it is hard to manage and you will be more able to crash your beautiful CNC machine because of basic mistakes. The good thing is you can write this program everywhere, even here. Let us use this opportunity to get an idea of how to write a handwritten G-Code CNC program.

Creating A Basic CNC Program

       Let’s create a VMC-HMC (vertical and horizontal machining center) minimal G-code program for drilling two holes.

   N1 G21 G90 G54 ;

   N2 T1 M6 ;

   N3 S1000 M3 ;

   N4 M08 ;

   N5 G00 ;

   N6 X50. Y0. 

   N7 G43 H1 Z10. ;

   N8 G81 Z-20. F120. ;

   N9 X-50.

   N10 G80

   N11 G00;

   N12 G91 ;

   N13 G28 Z0. ;

   N14 G28 X0. Y0. ;

  N15 M05 ;

   N16 M30;

   A CNC program is a combination of three G & M code snippets. Also, you can see N1 and N3…, they are Block (line) numbers that make it easy to edit and track the program. Later we give the command to the CNC controller to prepare itself for operations. In this section, we command CNC about selecting a metric system, selecting the coordinate system, and managing coolant, tool, and spindle speed.

In the Blue section, we move the CNC machine into the machining process, in the current stage machine moves can be seen by the eye. If we have more holes in different depths, we would have them here because we prepared a machine to move with T1 settings. If we had an operation with another tool ( for example tool 2-T2) We would use orange snippets in the future to prepare for the next operation.

In the purple section, we are preparing the controller to finish the program. In this section, we need to close the coolant, and top spindle and send CNC to the home position for the part loading-unloading process. Check this detailed explanation to understand the program structure and G-Code meanings.; 

   G21 G90 G54; –> Selecting (G21) millimeter in (G90) absolute mode with using first (G54) coordinate system.

   T1 M6 ; –> (M6) Mount (T1) Tool-1

   S1000 M3 ; –> (M3) Turn tool on CW direction in (S1000) 1000 Rpm  

   M08 ; –> Open coolant

   G00; –> Get ready for rapid (fast) positioning

   X50. Y0. –> Move to X50. Y0. coordinates

   G43 H1 Z10. ; –> (G43) Take (H1) Tool 1 height offset and move to Z10.

   G81 Z-20. F120. ; –> In direct drilling mode(drilling cycle), drill a hole in 20mm depth by moving 120mm per/minute (in X50. Y0.)

   X-45; –> Drill a hole in X-45. Y0. 

   G80; –> Close the drilling cycle so positions will not be repeated for the direct drilling cycle

   G00; –> Get ready for rapid (fast) positioning

   G91; –> Change mode to the incremental system, so it will move from the last point

   G28 Z0. ; –> Go to the upper limit of the Z-axis ( Z home position )

   G28 X0. Y0. ; –> Go to the X and Y axis limits ( X and Y home position )

   M05 –> Stop the spindle ( the tool spins at 1000 RPM)

   M30; –> End of the program ( give signal with buzzer and light to confirm program finished).

Using a CAD/CAM Software To Generate ISO G-Codes and ISO M-Codes 

Cam software
Cam software in action.

     Using software to generate a CNC program has been the most preferred method in the last 20 years. Improved computer graphics and computing power enabled CAD/CAM systems to produce more complex solutions for our modern world. Cars, bottles, and every complex shape product have a touch of CAD/CAM systems. CAD stands for Computer-Aided Design, and CAM stands for Computer-Aided Manufacturing.

CAD systems and CAD files aid us in designing 3D/2D shapes and surfaces and also allow us to interchange solid models between CAD and CAM. Those models and 2D drawings can be used in CAM systems to generate toolpaths, CAM toolpaths are the pre-calculation of the CNC program in the CAM system. In the end, you will be able to get the G and M codes (CNC Program) of these toolpaths.

Some of the famous CAD/CAM systems are; Mastercam, Solidworks, Solidcam, Cimatron, Top Solid, etc. With these systems, CNC programmers can produce highly precise, complex, and fast programs.

Complex 3D tool-paths
Complex 3D tool-paths

Using Standard Canned Cycles To Make CNC Programs

As you can guess from the word “canned”, it means something ready to use (like canned kidney beans). Canned cycles are standardized ready-to-use G&M code snippets, you can think of them as an accent in G codes. With this different accent, we can mean a lot to the CNC controller.

The CNC controller is the computer that dominates the CNC machine movements. With a couple of magic words, we can command a controller to drill a deep hole with thousands of pecking(drill cleaning processes while drilling deep holes). If we try to write a program with G code it would be frustrating and non-continuous. 

For example; 

   G83 X10.0 Y0. Z-10 R3 Q10  

   X-10.

   G80 

This code basically tells the controller we want 2 holes 10mm deep at X10. Y0. , X-10 Y0. Also, we command the controller to use the G83 pecking drilling cycle, with Q10, we are telling the controller to clean drill in every 10mm drilling. As you can see you can do a lot with less G code.

However improved controllers have newer cycles and all brands have different cycle syntax these days, so finding the correct syntax of the cycle may be challenging. Standard cycles give you a lot of power and you can easily program holes, rectangular pockets without any CAD/CAM, and handwritten hard-coded CNC programs.

Summary

    CNC programming is a complex and wide area to learn and deserves it. You can see that you have a lot of options for creating CNC programs. Handwritten G-Codes and Canned Cycles are good for basic fast response jobs; however, CAD/CAM systems can be difficult due to their sophistication level; However, those CAD/CAM systems open the door to complex surface machining and efficiency.

Today’s fast-phasing workshops use an increasing number of CAD-CAM systems to gain a competitive advantage. I recommend that you concentrate more on CAD-CAM systems. It will improve your skills and qualifications for job applications.

Also, you can watch our video about this topic;

What two types of programming are used on CNC machines?

  Writing G-Codes (ISO Codes) manually in a text editor and using CAM (Computer Aided Manufacturing) software to generate NC programs are two types of programming used on CNC machines.

What type of programming is used in CNC machine?

  CNC machines use several types of programming including writing G-Codes manually, using CAM software, programming with the CNC machine’s inbuilt conversational programming software, and using standard or special canned cycles.

What are the three types of software programs used in CNC systems?

  The three types of software programs used in CNC systems are CAM (Computer Aided Manufacturing) software, CNC machine’s inbuilt conversational programming software, and software for standard or special canned cycles.

What is the most widely used CNC programming language?

  G-Codes (ISO Codes) are the most widely used CNC programming language.

What is basic CNC programming?

  Basic CNC programming involves writing G-Codes manually in a text editor. G-Codes and M-codes are used to control the CNC machine’s axes (X, Y, Z, A, B) and move the cutter in the Cartesian coordinate system. It also involves setting feed rates and spindle speeds.

Do you need math for CNC?

  A basic understanding of mathematics is essential for CNC programming to calculate coordinates, feed rates, and for understanding geometrical relations.

By Isaac Aloyan

Isaac Aloyan is a talented mechanical engineer with a background in machinery design and manufacturing. He completed his diploma from the Department of Machinery Design and Manufacturing at Kocaeli University and also graduated from Level 7 NZDE Mechanical Engineering at Manukau Institute of Technology (M.I.T). Isaac has developed strong expertise in various areas of mechanical engineering, including CNC programming and machining, vacuum mold design and production, manual machining, CAD and CAM, and thermoforming machine design and production. Also, he has educator experience in the area of CNC machinery and programming and mechanical design. With two decades of experience under his belt, Isaac has established a website called mechutopia.com to share his knowledge and help others who are interested in the field of mechanical engineering. The site is likely to feature a wealth of information, resources, and tips for those looking to learn about CNC machines, machining, mold production, and more. It is a testament to Isaac's dedication to the field and his commitment to helping others excel in sub-domains of mechanical engineering like design and manufacturing.