G-code is the language of 3D printing and CNC machines. There are many different varieties of G-code that have many similarities as well as many differences. G-code files are not interchangeable between 3D printers and CNC machines because these machines perform very different functions. For instance, a CNC machine has a spindle, whereas a 3D printer has a heated nozzle.
Practically all 3D printers are controlled via G-code. G-code instructs the stepper motors how much to move, how hot to heat the build plate and nozzle, and it manages other functions such as pausing a print and leveling the bed.
Most FDM 3D printers use an open-source firmware called Marlin. It was derived from Sprinter and grbl and became a standalone project in 2011. Marlin features a complete G-code movement suite, including lines, arcs, and Bezier curves.
Here are some examples of simple movement G-code:
G0 X12 (move to 12mm on the X axis)
G0 F1500 (set the feedrate to 1500 mm/min)
G1 X90.6 Y13.8 (move to 90.6mm on the X axis and 13.8mm on the Y axis)
Other G-code commands include:
G0, G1 (move)
G28 (auto home)
G29 (bed leveling)
G35 (tramming assistant)
M18 (disable steppers)
M76 (pause print job)
M81 (power off) ...and many, many more
Writing Your Own G-code:
You can write your own G-code using a basic plain text editor such as TextEdit on a Mac or Notepad on Windows. Simply write the G-code manually in a text editor and save the file with a .gcode extension. Load the file onto an SD card, insert the SD card into a 3D printer, and navigate to the file on your 3D printer (the way you would normally 3D print a file).
Alternatively, you can send G-code commands directly to a 3D printer using your local network and Octoprint.