top of page
Search
Writer's pictureMatteo

How to write head and tail instructions

Updated: Sep 28, 2021

In this tutorial we will dive into g-Code instructions. We will focus on how to write head and tail instructions in order to adapt g-Code to any printer (your printer!).


Disclaimer: this tutorial is written with Marlin and/or Prusa firmware in mind. Most basic commands are the same across different firmware, however it is your responsibility to check what commands your firmware uses.


g-Code Anatomy

Tip: you can open and edit your gCode in any text editor.


Let's start from the basics:

  • g-Code commands are issued through a combination of letters and numbers which tell the firmware which command to run, and what are the variables of that command.

  • A g-Code file consists of a series of lines in a text editor. Each line is a single command. Your printer reads and runs them in order.

  • Most commands in 3d printing are G or M commands (e.g. G1, G90, M82, ...).

  • You can comment a line using semicolons (;). When the printer runs into a semicolon (;), it ignores what comes after it and jumps straight to the next line.

For example:

G1 X0 Y0 Z0 ;move to coordinates 0,0,0

G1 X1 Y1 Z0 E1 ;move to coordinates 0,0,0 while extruding 1mm of filament


Structure of 3d printing g-Code

In 3d printing, the g-Code is normally organized in 3 main blocks:

  • Head: a set of instruction that inform the machine on what step to take before printing commence.

  • Main Body: it is the core of your print. It includes all the instructions concerning your print object: where to move the extruder, at what speed, how much material to extrude, and so on.

  • Tail: a set of instructions that inform the machine on what step to take after the print is finished.

The Main Body, is what you download from SliceUp modules. You will have to write Head and Tail instructions in order to tailor the Main Body to your machine. Let see how.


How to write Head g-Code

It is important to understand that the necessary head instructions will vary depending on your hardware/firmware and there is no 'one-fit-all-solution'. Also, in any given case there will be multiple way of writing instructions that will get the job done.


However, the objective is that of getting the machine ready to print, and in order to do so, you want to perform the following operations:

  • Set Bed Temperature (FDM only) - M140/M190

  • Set Extruder Temperature (FDM only) - M104/M109

  • Set Units to millimiters - G21

  • Set Coordinates System - G90/G91

  • Set Extrusion mode - M82/M83

  • Home all axis - G28

  • Auto Bed Levelling (optional) - G29(marlin) - G80/(prusa)

  • Prime the extruder (optional) - G1 (purge line)

TIP: if this is new to you, it may be a good idea to open up an older g-code, so you can study the head. DO NOT copy and paste blindly, instead, try go through the different commands, understand what everything does, and reduce the head to a bare minimum.


The following two images shows how I tackle all the points on two different machines: a CR10, using Marlin 2.0 firmware, and a prusa MK2, which uses Prusa Firmware.

3d print g-code example
CR10 vs Prusa MK2 head g-Code

A couple things to watch out for:

  • Make sure to set extruder coordinates (relative vs absolute) so they are coherent with the slicing setting. If you are unsure , check E values. Relative E values are made up of small increments, while Absolute E value adds up at each line.

  • If you are using absolute E coordinates (M82), remember to reset E values to 0 before the main block (G92 E0, as seen in the Prusa Head).

  • The first 6 line of the Prusa's head are setting maximum values for acceleration, feed rate, travel, jerk. This are advanced settings and in most cases are not necessary in SliceUp. Those value are usually defined to a standard value in the firmware, however, you can overwrite those value in the g-code, if necessary.

  • It is good practice commenting each line, so to catch up with different commands quicker.

  • It is convenient to save head/tails as machine-material-type of extrusion, so I can retrieve it easily and quickly copy and past them when needed


How to write Tail g-Code Instructions

As before, Tail instructions can vary depending on your hardware, and it could be a good idea to study what it normally happens by opening an old g-Code.


Normally, you will want to perform the following operations:

  • Move extruder away from the print - G1

  • Turn off bed heater - M140

  • Turn off extruder heater - M104

  • Turn off part cooling fan - M107

  • Disable stepper motors - M84

The following images shows how I tackle Tail instructions on two different machines: a CR10 using Marlin 2.0 firmware and a Prusa MK2 using Prusa firmware.

tail g-code instructions example
CR10 vs MK2 tail gCode

Again, a couple of things to watch out for:

  • In both example G1 is used to move the extruder to the upper hardware limit along Z. If you do the same, make sure to adjust the Z value in order to fit your printer volume.

  • Disabling the stepper motor may not be a good idea on a delta printer, as sometimes the extruder may fall and crash on the printer.

Save your .gcode

From your text editor:


Save As > set file type as All Files > save using .gcode extension


Unblock .gcode file

Depending on your OS and/or firewall setting, you may need to unblock the gCode file before loading it on a SD Card. To do so:


Right Click the File > Properties > uncheck the Unblock box > Apply



Give it a try!

Hopefully this tutorial cleared things up a little, so do not be afraid to give it a try. If you are a newbie it is a lot to process at first, but confidence will come over time.


If you still feel insecure about it, or if you are in need of further explanation, do not hesitate to ask for help on the forum. If you want to learn more about g-Code, check this useful links to some good resources that treat g-Code in detail.




208 views0 comments

Comments


Commenting has been turned off.
bottom of page