Unleash your creativity with 3D printing!

3D Printing Spot Logo

How to Edit G-code in Cura: Everything You Need to Know

How to Edit G-code in Cura: Everything You Need to Know | 3D Printing Spot

Updated by

Craig A Fry

/

April 14, 2021

Cura is one of the most commonly used open-source slicing programs for G-code and 3D printers. G-code is the programming language itself that is used to command a machine to perform a certain action.

Cura allows you to begin by choosing the settings with which you will begin your project. Those settings are either “Recommended” or “Custom.” The recommended settings are generally for beginners, and the custom settings allow for a much wider breadth of editing the g-code.

This guide will provide a step-by-step understanding of the tools and processes that are available to you for editing G-code in Cura.

ShowHide

Table of contents:

First Steps

After downloading Cura, you will go through the first basic steps of moving through the User agreement, release notes, and data sharing disclaimer. After agreeing to those items, you will be asked to add a printer.

Networked and non-networked 3D printers can be added to your Cura list. If your Ultimaker 3D printer is connected to the same network, you can directly connect to it so it will automatically configure your preferred setup. You can also add a printer by IP number.

After establishing the appropriate network connections, you can sign in with your Ultimaker account so that you have access to the cloud. You are ready to begin 3D printing and editing g-code in Cura.

Custom Mode

There are a number of customizable elements in the custom mode for Cura. These changes can modify your printing profile. In the right corner, if you click on the pencil icon, a dropdown menu for the print settings will appear. When you select “Custom” you will be presented with an overview of the custom print settings. The items presented to you that will affect printer actions are as follows:

  1. Linked setting. If this setting is activated, it will link all extruders. It will also always be equal between all extruders.
  2. Greyed out setting. This setting is overwritten by a child setting. In order to alter this, the child setting must be reset.
  3. Gear icon. Opens up the preferences in the settings.
  4. Information icon. Shows which settings are influencing the printer.
  5. Categories. Can be collapsed to hide them temporarily when focusing on different aspects.
  6. Reset icon. Resets the value to the default setting
  7. Calculated icon. Indicates the setting is typically calculated from a default setting.

Accessing G-Code Files

G-code files are saved as plain text files. Therefore, they can be edited in a plain text editor and imported into Cura. Cura uses a program called CuraEngine to generate its G-code.

In order to import a G-code file, click on the preferences, then click profiles, and then click import. A browser will then open up for you to import your plain text G-code file.

Additionally, you can go to the printer settings, and then machine settings, and type in your G-code manually in Cura. You will be able to enter G-code for the printer, extruder 1, and extruder 2.  You will have a G-code start column and end column.

Printer G-Code in Cura

In the printer column, you can modify the following aspects:

·         X (width)

·         Y (depth)

·         Z (height)

·         Build plate shape

·         Origin at center

·         Heated bed

·         Heated build volume

·         G-code flavor

·         Start G-code

On the left side is the printhead settings where you can modify the following aspects:

·         X min

·         Y min

·         X max

·         Y max

·         Gantry Height

·         Number of Extruders

·         End G-code

In both the Extruder 1 and Extruder 2 tabs you can modify the following aspects:

·         Compatible material diameter

·         Nozzle offset X

·         Nozzle offset Y

·         Cooling Fan Number

·         Extruder Start G-Code

·         Extruder End G-Code

G-Code Rules

Just like in algebra, G-code has its own set of rules regarding its order of operations. Here is a list of the more common rules in the order for which they will be followed by the program:

  • Comments
  • Feed rate
  • Spindle speed
  • Select tool
  • Change tool

Each G-code command places the machine into a “mode.” So for example, if you issue a G2 command followed by the coordinates, you will not need to issue another G2 command if you want it to perform another G2 action.

The reason for this is that the machine is already in G2 mode and will follow the coordinates in G2 mode until another command has been issued.

The F command sets the feed rate. This must be set, unless there is a default feed rate, before your first G command. In order to initiate a string of G-code, the % symbol must be at the start of every file.

History of G-Code

G-code was initially developed in the 1950s at MIT. It became standardized by the Electronic Industry Alliance. It was originally designed to work on an X-Y axis, the Z axis was a later development.

G-code also began as a very simple language that was unable to encode logic into its lines. It was designed for machines with a small amount of memory. Over time, new capabilities were added to include macro language.

G-Code Comments

In order to leave plain English comments, the language must begin with a semi-colon. Comments can serve as reminders or points of clarification for other programmers when they are reviewing your code.

It can also help you when you are going back to review an old or complex piece of code and you need a refresher.

G-Code Commands

The following will list the most common and important G-code commands that will be useful for you when using a 3D printer.

G0/G1 – Rapid and Controlled Motion

G0 tells the machine to move at maximum travel speed to the coordinates that follow G0. Both axes will coordinate their travel at the same time. G0 is not used for printing, but to move to another location or quickly begin another job in a different area.

G1 is a controlled motion command. Following G1 and its coordinates, a feed rate is determined. The axes will move in a coordinated manner to that location at the specified feed rate. The feed rate is written after the coordinates.

G2 – Clockwise Motion

Initiating G2 and including the offset from center will create a clockwise motion. The motion will begin at the starting point and travel to the specified endpoints. The G2 starting point will be where the machine is located prior to starting the G2 command.

G3- Counter Clockwise Motion

Similar to G2, this command will create a counter-clockwise motion.

G17/18/19 – Planes

These commands determine which planes will be printed upon by the printer. The following list describes the corresponding planes for each command.

• G17 = x/y plane

• G18 = z/x plane

• G19 = y/z plane

G20/G21 – Size

This determines the size of the units. G20 is for inches, G21 is for millimeters.

G28 – Referencing Home

The G28 command sends the extruder to its home position. If you are using multiple extruders, you can set coordinates after G28 to avoid extruder collisions. The extruder will travel to those coordinates and then travel home.

Depending on the printer you are using, you may be required to input coordinates to determine the home position.

G29: Bed Leveling

Mesh leveling measures the bed height at multiple points. This measurement will generate a 3D mesh that illustrates any failures or imperfections in the bed.

G60, G61: Save and Move Tool Position

G60 will save the tool to its specified slot. S will specify which memory slot it is saved to. The default memory slot is 0. G61 will return the tool to its previously saved location.

G90: Absolute Mode

This is considered the default mode for most novices and beginners. G90 causes all units to be interpreted as absolute coordinates.

G91 – Incremental Mode

This causes the extruder to move a number of units from its current point.

G92: Set Position

This will set the current position to the specified values. E<pos> creates a new extruder position. XIYIZ<pos> will set a new position on the X, Y, or Z-axis. If you want to reset the machine position, you would input G92.1. This will send the machine back to the default position of 0,0,0.

Feed Rate

The feed rate is the speed at which a tool performs an action. This can be applied to a number of applicable machine parts. The feed rate is one of the most important parts to take into consideration when editing G-code. It is measured in units/minute.

The feed rate is the requested speed for all axes and it can be considered the “speed dial” for parts of your printer.

Due to the fact that the feed rate is for all four axes, it will affect the outcome of your project if it is not calibrated correctly. If you perform a movement in one only one axis, it will be constrained by the maximum speed of that axis.

If you perform a movement on all four axes, the movement will be more smooth as the other axes catch up with each other.

Setting Feed Rate Percentage

Feed rate percentage is set by M220. Following M220 will be S[percentage]. So for example, if you want to set your feed rate percentage to 20%, your line of code would be M220 S20. You can also check the feed rate percentage by just inputting M220.

You can input M220 B to back up the current feed rate.

Flow Rate

The flow rate refers to the slicer setting that determines the amount of filament to extrude. It is also known as the extrusion multiplier. The flow rate is determined by M221.

To establish the flow rate, a line is created for M221 followed by S[percentage]. So for example, if you want to increase the flow rate to %110, the code would be M221 S150.

Initialization Phase

Before printing can occur, a number of steps need to be taken to ensure your printer operates properly and safely. Your G-code should contain commands to begin heating the print bed, heating the extruder, purging the nozzle, and bringing the nozzle to the start position.

Here is an example of a startup code that involves setting coordinates and warming up the printer bed.

  •      G90
  •      M82
  •      M106 S10
  •      M140 S150
  •      M190 S150

As mentioned previously, G90 sets the coordinates to absolute mode. That is the first step. The second line is an M-code, which will tell the extruder to interpret the units in an absolute value. The third line activates the fan at a low speed. The fourth and fifth lines tell the bed to heat up to 150 degrees and to then stop once it reaches 150 degrees.

Printing Phase

When a 3D printer begins printing, it works by slicing many horizontal layers. The nozzle will move many times on the X-Y plan to lay down filament and then make one movement up or down on the Z-plane to begin printing the next layer.

Resetting Phase

After a job is done, a printer should reset itself. A G28 command will bring the nozzle back to its home position. An M104 S0 and M140 S0 command will turn off the bed and the heaters. An M84 command will turn off the motors.

Examples of Basic G-Code Functions

The following examples are lines of code that are commonly used in 3D printing.

Changing a Filament

The following code is an example that could be placed where you want to change a filament on a single hot-end. The code will move the hot end out of the way and to a position that is accessible. It will then eject the current filament, wait for your signal, return to its designated start location, and resume printing.

Comments are included to paint a clearer picture as to why we would use certain G-codes to get to our desired outcome.

·         G91: Command to set relative positioning. Allows you to move the head and return it to start position.

·         G1 Z15 F1000 ; Lift the nozzle 15 mm at 1,000 mm/min. This brings the nozzle away from the project before it is raised higher up to a point where it is easily accessible.

·         G1 X100 Y100 F3000; From the nozzle’s current position, it will move right 100 mm and up 100 mm. This will make it easily accessible and move it far from the project.

·         G1 E-100 F1000: This will spit out the current filament.

·         M0: Pause and wait for user input — This is the point at which you can change the filament.

·         ; Change filament here: This is a command that is preceded by a semi-colon. It can be used to remind a new user or someone else who is unfamiliar with your code that this is for changing filament.

·         G1 E30 F10: Prime hot end with 30 mm new filament

·         G1 X-100 Y-100 F3000: This sends the nozzle back to its beginning location

·         G1 Z-10 F1000: This drops the hot end back to its beginning location.

·         G90: Resumes absolute positioning.

Remember, the g-codes are “modes” for the machine. If you switch out of G90 to enter G91, you must resume G90 mode after your task is complete.

Cleaning a Hot End

If you want to clean off a hot end in the middle of a project, the following code allows you to do so. The optimal time to change a hot end is in between layers.

  • G92 E0: Resets the filament length
  • G1 Yxx F500.0:  Moves hot end toward the top to get it away from the project
  • G1 X70.0 E10 F500.0: This initiates a purge to begin cleaning the hot end. It will extrude 10mm of filament over 70 mm of X travel
  • G1 X100 E12 F500.0: Conclude purge with 12 mm of filament over 100 mm
  • G92 E0: This resets the filament length
  • G1 Y-xx F500.0: This returns the hot end to the project so you can resume printing.

M-Code

M-codes are another vital set of commands that will be mixed in with your G-code program. M-code applies to specific parts of a machine and creates actions for that machine, whereas G-code sets the entire machine into a certain mode.

Similar to G-codes, M-code is also written with a number after the M. For example,

Additional M-Codes

The following is a list of common M-codes that you may find in 3D printing. These codes will often be found alongside G-codes so that a program will work properly.

M00/01: Program stop

The M0 and M1 commands pause after the previous movement. It will wait for the user to continue. M1 is a deprecated alias for M0. If S and P are included simultaneously following M00 or M01, S shall take precedence.

Here are the parameters for M00/01:

[P<ms>} Expire time in milliseconds

[S<sec>] Expire time in seconds

[string] Displays optional message on LCD

M02: End of program

M02 will end the program.

M03: Activates spindle in a clockwise direction

This will cause the machine to wait for a move to complete and then set the spindle speed. S will be the configured value range. I[mode] turns inline mode on or off.

M04: Activates spindle in a counter-clockwise direction

This will cause the machine to wait for a move to complete, and then set the spindle speed. S will be the configured value range. I[mode] turns inline mode on or off.

M05: Stops the spindle

This will cause the machine to wait for a move to complete, and then will turn off the spindle and PWM. With lase_move_G0_off and laser_mover_G28_off enabled, G0 and G28 will also turn the laser off

M06: Allows for a tool change

This identifies which tool you wish to change and will put it in the spindle. For example, if you want to change tool 5, you would input M06 T5.

M07, M08, M09: Coolant Controls

This is specific for printers that may have liquid cooling systems. M7 turns mist coolant on. M8 turns flood coolant on. M9 turns all coolant systems off.

M16: Expected Printer Match

This performs a case-sensitive comparison between the configured machine_name and the string argument. This serves as a feature that prevents errors or failures because if the machine name does not match, it will inform you to stop and reset the printer.

If your machine name is “Printer 1,” you would type M16 Printer 1 to stop the code if the machine is not named Printer 1.

M17: Enable Stepper Motors

A stepper motor is a set of electromagnetic coils that are activated in an assigned order. The activation causes the motor shaft to spin an exact number of degrees. Stepper motors are essential for 3D printer usage.

M17 by itself will enable all stepper motors. M17 followed by an axis will enable the motor just for that specified axis.

M18: Disable Stepper Motors

M18 can disable stepper motors via a timeout function, or by specifying which axis will deactivate. In order to deactivate through a timeout, the code would be M18 S[seconds].

M20: List SD Card

This command will list all the contents of an SD card. The contents will be displayed in a serial output DOS 8.3 format.

M21: Activate SD Card

If the SD card is not being detected automatically, you can override that error by inputting M21. This will initiate the SD card.

M24: Initiate an SD Card Print

This command will initiate or resume a printing job from an SD card.

M25: Pause an SD Card Print

This command will pause an SD card print.

M48: Probe Accuracy Test

In order to have a successful project printed, you must make sure your probes are accurate and calibrated properly. The probes will determine the proper height for your nozzle. M48 will test the probes for accuracy and produce a standard deviation based on at least two or more probes that are in the same XY axis location.

Here are the parameters for M48:

[E<engage>] : Engages for each probe

[L<legs>] : Number of legs to probe

[P<probe>] : Number of probes to test

[S<0I1>] : Star/Schizoid probe. Default test is seven points, this can be overridden with an L command. S0 performs a circular pattern whereas S1 performs a star pattern.

[V<level>] : Sets verbose level

[X<pos>] : X position

[Y<pos>] : Y position

M80, M81, M85: Activate/Deactivate Power

M80 will activate the high-voltage power source. M81 will deactivate the high-voltage power source.

M85 can deactivate the power source based on a timeout function. For example, if you wanted your printer to shutdown after one minute of inactivity, you would input M85 S<seconds>

M104, M105, M109: Hot End Temperature Actions

This will be important to calibrate based on the type of plastic/filament you are using for your project. Inputting M104 will update the temperature in the background without delay.

You can set a max target temperature by using B<temp> and a target temperature by using S<temp>.

M105 will report the hot end temperature.

M109 will cause the machine to wait for the hot end to reach a target temperature before resuming or beginning work. For example, if you input M109 S160, it will heat up to the target S temperature before resuming or beginning work.

M112: Emergency Stop

This command should be used to immediately stop all machine functions. It is used for emergencies. It will shut down all steppers and heaters. You will be required to issue a reset command to resume normal function.

Input and Output

Programming in a 3D printer is a two-way street. The communication has to go back and forth between the computer and the printer. When you initiate the print sequence, each line of code is sent to the printer from the computer one at a time. If no error is encountered, the computer will send the subsequent line.

Printers can also report back different statistics or parameters. Some of the data include coordinates of the nozzle, bed temperature, and more.

When you are ready to begin practicing your G-code abilities, you can use different visualization tools. Cura comes with a visualization tool. This will allow you to see what would happen if your code was activated without having to risk losing material or causing an accident. Visualization tools are helpful in avoiding printing failures.

Conclusion

G-code is a simple but effective language that can easily be edited in Cura. The program has options for customization that will suit everyone from beginners and hobbyists to professionals. It is important to remember that G-code and its commands are meant for machines to perform certain actions. In order to avoid mistakes, be sure to use visualization functions to ensure your code is written correctly. This will help you avoid any print failures or errors and will also save you from wasting materials and time.

Home /

How to Edit G-code in Cura: Everything You Need to Know

Craig A Fry

Craig A Fry

Craig has spent 20 plus years in the custom manufacturing industry as a COO, CEO and Owner of various custom product businesses. His experience has exposed him to all types of manufacturing from die cast, die struck, injection molding, CNC machining, laser etching, engraving and of course 3D printing.

Learn more about the author

Similar Posts You Might Like

ABOUT US AT 3D PRINTING SPOT

Our purpose is to provide the most helpful, and easy-to-read 3D printing content possible ALL IN ONE SPOT.  We will explain a technical topic in ordinary language, so ordinary people can unleash the creativity of 3D printing.  Come back often as we produce content multiple times a week.

SUBSCRIBE TO
3D PRINTING SPOT

CONTENT, NEW RELEASES & REVIEWS

Thank you! Be sure to check your email!
Something isn't right. Try to submit your email again.

3dprintingspot.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon. This site also participates in other affiliate programs and is compensated for referring traffic and business to these companies.

© 2021 3D Printing Spot
Contact UsTerms & Conditions | Privacy Policy

573 N Main Street Kaysville, UT 84037