This image: G-Code and M-Code - the language of CNC.
This figure illustrates the idea that G-Code and M-Code are the "language" used to communicate with CNC machines, with symbols for G (motion) and M (additional function) likely surrounding the CNC machine.
🎯 Tagline: Open the door to the world of CNC machine programming ! For all CNC technicians, whether beginners or those who need a refresher, understanding the basics of G-Code and M-Code is more important than ever. These codes are the "language" used to command machines to move and work as we want. This article will take you to learn the most popular commands used most often in CNC work, along with basic lessons for beginners, including examples of using the G01, G02/G03, M03, and M08 commands that will help you confidently apply them to real work.
🛠️ What are G-Code and M-Code?
Before we dive into the example commands, let's first understand what role these two types of code play in controlling a CNC machine.
G-Code (Geometric Code):
is the main command that controls the movement of the cutting tool, such as rapid traverse, linear interpolation, or circular interpolation. G-Code tells the machine "where to go" and "how to go".
M-Code (Miscellaneous Code):
is an additional command that controls other functions (Machine Functions) of the machine that are not directly related to movement, such as turning the spindle on/off, turning the coolant on/off, or changing tools (Tool Change). M-Code tells the machine "what to do" in addition to movement.
🚀 Popular G-Code that beginners must know
These G-Code commands are the basics that you will encounter and use all the time when programming CNC machines.
| Command (Code) | meaning | General use |
| G00 | Rapid Traverse | Used to move the cutting head to a new position without cutting the workpiece, saving time. |
| G01 | Linear Interpolation | Used for cutting workpieces in straight lines with a specified feed rate. |
| G02 | Circular CW insertion | Used for cutting workpieces into clockwise arcs . |
| G03 | Circular CCW insertion | Used for cutting workpieces in counter-clockwise arcs. |
| G90 | Absolute positioning | The entered coordinates are always referenced to the workpiece zero point. |
| G91 | Incremental positioning | The entered coordinates refer to the last position of the tool. |
💧 M-Code is important for controlling machines.
These M-Codes help control the additional functions required for the machining process.
| Command (Code) | meaning | General use |
| M03 | Spindle On | Command the spindle to rotate clockwise (with speed S specified) to start cutting. |
| M05 | Spindle Stop | Order the spindle to stop when the cutting is finished or when changing tools. |
| M06 | Tool Change | Order the machine to automatically change the cutting tool at the chuck. |
| M08 | Coolant On | Turn on the water/coolant system during cutting to reduce heat and lubricate. |
| M09 | Coolant Off | Order to shut off the water/coolant system when finishing a cut or before changing tools. |
| M30 | Program End | End all program execution and return to the beginning. |
📝 Example of using commands G01, G02/G03, M03, M08 (Basic Lesson)
Let's look at an example of how to combine these commands to create a basic CNC program.
1. Starting: Turn the spindle and turn on the coolant.
N10 M06 T01 ; เปลี่ยนเป็นเครื่องมือเบอร์ 1
N20 S1500 M03 ; สั่งหมุนสปินเดิลที่ความเร็ว 1500 รอบ/นาที ตามเข็มนาฬิกา (M03)
N30 G00 X10 Y10 Z5 ; เคลื่อนที่อย่างรวดเร็ว (G00) ไปยังจุดเริ่มต้น X=10, Y=10, Z=5
N40 M08 ; เปิดน้ำหล่อเย็น (M08)
2. Cutting movement of the workpiece in a straight line (G01)
Suppose we want to make a cut from the point (10, 10) to (50, 10) at depth Z-1.
N50 G01 Z-1 F100 ; ลงไปที่ความลึก Z-1 ด้วยอัตราป้อน F100 (Feed Rate = 100 mm/min หรือ inch/min)
N60 X50 Y10 F150 ; ตัดเป็นเส้นตรง (G01) ไปยัง X=50, Y=10 ด้วยอัตราป้อน F150
Note:
FThe Feed Rate will affect the G01 and G02/G03 commands to control the cutting speed of the workpiece.
3. Movement of cutting workpiece in curves (G02/G03)
Suppose we want to cut an arc from the point (50, 10) to (50, 50) with its center at (50, 30).
Clockwise Curve (G02):
G-CodeN70 G02 X50 Y50 J20 ; ตัดโค้งตามเข็มนาฬิกา (G02) ไปยัง (X50, Y50) ; โดยมี J20 คือระยะห่างของจุดศูนย์กลางบนแกน Y จากจุดเริ่มต้นCounterclockwise Arc (G03): (Reverse Direction Example) Suppose you want to cut an arc from the point (50, 50) to (10, 50) with the center at (30, 50).
G-CodeN70 G03 X10 Y50 I-20 ; ตัดโค้งทวนเข็มนาฬิกา (G03) ไปยัง (X10, Y50) ; โดยมี I-20 คือระยะห่างของจุดศูนย์กลางบนแกน X จากจุดเริ่มต้นNote:
I,J,Kare used to specify the distance of the center point of the arc from the origin along the X, Y, Z axes, respectively.
💡 Conclusion and tips for CNC technicians
Learning G-Code and M-Code is the heart of CNC operations . Practicing and understanding popular commands like G00, G01, G02/G03, G90/G91, M03, M05, M06, M08, M09, and M30 will enable you to create basic programs and control machines effectively as a CNC operator.
Important tips:
Practice often: Writing and testing code on a simulator will help you become more familiar.
Read the manual: Always be sure to check the manual for the CNC machine you are using, as some codes may have different usage or parameters depending on the manufacturer.
Learn by example: Study practical programs to understand their structure and techniques.
Learning the language of CNC machines will open up a whole new world of precise and efficient manufacturing for you!
| Main code | GCode, MCode, G-Code, M-Code, G01, G02, M03, M08, CircularInterpolation, LinearInterpolation |
| Control | CNC programming, CNC technician, machine commands, motion control, SpindleControl, CoolantControl |
| Basic/Level | GCode Basics, Basic Lessons for Beginners, Popular Commands, CNC Programming |
| process | Machining, ToolChange, FeedRate, RapidTraverse |
| Thai language only | CNC programmer, CNC technician, linear motion, circular motion |
Great! Having illustrations helps greatly in understanding the G-Code and M-Code articles, especially for beginner CNC operators. I will create 4 illustrations with English text as requested.