Watching a 3D printer build an object (especially for the first time) is a fascinating experience. It isn’t just the fact that the this printer is creating something from scratch, but also the grace by which it does it. It’s the various speed changes, the dance of the nozzle across the print bed, the flawless control system specifying every movement and function. Believe it or not, you yourself can orchestra the mind of your 3D printer by controlling or writing in gCode, the programming language that directs every movement and adjustment your machine makes.
For those who don’t know, gCode is an old numerical control (NC) programming language that allows people to define how a computerized machine tool, like 3D printing or CNC milling, will produce something. This includes where the printhead moves, how fast it moves, what direction it moves in, as well as the extruder temperature, retraction settings, and the fan as well. This gCode is what is produced by your slicer software, whether is be Cura, Simplify3D, Slicr, or any other, essentially preparing every aspect of how the proposed 3D model will be manufactured. When the gCode is sent to the printer it will appear as a long strand of certain characters and numbers, like so:
N4 G92 E0*67
N6 G1 F1500.0*82
N7 G1 X2.0 Y2.0 F3000.0*85
N8 G1 X3.0 Y3.0*33
This is basically a string of commands or parameters separated by a space or a new line. Though each machine has a specific gCode language, they oftentimes share the same commands, the most common families are Marlin, Repetier, and Reprap. By hooking up your computer to your 3D printing device, you can actually write your own gCode and watch is your printer reacts to your command. This is especially useful for those looking to run specific tests during calibration or control a print too complex for default slicers, or someone planning to find the best temperature settings or change the color of a filament. Additionally, gCode is modified manually to change the temperature between layers, which can be helpful to find the sweet spot for specialized materials with wood filaments.
The gCode can be written in either ASCII and binary encodings. The former is actually binary file that’s defined by ASCII characters, each character (byte) essentially holds a unique binary code (bits). This enables ASCII to be exported and written in a text editor like notepad, which will allow you to see all the commands that the 3D printer controller will undertake during the printing process. Some of these commands are standard, while others are more specific to certain languages. The two primary commands are G-commands, which controls standard gCode things like movement, and M-commands, a RepRap-defined command that controls other functions of the printer, such as turn a cooling fan on or off. Though this language seems quite daunting to learn, resources like the RepRap Wiki act as a comprehensive reference of commands and codes.
- G0 & G1: Move
- G10 : Retract
- G11 Unretract
- M107: Fan Off
- M106: Fan On
- M104 : Set Extruder Temperature
But be careful when you’re editing the gCode yourself, as you could possibly overload and damage your 3D printer!