Skip to content

Additional G and M codes

Terje Io edited this page May 27, 2024 · 4 revisions

New G- and M-codes is generally implemented according to the LinuxCNC specification. Some driver specific M-codes, such as those for CO2-laser or Trinamic support, are either made up by me or follow specifications from other implementations.

Codes available for all drivers and configurations

G5  - cubic spline
G50 - Reset scaling (not LinuxCNC)
G51 - Scale axes (not LinuxCNC)
G73 - Drilling cycle, chip breaking
G81 - Drilling cycle
G82 - Drilling cycle with dwell
G83 - Drilling cycle with peck
G98,G99 - Canned cycle return level

Codes available in Lathe Mode, requires driver and hardware (encoder) support

G7  - Lathe diameter mode
G8  - Lathe radius mode
G33 - Spindle synchronized motion
G76 - Threading cycle
G95 - Feed rate mode, units per revolution
G96 - Constant Surface Speed mode (CSS)
G97 - RPM mode

Codes available if tool table is enabled

G10 L1 - Set tool table
G10 L10 - Set tool table
G10 L11 - Set tool table
G43 - Tool length offset
G43.2 - Apply additional tool length offset
M6 - Tool change
M61 - Set current tool

Codes available if driver supports manual tool change or ATC

M6 - Tool change
M61 - Set current tool

The sender has to support the new tool change protocol if manual tool change is to be used. If not M6 commands should be handled by the sender or stripped out.

Codes available if driver or plugins supports them

G65 - Call macro (not LinuxCNC), available from build 20230507*
M62-M65 - Digital Output Control
M66 - Wait on Input
M67 - Analog Output, Synchronized
M68 - M68 Analog Output, Immediate
M70-M73 - Save and restore modal state
M99 - Return from macro, optional

* Requires macros and/or SD card plugin. Macros stored on SD card (or in littlefs) has to be named P<id>.macro where <id> is the macro identifier - this has to be a integer value >= 100 and <= 65535.
If NGC expression support is enabled word values are passed as variables:

Word Variable Word Variable Word Variable
A #1 I #4 T #20
B #2 J #5 U #21
C #3 K #6 V #22
D #7 M #13 W #23
E #8 Q #17 X #24
F #9 R #18 Y #25
H #11 S #19 Z #26

Syntax: G65 P<id> (A- B- C- ...)

NOTES: Axis words ABC and UVW are only available if the corresponding axes are enabled.


NOTE: use the new codes with caution, they have not undergone extensive testing!

NOTE: the HAL has entry points for driver specific M-codes and setting handling, this makes it fairly easy to extend grblHAL - this without changing the core code.


2024-05-27