Mach 4 G Code is a set of standardized commands used to control CNC machines running the Mach 4 CNC controller software. This list enables precise movement, spindle control, tool changes, and feed rate adjustments without manual intervention. To use these commands, you must have Mach 4 installed on a compatible PC connected to your CNC machine via a motion controller, with correct motor tuning and limit switch wiring already configured. No additional hardware is required beyond what is needed to run Mach 4 itself.
What You'll Need
- A computer running Windows 7 or later (64-bit recommended)
- Mach 4 CNC Controller software (licensed version)
- A compatible motion controller (e.g., PoKeys, PMDX, or Ethernet-based board)
- Properly wired CNC machine with steppers or servos, limit switches, and spindle control
- A G-code file or text editor to write and save your program (.nc or .gcode extension)
Step-by-Step
- Power on your CNC machine and ensure all limit switches are properly engaged — if any are tripped, the machine will not home or move.
- Launch Mach 4 on your control computer and load your machine configuration file (.xml) that matches your machine’s axis layout, steps per unit, and motor tuning.
- Click the Home All button in the Mach 4 interface to move all axes to their reference positions. Wait for the green Home indicator lights to turn on for each axis.
- Open your G-code file in a text editor like Notepad++ or within Mach 4 using File > Open Program. Verify the file starts with % and ends with M30 or M02 to indicate proper program termination.
- Load the program into Mach 4 by clicking Load Program or pressing Ctrl+L. The program lines will appear in the program window.
- Set the work coordinate system (G54–G59) by jogging the tool to your material’s origin point, then click Set Work Zero on the appropriate axis panel.
- Ensure the spindle is off and the tool is clear of the material. Select the correct tool number if using an automatic tool changer (ATC), or manually install the tool if not.
- Enable the spindle using M3 (clockwise) or M4 (counterclockwise) followed by S### to set RPM (e.g., M3 S8000). Confirm spindle rotation with the spindle speed indicator in Mach 4.
- Click Start or press F5 to begin execution. Observe the first few lines of motion for accuracy — if the tool moves incorrectly, stop immediately using the red Feed Hold button.
- Monitor the machine during operation. Use the Pause button to interrupt, Reset to cancel the program, or Step to execute one line at a time for debugging.
- After completion, verify the part matches dimensions. Use a caliper to check critical features against the G-code’s programmed values.
Common Mistakes
- Forgetting to set work zero before starting — this causes all cuts to be offset by inches or millimeters.
- Using G20 (inches) with a machine calibrated in G21 (millimeters), resulting in 25x overtravel and potential collision.
- Missing or misordered G-code blocks — for example, using G01 without a preceding F (feed rate) command, which may cause erratic movement.
- Running a program with M06 (tool change) but no tool number specified, like M06 T1 — this halts the machine indefinitely.
- Not verifying motor tuning values (steps per unit) before running, leading to inaccurate positioning even if the G-code is correct.
Tips
- Always simulate your G-code in Mach 4’s Verify mode before running on the machine — it shows path preview without motion.
- Use comments in your G-code (surrounded by parentheses) to document tool changes, coolant states, or material settings — e.g., (TOOL: 1/4" end mill, ALUMINUM).
- Keep your G-code files organized by material and tool type, using clear filenames like Aluminum_Slot_1.nc.
- Use G91 (incremental) sparingly; G90 (absolute) is safer for most machining operations.
- Always include G4 P1 (dwell 1 second) after spindle start to allow full RPM before cutting begins.
- Save your machine configuration file (.xml) after any change — losing it means retuning all axes from scratch.
Troubleshooting
- Machine doesn’t move after pressing Start — Check if the E-stop is engaged, verify all limit switches are not stuck, and confirm the motor drivers are powered and not overheating.
- Position drift during long runs — This usually means motor current is too low or belts are slipping. Increase motor current in the motion controller settings and inspect belt tension.
- Spindle won’t turn on — Confirm the spindle control output is assigned correctly in Mach 4’s Config > Ports & Pins > Spindle section. Test with the manual spindle on/off buttons.
- Program stops at line 10 with "Unknown Code" error — Check for typos: G001 should be G00, M001 should be M00. Remove any extra spaces or special characters.
- Tool path is mirrored or inverted — Reverse the direction of the affected axis in Config > Ports & Pins > Motor Tuning by checking the "Invert" box for that axis.