gcode Command Reference Table

[Motion86]

Description

This page describes the commands supported by the gcode() function, the command format, and how to use it.

The – sign in the command format (e.g., G1 Axes- F-) represents the value input.

For more details about the various motion effects, please refer to the motion method explanation page.

G-Code Reference Sheet

G-CodeDescription
G1Linear motion
G2Clockwise circular motion
G3Counterclockwise circular motion
G4Pause command
G17Select XY plane for circular motion
G18Select XZ plane for circular motion
G19Select YZ plane for circular motion
G90Absolute position mode
G91Relative position mode
G90.1Absolute position mode at the center of the arc
G91.1Arc center relative position mode
G92Coordinate System Offset

G1

G1 Axes- F-

For straight-line movement, G90 and G91 can be used to designate absolute mode or relative mode.

  • Axes: For the endpoint coordinates
  • F: For feeding speed

Usage examples:

1. Move from the current position to the absolute coordinates (10,10,20) in a straight line at a feed rate of 500.

machine.gcode("G90");
machine.gcode("G1 X10 Y10 Z20 F500");     

2. Move the current position as the base, relative to each other (10,-10,20).

machine.gcode("G91");
machine.gcode("G1 X10 Y-10 Z20 F500");  

3. The X and Y-axis positions of the current position remain unchanged, and the Z-axis is moved to the absolute coordinate Z=50.

machine.gcode("G90");
machine.gcode("G1 Z50 F500");   

G2, G3

Circle mode: G2 Axes- Offsets- P- F-

Radius mode: G2 Axes- R- P- F-

G2 is for clockwise circular movement, G3 is for counterclockwise circular movement, and G17, G18, and G19 can be used to specify the axis of the drawn circular plane and helix.

  • Axes: For the endpoint coordinates
  • Offsets: the center of the arc
  • R: the radius of the circle
  • P: the number of circles drawn
  • F: For feeding speed

The value of the arc radius R can be negative, if it is negative then the arc path will be greater than 180∘. According to different combinations of parameters, we can draw arc, circle, spiral, etc. For detailed explanation of the motion method, please refer to the motion method explanation.

Usage examples:

1. Draw a 90∘ arc from (0,0,0) to (50,50,0) on the XY plane with the center (50,0,0).

machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G2 X50 Y50 I50 J0 F500");

2. Draw a 90∘ arc from (0,0,0) to (50,50,0) in the XY plane with the center (50,0,0).

machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G2 X50 Y50 R50 F500");

3. Draw a 270∘ arc from (0,0,0) to (50,50,0) in the XY plane with the center (50,0,0).

machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G3 X50 Y50 R-50 F500");

4. Draw a 90∘ arc from (0,0,0) to (50,50,0) in the XY plane with the center (0,50,0).

machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G3 X50 Y50 R50 F500");

5. Draw a circle clockwise from (0,0,0) in the XZ plane with the center (0,0,50).

machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G18");
machine.gcode("G2 X0 Z0 I0 K50 F500")

6. Draw a helix with XY as the circular plane, origin as the center, Z-axis as the height, and pitch as 10, starting from (50,0,0) and ending at (50,0,100) clockwise.

machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G17");
machine.gcode("G2 X50 Y0 Z100 I-50 J0 P10 F500");

G4

G4 S-

G4 P-

The machine is suspended for a period of time.

  • S: Time in seconds, both inputs are integers
  • P: Time in milliseconds

Usage examples:

1. Wait 2 seconds at the coordinates (50,0,0) and then move to the coordinates (0,50,0) in a straight line.

machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G4 S2");
machine.gcode("G1 X0 Y50 Z0 F500");

2. Wait 0.5 seconds at the coordinates (50,0,0) and then move to the coordinates (0,50,0) in a straight line.

machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G4 P500");
machine.gcode("G1 X0 Y50 Z0 F500");

G17、G18、G19

G17

G18

G19

Specifies the plane for the arc motion. If not specified, the default is G17.

  • G17: Specify the plane as XY plane
  • G18: Specify the plane as XZ plane
  • G19: Specify the plane as YZ plane

Usage examples:

1. Starting from the origin (0,0,0), draw a circle with a radius of 50 in the XY plane clockwise and a circle with a radius of 50 in the YZ plane counterclockwise.

machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G17")
machine.gcode("G2 X0 Y0 I50 J0 F500");
machine.gcode("G19")
machine.gcode("G3 Y0 Z0 J0 K50 F500");

2. Draw a clockwise spiral from (0,0,0) to (0,100,0) with XZ as the circular plane, (0,0,50) as the center, Y-axis as the height, and the pitch as 10.

machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G18");
machine.gcode("G2 X0 Y100 Z0 I0 K50 P10 F500");

G90、G91

G90

G91

Set the mode of the position coordinates. If not specified, G90 is preset.

  • G90: If absolute mode is used, the parameter Axes in the G1, G2, and G3 commands is the absolute position.
  • G91: If the relative mode is used, the parameter Axes in the G1, G2, and G3 commands is the relative position.

Usage examples:

1. Move from the current position to the absolute coordinates (10,10,20).

machine.gcode("G90");
machine.gcode("G1 X10 Y10 Z20 F500");

2. Move the current position as the base, relative to each other (10,-10,20).

machine.gcode("G91");
machine.gcode("G1 X10 Y-10 Z20 F500");

3. From the coordinates (50,0,0), draw a clockwise arc with a radius of (100,0,0) and move it to (150,0,0).

machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G2 X150 Y0 I50 J0 F500");

4. From the coordinates (50,0,0), draw a clockwise arc with a radius of (100,0,0) and move it to (150,0,0).

machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G91");
machine.gcode("G2 X100 Y0 I50 J0 F500");

G90.1、G91.1

G90.1

G91.1

Set the mode of the center coordinates. If not specified, it is preset to G91.1.

  • G90.1: If absolute mode is used, the parameter Offsets in the G2 and G3 commands are absolute positions.
  • G91.1: If relative mode is used, the parameter Offsets in the G2 and G3 commands are relative positions.

Usage examples:

1. From the coordinates (50,0,0), draw a clockwise arc with a radius of (100,0,0) and move it to (150,0,0).

machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G90.1");
machine.gcode("G2 X150 Y0 I100 J0 F500");

2. From the coordinates (50,0,0), draw a clockwise arc with a radius of (100,0,0) and move it to (150,0,0).

machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G91.1");
machine.gcode("G2 X150 Y0 I50 J0 F500");

G92

G92 Axes-

Coordinate system offset, specifying Axes as the coordinates of the current position.

  • Axes: Current position of the coordinates

Usage examples:

1. Offset the coordinate system to assign the current position to the absolute coordinates (50,50,50).

machine.gcode("G92 X50 Y50 Z50");

See also

  • Explanation of exercise method()
  • gcode()

Libraries Reference Home

The text of the 86Duino reference is a modification of the Arduino reference and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Leave a Comment

Scroll to Top