GCode Editor

Published 16 August 2016

Above: an uncorrected soldermask and the circuit board it covers. Note some pairs of pads on the board correspond to a slot on the mask; this causes bridges.

I needed to edit GCode 3D printer commands, so I wrote a full program for it. You can find source, documentation, and a download on BitBucket. Pull requests welcome! Why I needed this program, what it does, and how you can improve it all below the fold!

A brief introduction to GCode and the need for this program

RepRap-like 3D printers use a flavor of a language called ‘GCode’ to encode instructions for creating a form. GCode takes the form of a text file with one command on each line. The commands are low-level instructions for moving motors and other components; a line might look like M129 P1000, where M129 is the wait command, and P1000 is a 1000ms (1 second) duration. It is possible to write GCode by hand using a text editor, but it is very difficult because GCode encodes spatial data. Luckily, programs called ‘slicers’ exist to turn 3D models like STLs or OBJs to GCode. These programs are great, but their general-purpose algorithms tend to run into issues with some strange geometries (like very thin planes: see later in this post). The GCode slicers output in these cases is typically almost what the users wants, but need some human intervention. Changing the code with a text editor is tedious at best and futile at worst, so I wrote a program to allow the easy graphical editing of these files.

Use case

I’m printing solder stencils to allow me to fabricate environmental sensors more easily and reliably. However, my current design iteration (more on that in a later post) uses a couple 0603 SMD components. 0603 components are absolutely tiny, which is why the solder stencil is necessary: I place the circuit board under the stencil (which has a raised lip to help align the board), then use a little plastic slide to apply solder paste to the stencil. Holes in the stencil deposit solder on the circuit board. Then, I remove the stencil, place components on the little solder pads, and heat the entire assembly to allow the solder to flow. Because the stencil is about 0.5mm thick, it deposits plenty of solder; since I use professionally printed boards, the solder flows accross the surface of the metal pads but does not leap to other pads easily because of a coating called soldermask, which repels it. If anyone has used crayons and watercolors to produce small patches of watercolor, it works on much the same principle. However, if there is solder already connecting the pads when the board is heated, it is virtually guaranteed to make bridges, shorting out the component.

0603 Resistor: so called because it is 0.6in by 0.3in The resistor which makes tiny soldermask holes so important

This is a problem because many slicing algorithms treat two closely-spaced holes on a single-layer-thick print as one hole, perhaps expecting to split them on a nonexistent second layer. Now, because of the thickness of the stencil (and the resulting abundance of solder), I don’t mind covering some of the pad with stencil, but I do mind bridging two pads. Unfortunately, the merged hole causes a large bridge to appear, and there is no setting for such a specific use case in Slic3r. This is where the program (which I have unimaginatevly titled ‘GCode Editor’) comes in. You can download a copy on my BitBucket, or build it from source. The jarfile works for everyone, and the .deb provides filetype association and dash search for Debian-derived OSes (like Ubuntu). Using the program, I am now able to correct Slic3r’s output to add a single extrusion command to separate the pads. Conveniently, the program reorders commands, alters their extrusion parameters to match, and inserts G92 (coordinate reset) commands as necessary to avoid altering the rest of the program.

Caveats

The program does not have any sanity checks, instead assuming the user knows what is and isn’t possible for their printer. At present, the program does not have dedicated support for multiextruder programs. That said, it is fairly stable and completely open source, so the best way to see if things work is to try them and if you need a feature which isn’t in there, I invite you to add it.