Skip to content
markmaker edited this page Apr 1, 2021 · 14 revisions

NOTE: This page describes Gcode supported by TinyG in firmware versions 0.95 and later

See also:

TinyG implements the NIST RS274v3/ngc dialect of Gcode. We try to adhere as closely as possible to the NIST Gcode and LinuxCNC Gcode specifications:

Cheat Sheet

This table summarizes Gcode supported. axes means one or more of X,Y,Z,A,B,C.

Gcode Parameters Command Description
G0 axes Straight traverse Traverse at maximum velocity. At least one axis must be present
G1 axes, F Straight feed Feed at feed rate F. At least one axis must be present
G2 axes, F, I,J,K or R Clockwise arc feed Arc at feed rate F. Offset mode IJK or radius mode R
G3 axes, F, I,J,K or R Counter clockwise arc feed Arc at feed rate F. Offset mode IJK or radius mode R
G4 P Dwell Pause for P seconds
G10 L2 axes, P Set offset parameters P selects coordinate system 1-6
G17 Select XY plane G17, G18 and G19 set the plan in which the G2/G3 arcs are drawn
G18 Select XZ plane
G19 Select YZ plane
G20 Select inches units mode All Gcode from this point on will be interpreted in inches
G21 Select mm units mode All Gcode from this point on will be interpreted in millimeters
G28 axes Go to G28.1 position Optional axes specify an intermediate point
G28.1 Set position for G28 The current machine position is recorded (No parameters are provided)
G28.2 axes Homing Sequence Homes all axes present in command. At least one axis must be specified
G28.3 axes Set Absolute Position Set axis to zero or other value. Use to zero axes that cannot otherwise be homed
G30 axes Go to G30.1 position Optional axes specify an intermediate point
G30.1 Set position for G30 The current machine position is recorded (No parameters are provided)
G53 Select absolute coordinates Non-Modal: Applies only to current block
G54 Select coord system 1 G54 is typically used as the "normal" coordinate system and reflects the machine position
G55 Select coord system 2
G56 Select coord system 3
G57 Select coord system 4
G58 Select coord system 5
G59 Select coord system 6
G61 Exact path mode Continuous motion between Gcode blocks - exact path will be traced - stops only if it must
G61.1 Exact stop mode Motion will stop between each Gcode block
G64 Continuous path mode Sacrifice path following accuracy in order to keep the feed rate up
G80 Cancel motion mode
G90 Set absolute mode
G91 Set incremental mode
G92 axes Set origin offsets
G92.1 Reset origin offsets
G92.2 Suspend origin offsets
G92.3 Resume origin offsets
G93 Set inverse feedrate mode
G94 Cancel inverse feedrate mode
Mcode Parameter Command Description
M0 Program stop
M1 Program stop Optional program stop switch is not implemented so M1 is equivalent to M0
M2 Program end
M30 Program end
M60 Program stop
M3 S Spindle on - CW S is speed in RPM
M4 S Spindle on - CCW S is speed in RPM
M5 Spindle off
M6 Change tool No operation at this time
M7 Mist coolant on Note that mist and flood share the same Coolant ON/OFF pin
M8 Flood coolant on Note that mist and flood share the same Coolant ON/OFF pin
M9 All coolant off Note that mist and flood share the same Coolant ON/OFF pin
M114 Get current position Report the current coordinates
M115 Get Firmware Report the current firmware, version and capabilities
M201.3 axes Set axes jerk Set transient axis jerk rate
M400 Finish moves Wait for current moves to finish
Other Parameter Command Description
N line number label gcode block Line numbers are allowed, handled, and may be reported back in status reports. Don't underestimate how useful this is for debugging Gcode files.
() comment gcode comment Gcode comments are supported. They are stripped and ignored, except for messages (below)
; comment alternate comment A semicolon is an alternate way to delimit a comment. This is not Gcode "standard", but is used by Mach and some Reprap codes. (available as of build 378.05)
(msg....) message gcode message Gcode messages are comments that begin with the characters msg (case insensitive). These will be echoed to the operator

Gcode Reference

Some of the more complicated commands are described here. Much of this is shamelessly cribbed from the LinuxCNC Gcode pages

G10 Set Parameters (Offsets)

Currently the only G10 command supported is G10 L2, which is used to set coordinate offsets. Use Pn to select coordinate system 1-6 (G54 - G59, respectively), and one or more axis value to set the offset for that axis. The format is:

G10 L2 P1 X0 Y0 Z0 A0 B0 C0  - set G54 offsets to zero, making G54 act as persistent absolute coordinates

G28, G28.1, G30, G30.1 Go To Predefined Position

G28 (and G30) will move the machine to the absolute coordinates set in G28.1 (G30.1), optionally through an intermediate point. Movement will occur at the traverse rate (G0 rate). Axes that are not specified are ignored (not moved). The axis value is the intermediate point for that axis.

Format is:

G28 X0 Y0 Z0 A0 B0 C0
Gcode Parameters Command Description
G28 axes Go to G28.1 position Goes through intermediate point if axes are present
G28.1 Set position for G28 Axes are not used and are ignored if present
G30 axes Go to G30.1 position Goes through intermediate point if axes are present
G30.1 Set position for G30 Axes are not used and are ignored if present

Example of use:

  • Go to an arbitrary position, e.g. G0 x100 y100
  • Send G28.1 - This will "remember" the absolute position. This position remains constant regardless of what coordinate system is in effect.
  • Then go to a different place, e.g. G0 x50 y50
  • Send G28 - The machine will return to x100 y100

Example:

  • Go back to X0Y0
  • Send G91 G28 Z10 - this will move to x100 y100. The tool will initially lift z by 10 mm (or inches); G91 is used to set relative mode for this command.

G61, G61.1, G64 Path Control Modes

TinyG supports exact path mode (G61) and exact stop mode (G61.1). G64 is recognized, but is treated as exact path mode. In exact stop mode motion will stop between each Gcode block. In exact path mode the exact path is followed (i.e. corners are not rounded). The velocity at the points joining 2 blocks is controlled to keep the change in direction between the blocks within centripetal acceleration limit set by $JA. Please see here for an explanation.

M2, M30 Program End

program END (M2, M30) performs the following actions:

  • Axis offsets are set to G92.1 CANCEL offsets
  • Set default coordinate system (uses $gco)
  • Selected plane is set to default plane ($gpl)
  • Distance mode is set to MODE_ABSOLUTE (like G90)
  • Feed rate mode is set to UNITS_PER_MINUTE (like G94)
  • The spindle is stopped (like M5)
  • Motion mode is canceled like G80 (not set to G1)
  • Coolant is turned off (like M9)
  • Default INCHES or MM units mode is restored ($gun)

M114 Get current Position

Reports the current target position.

Example:

M114

X:100.0000 Y:0.0000 Z:0.0000 A:0.0000 B:0.0000 C:0.0000

M115 Get Firmware, Version and Capabilities

Reports the firmware, version and capabilities as many other controllers do. This allows Gcode generating software connected to an initially unknown controller to automatically detect it and adapt itself accordingly. Gcode generating software can then provide a "Plug-and-Play" experience to the user.

Example:

M115

FIRMWARE_NAME:TinyG, FIRMWARE_URL:https%3A//github.com/synthetos/TinyG, FIRMWARE_VERSION:0.97, FIRMWARE_BUILD:440.21, HARDWARE_PLATFORM:1.00, HARDWARE_VERSION:8.00

M201.3 Set jerk

Sets the jerk of one or more axes transiently. Axis jerk rates are given in units per second³ in order to remain compatible to analogous M201 commands on other controllers. The jerk rates are internally converted to TinyG's km per minute³ rate. Note, $xjm, $yjm etc. remain unaffected by the transient setting.

Example:

M201.3 X90000 Z10000

Watch a video of how this is useful for the OpenPnP software:

https://youtu.be/6SBDApObbz0

M400 Wait for current moves to finish

Some Gcode generating application (e.g. OpenPnP) need to interact in real-time with the machine. One example: A camera is moved to a location, then Computer Vision is used. Obviously, the application needs to know when the camera has arrived, before it can take a picture.

M400 blocks all further command processing, until the move buffers have drained. The acknowledgement "tinyg ok>" is only reported once this has happened. The application can therefore synchronize itself efficiently with TinyG.

Example:

G1 X100
M400   ; wait for the move to complete
M114   ; only now report the position

Gcode Comments

  • Comments start with a '(' char or alternately a semicolon ';'
  • Comments always terminate the block - i.e. leading or embedded comments are not supported
Valid comment cases       Notes:
G0X10                      - command only - no comment
G0X10 (comment text)       - command with comment
G0X10 (comment text        - it's OK to drop the trailing paren
G0X10 ;comment text        - comment delimited by semicolon (firmware build 378.05 and later)
(comment text)             - there is no command on this line
Invalid comment cases     Notes:
G0X10 comment text         - comment with no separator
N10 (comment) G0X10        - embedded comment. G0X10 will be ignored
(comment) G0X10            - leading comment. G0X10 will be ignored
G0X10 #comment             - invalid comment separator
Clone this wiki locally