Example Code: How to 3D Print Your Own Stand-off’s for Electronics

Often times in electronic assemblies, printed circuit boards (PCB) are spatially separated from one another through the use of stand-offs.  These stand-offs are usually quite prone to breaking, especially if you’re replacing/repairing/generally manipulating the PCBs attached to them.

Finding a stand-off that perfectly matches the original equipment manufacturer (OEM) stand-off can be a real pain, if even possible.  Luckily, with the advent of 3D printers, you can print your own stand-offs to your own specs!

There is an array of software packages available for designing models to be printed by 3D printers.  We like OpenSCAD because it’s:

  • free
  • precise
  • easy-to-use (even with very limited programming experience)
  • PARAMETRIC MODELS

OpenSCAD allows the user to “script” their model to precise dimensions and positioning, as opposed to popular GUI software where the user “draws” the model with the computer mouse.  GUIs are fantastic for artistic models (e.g. miniature sculpture), but not so great for scientific/mechanical/structural objects like stand-offs, where the dimensions of every minor feature to the model make or break its usefulness.

Did we mention that OpenSCAD models are parametric? That means that you can define models according to variables rather than fixed numbers.

For example:  you want a small box to hold your keys.  This box (imperfect cube) only needs to be about 75 mm wide,  25 mm deep, and 50 mm tall (roughly 3 x 1 x 2 inches).  You write some code like  “…cube([75,25,50]);….”  along with some other stuff and that results in a box that’s the best size for holding your keys.

But you really like that box, and you wish you had one just like it, except bigger, to hold your shoes.  So you go write new code  “…cube([300,125,125]);…”.  But then you want another box to hold your silverware.  So you go write more code with those dimensions.

Well how about instead, you have one code file (e.g. box.scad) that begins by declaring some variables:

x = ;  y = ;  z = ;  …and then your line “cube([x,y,z]);”…

Now, you can simply open “box.scad” and change the numbers for x=, y=, z= at the beginning, and the code will automatically generate the box to those dimensions.

Obviously this isn’t the best example – it’s not hard to type “cube([##,##,##]);” multiple times.  But if you’re familiar with OpenSCAD (or any other programming), you know that the code is much more than one simple cube line.  The model you’re generating likely passes x,y,z dimensions into several functions/modules to render the final piece.  It’d be a total pain to hunt down all the functions that use the dimensions you want to change and manually alter them.  So that’s why we define those variables at the beginning and pass them into all our functions.  Then you can simply change the variables at the top of the code anytime you want to reuse it for a slightly different size.

BACK TO THE STAND-OFF

We promised some example code.  So here it is, albeit extremely simple:

r = 5; h = 20; thickness = 2;

difference(){

cylinder(r=r,h=h);

cylinder(r=r-thickness,h=h);

}

 

Simple stand-off generated from the above code in OpenSCAD

Simple stand-off generated from the above code in OpenSCAD

If you download OpenSCAD, you can copy-paste this code right into the editor to make a simple stand-off.  Note that simply changing the numbers for radius, height, and thickness is all that’s needed to scale this stand-off to your liking.

There are a ton of resources out there on the internet to assist you in learning 3D modeling.  But, if you need a specific model and lack the time/will to design it yourself, email info@comvolt.com for any inquiries!