CNC router bits and carbide cutting tools with tutorials and technical guides

Sweetspot G-code: Zig-Zag Pattern


G-code is remarkably easy to understand, once you master a few commands and become familiar with the required syntax. Every line is in clear text (like HTML) and the commands logically positioned with the arguments that they operate on. The full scope of the allowable syntax is beyond the purpose of this short tutorial. For a complete description, look at the G-code Primer (The NIST RS274/NGC Interpreter).

At Think & Tinker, we have the system origin (X0, Y0, Z0) defined in the lower left corner of the cutting table, near the corner of the FRONT and LEFT edges. The positive (+) X direction is to the right. The positive (+) Y direction is towards the BACK of the table. As you might expect, the positive (+) Z direction is vertically up from the surface.

Line numbers (Command starts with a N) are totally optional, but VERY handy for editing long programs. Controller software, like Mach3, often show line numbers by default.

Leading and trailing ZEROS are ignored by the G-code interpreter. They are shown in the code for clarity and can make troubleshooting much easier later on.

The code shown in the table below is what we use for ANY of our tools with cutting diameters 1/8 in. and smaller. The only things that change are the feedrates (F commands).

One of the things that you will notice about the following code is that the main section is very repitive. That makes it easy to modify by cutting and pasting blocks of text, as long as you remember set the feedrate (FXX) for each step. The code areas marked in green are essentially a header and footer that might be slightly different depending on your controller software and the way you define you local origin. The codes used in this tutorial are so generic that they should work with virtually any controller that supports NIST RS274 (V3).

Line
No.
Command Description Schematic
N000 G90 Set ABSOLUTE mode (all moves will be made relative to the defined origin (X0, Y0, Z0) of the CNC system Header information that configures the controller to use INCHES as the standard unit and INCHES PER MINUTE as the feed unit. This code can be used in a metric environment as long as the arguments for X, Y and Z are converted to the appropriate metric values.
N001 G00 Set RAPID TRAVERSE mode (used for rapid moves when the bit is retracted from the material being cut)
N002 G20 Set system units as INCHES
N003 G94 Set system feedrates as UNITS PER Minute (with the preceding G20 command, the feedrates are set to INCHES PER MINUTE)
N004 Z1.000 Move the spindle to a point 1.000 inches above Z0 (in this case, Z0 is the heigth of the spindle when the tip of the cutter is just barely touching the surface of the material being tested)
N005 X0.000Y0.000 Move the spindle to the defined origin point of the XY axes (X0, Y0)
N006 M3 Turn on spindle rotating clockwise. (If your system has program control of the spindle speed, you would use M5 SXXXXX, where XXXXX is the spindle RPM that will be used in this test)
N007 ( START ZIG-ZAG ) Comment line. Any text that is between parentheses is ignored, even if it is in the same line as a command. ZigZag
N008 G01 Set MACHINING mode (all of the following move commands will be executed at the defined feedrate while plunged into the material. This mode will stay in effect until cancelled by G00)
N009 F5 Set feedrate to 5 (with G20 G94 this becomes 5 inches / min.)
N010 Z-0.003 Plunge spindle to a point 0.003 in. below the surface of the material (referred to as the "plunge depth" for the next command)
N011 G91 Set INCREMENTAL mode (all moves will be made relative to the current position of the spindle. Like the clues in a treasure map. Take 2 steps straight head, turn 90° to your left, take 10 more steps....)
N012 F10 Set the FEEDRATE to 10 (10 inches/min.)
N013 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N014 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N015 F15 Set the FEEDRATE to 15 (15 inches/min.)
N016 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N017 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N018 F20 Set the FEEDRATE to 20 (20 inches/min.)
N019 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N020 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N021 F25 Set the FEEDRATE to 25 (25 inches/min.)
N022 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N023 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N024 F30 Set the FEEDRATE to 30 (30 inches/min.)
N025 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N026 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N027 F35 Set the FEEDRATE to 35 (35 inches/min.)
N028 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N029 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N030 F40 Set the FEEDRATE to 40 (40 inches/min.)
N031 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N032 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N033 F45 Set the FEEDRATE to 45 (45 inches/min.)
N034 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N035 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N036 F50 Set the FEEDRATE to 50 (50 inches/min.)
N037 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N038 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N039 F55 Set the FEEDRATE to 55 (55 inches/min.)
N040 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N041 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N042 F60 Set the FEEDRATE to 60 (60 inches/min.)
N043 X1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the right and 0.125 in.up the Y axis
N044 X-1.000Y0.125 Cut from the current spindle location to a point that is 1.000 in. to the left and 0.125 in.up the Y axis (the spindle is now back on the left side of the pattern but 0.250 in. up the Y axis from where the cut started)
N045 G90 Set ABSOLUTE mode Footer information that tidies up the system, returning the spindle to the home position (local origin), turns off the spindle, and tells the controller that the end of the program file hase been reached. As with the header, this part of the code might need to be modified slightly if the controller software requires a different shut down procedure.
N046 G00 Set RAPID TRAVERSE mode
N047 Z1.000 Lift spindle to point 1.000 in. above the surface of the material
N048 X0.000Y0.000 Return to the defined system origin (X0, Y0, Z0)
N049 M05 Turn off the spindle
N050 M02 End of Program