How to Send G-Code to a 3D Printer

By
Marilyn Grant
Marilyn Grant
Writer
Marilyn knows how to present the dullest topic in an interesting and easy-to-read way. When she’s not teaching English Literature at a local school or writing for our site read more
reviewed
Reviewed By
Julie Flores
Julie Flores
Expert Consultant
Julie owns a shop specializing in sewing equipment and accessories. No wonder she knows everything when it comes to technical specifications of practically anything we revie read more
Last updated: August 08, 2023
CraftyHangouts is reader-supported. We may earn a commission through products purchased using links on this page. Learn more about our process here

Anyone can use a 3D printer, thanks to how easy it is to download free object models online. So long as you have a basic knowledge of how to send G-Code to a 3D printer, you can get the physical created magically from a digital file.

As it turns out, there’s more to 3D printing than that. If you are still only thinking about this lesson, then we recommend that you familiarize yourself with these best 3D printers for beginners. Once you understand a bit more about g-code and what makes 3D printers tick, you will have the power to customize g-code Trusted Source Customizing G-code - Harvard Wiki Most machines speak variations of the g-code, making the code vary depending on type, make, and model of the printer.  Machine specific commands are those that start with an M. M-codes tell the printer how to perform an action, such as the start/end of the program and what temperature to heat the extruder to. wiki.harvard.edu and create even more awesome projects and have the skills to troubleshoot problems easily.

After creating or downloading your project as an STL file, you will then proceed to feed it into a slicer software which will then generate the g-code file. Sending this file to the 3D printer is the last step of the process before you begin printing, which you can do by:

  • Using an SD card to carry over the file to the 3D printer.
  • For WIFI-enabled 3D printers, you can simply send the file over wirelessly
  • Use a USB cable to send the file directly from your computer

One of the best free software to help do all this is Repetier Host, but we will cover that later. For now, let’s start with g-code.

What is G-Code?

G-code is short for geometric code, a type of low-level programming language used by machines such as CNC (Computer Numerical Control) and 3D printers. The language is used to provide commands to control the movement of the machine head, provide initialization protocols, and other essential instructions.

G-code language is presented in cleartext format, which means that humans can understand it as easily as the printer does.

A g-code file is simply a sequential set of commands that guides the 3D printer on a step-by-step process of how to create the project. It controls the movement of the printer head using Cartesian coordinates, sets the amount of extrusion, extrusion speed, temperature, and all other important details.

There are specific commands used in g-code to pass these instructions along. They are easy to understand once you have spent some time exploring the language.

Common G-Code Commands

G-code lacks sophisticated constructions such as variables and loops. Instead, it uses standard commands which serve as functions with arguments. An example of a line of code would look something like this:

G1 X-5.3 Y-5.5 Z2.0 F2000.0 E0.0250

The first command, G1, tells the printer to move in a straight line towards the coordinates (X-5.3 Y-5.5 Z2.0) at a feed rate of 2000 while extruding 0.0250 of material. Thus, the command comes with its own arguments, which makes the code very easy to read.

Here are 10 common g-code commands to help you understand and read it better.

1.   G0 – Rapid Motion

How to Send G-Code to a 3D Printer

This command tells the print head to travel at maximum speed to the coordinates specified. It will typically do so without extrusion, traveling through the three axes simultaneously. Another example of a rapid motion command could be G0 X8 Y15.

2.   G1 – Controlled Motion

Unlike the command for rapid motion, this one provides arguments as parameters to control the coordinates for movement as well as the feed rate and volume of extrusion. The main example above,  G1 X-5.3 Y-5.5 Z2.0 F2000.0 E0.0250, is one example of a G1 command.

3.   G-28 – Homing Routine

This command instructs the printer head to return to the farthest edges of its travel until it contacts the end-stops. This “home” position gets the head out of the way when you’re ready to remove your finished product. You can also specify which axis you want the homing command to get out of the way.

  • G28 gets to the home position on all axes
  • G28 X Y gets to the home position on the X and Y axes
  • G28 X gets to the home position on the X-axis

4.   G20 and G21 – Set Units

These two commands instruct the 3D printer on which units to use. G20 tells it to use inches (imperial system), while G21 is for millimeters (metric system). As you can imagine, it is very important to be sure of which units you are referring to when you send direct commands to your 3D printer. For example,

G20

G1 X-5.3 Y-5.5 Z2.0

Tells the printer to move 5.3 inches along the X-axis, 5.5 inches along the Y-axis, and 2 inches up.

5.   G17/G18/G19 – Set Planes

These three commands are used to set the plane in which the printer head should move. T

G17 – this is a default for the X/Y plane

G18 – represents the Z/X plane

G19 – it represents the Y/Z plane

6.   G90 and G91 – Positioning Mode

The printer head can use both absolute and relative positioning to move. Absolute positioning references the neutral point (X=0, Y=0, Z=0) to move to the exact Cartesian coordinates indicated, while relative positioning tells it to move in reference to its current position. Here are examples.

Absolute Positioning:

G90

G1 X-5.3 Y-5.5 Z2.0 F2000.0 E0.0250

Relative Positioning:

G91

G1 X-5.3 Y-5.5 Z2.0 F2000.0 E0.0250

In both cases, you can instruct the printer to use either system of units.

7.   G2 – Clockwise Motion and G3 – Counterclockwise Motion

How to Send G-Code to a 3D Printer

This command tells the printer head to move clockwise starting from its current position. X/Y parameters specify the endpoint of the resultant arc, while the center of rotation is specified by the parameter I – this is the X offset of the head’s current position from the center of rotation. You can also set the Y offset of the center of rotation using the parameter J.

G20 G90 G17

G1 X5 Y15

G2 X150 Y50 I0 J-200

G3 commands follow the same format, only that the printer head moves anticlockwise.

G20 G90 G17

G1 X5 Y15

G2 X-150 Y50 I0 J-200

In either command, the second line of code gets the printer head to the starting point, while the third line defines the kind of motion, the endpoint, and center points respectively.

8.   Code Comments

In reality, any g-code file will contain a lot of plaintext English comments to help ease understanding. This code also provides information such as the software version, printer type, filament characteristics, and more.

Code comments in g-code always start with a semicolon, which tells the printer not to execute them. For example:

G1 X5 Y15 ; Linear movement in a straight line to the coordinates X5 and Y15

9.   M Commands

M or “miscellaneous” commands are used to control printer settings. These can be anything from setting the temperature of the bed to putting the printer ON or OFF. For example:

M104 ; starts heating the extruder, but you can carry out more commands in the meantime

M109 ; instructs the printer to wait until the set temperature is attained

The arguments for this command are used to tell the machine what units are to be used. S is for degrees Celsius, T value is used when you have more than one extruder to specify which one you are referring to. For example:

M104 S230 T0 ; start heating the extruder T0 to 230 degrees Celsius

G28 X0 ; home the extruder on the X-axis while it continues heating

M109 S230 T0; wait for T0 to reach 230 degrees before executing the next command

For printers with only one printer head, you can eliminate the T arguments. M140 and M190 are used in the same way to heat the printer bed, but only the S argument is needed.

10.  F and E Values

F-values specify the feed rate – that’s the rate at which the extruder traveling. These values are usually set in mm/min, so a value of F300 means a rate of 5mm/s. E values are used to signify the amount of material extruded so far on filament 3D printers. It’s much easier to just let the slicer program handle this automatically.

Sending G-Code Files to Your 3D Printer

Now that you understand the technical part of g-code, actually sending the completed .gcode file to the printer should be easy. There are three ways to do it:

Using an SD Card

How to Send G-Code to a 3D Printer

This is the easiest and most common way to send the .gcode file to your 3D printer. Every printer has an SD card slot and comes with an adapter, and you can use almost any decent size SD card for the job.

Once you have the file loaded on the card, simply insert it into your printer, initialize it, and select the file name under which you saved the .gcode file for the particular project. Your printer’s manual should have information on how to do this.

Via USB Cable

A direct cable connection is one way to send g-code from a computer to a 3D printer. You will need a software terminal that can use the PC’s COM port to make this possible, one of which is Repetier Host. More about Repetier in a bit.

Most people don’t favor this method because the PC will need to stay connected to the printer for the entire time the print is in progress, which could be hours or days. If on a laptop, even going into sleep mode can interrupt or ruin the printing process.

Via Wi-Fi

Some of the best 3D printers out there actually come with inbuilt wireless connectivity using WIFI. It is an easy way to send raw g-code to a 3D printer and even edit it manually in the process.

If you have one of those budget 3D printers, you can even upgrade the controller or use a Raspberry Pi or Arduino module to give it wireless connectivity.

In this case, you will also need a software host such as Repetier to create a send path for the file to the printer. As with the direct connect method, any interruption in your WLAN connectivity can ruin the printing process. Repetier uses a more reliable method of caching the model onto its servers.

How to Send G-Code to a 3D Printer Using Repetier-Host

Repetier Host is a free program combining a slicer and g-code editor as well as object placement, basic design, and communication functionalities into one convenient program.

Using Repetier Host is easy enough. You simply load your STL file by selecting “Object Placement.” After this, select “Slice with Slic3r” or “curaEngine”, which will generate the g-code file. You can then save this file to your computer and copy it to an SD card.

Connecting over WIFI or cabled connection is a bit more technical, but Repetier as a full how-to guide on the process here Trusted Source Connection Problems - Repetier There are several ways to connect Repetier-Host with your printer:
Repetier-Server
Serial Connection
TCP/IP Connection
www.repetier.com
.

Final Thoughts

3D printing has now become simple and easy, but it is still a pretty technical process. If you’re just getting started, you should read through the book 3D Printing for Dummies to get acquainted with the fundamentals. The book covers things like types of 3D printers, materials, assembly, calibration, web-based printing, and more.

In reality, learning how to send g-code to a 3D printer is only the first step of the process. If you want to get better and gain more control, contrive to understand how g-code works and what the g-code file actually looks like. After all, 3D printing isn’t really for dummies.

References

1.
Customizing G-code - Harvard Wiki
Most machines speak variations of the g-code, making the code vary depending on type, make, and model of the printer.  Machine specific commands are those that start with an M. M-codes tell the printer how to perform an action, such as the start/end of the program and what temperature to heat the extruder to.
2.
Connection Problems - Repetier
There are several ways to connect Repetier-Host with your printer:
Repetier-Server
Serial Connection
TCP/IP Connection
Leave a comment

Your email address will not be published. Required fields are marked *