{"id":195,"date":"2015-07-14T23:46:19","date_gmt":"2015-07-14T23:46:19","guid":{"rendered":"http:\/\/www.comvolt.com\/eblog\/?p=195"},"modified":"2015-07-21T18:44:15","modified_gmt":"2015-07-21T18:44:15","slug":"example-code-how-to-3d-print-your-own-stand-offs-for-electronics","status":"publish","type":"post","link":"http:\/\/www.comvolt.com\/eblog\/example-code-how-to-3d-print-your-own-stand-offs-for-electronics\/","title":{"rendered":"Example Code: How to 3D Print Your Own Stand-off&#8217;s for Electronics"},"content":{"rendered":"<p>Often times in electronic assemblies, printed circuit boards (PCB) are spatially separated from one another through the use of stand-offs. \u00a0These stand-offs are usually quite prone to breaking, especially if you&#8217;re replacing\/repairing\/generally manipulating the PCBs attached to them.<\/p>\n<p>Finding a\u00a0stand-off that perfectly matches the original equipment manufacturer (OEM) stand-off can be a real pain, if even possible. \u00a0Luckily, with the advent of 3D printers, you can print your own stand-offs to your own specs!<\/p>\n<p>There is\u00a0an array of software packages available for designing models to be printed by 3D printers. \u00a0We like <a href=\"http:\/\/www.openscad.org\" target=\"_blank\">OpenSCAD<\/a> because it&#8217;s:<\/p>\n<ul>\n<li>free<\/li>\n<li>precise<\/li>\n<li>easy-to-use (even with very limited programming experience)<\/li>\n<li><em><strong>PARAMETRIC MODELS<\/strong><\/em><\/li>\n<\/ul>\n<p><a href=\"http:\/\/www.openscad.org\" target=\"_blank\">OpenSCAD<\/a> allows the user to &#8220;script&#8221; their model to precise dimensions and positioning, as opposed to popular GUI software where the user &#8220;draws&#8221; the model with the computer mouse. \u00a0GUIs 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.<\/p>\n<p>Did we mention that OpenSCAD models are parametric? That means that you can define models according to variables rather than fixed numbers.<\/p>\n<p>For example: \u00a0you want a small box to hold your keys. \u00a0This box (imperfect cube) only needs to be about 75 mm\u00a0wide, \u00a025\u00a0mm\u00a0deep, and 50 mm tall (roughly 3 x 1 x 2 inches). \u00a0You write some code like \u00a0&#8220;&#8230;cube([75,25,50]);&#8230;.&#8221; \u00a0along with some other stuff and that results in a box that&#8217;s the best size for holding your keys.<\/p>\n<p>But you really like that box, and you wish you had one just like it, except bigger, to hold your shoes. \u00a0So you go write new code \u00a0&#8220;&#8230;cube([300,125,125]);&#8230;&#8221;. \u00a0<em>But then<\/em>\u00a0you want <i>another box<\/i>\u00a0to hold your silverware. \u00a0So you go write <em>more<\/em>\u00a0code with <em>those\u00a0<\/em>dimensions.<\/p>\n<p>Well how about instead, you have one code file (e.g. box.scad) that begins by declaring some variables:<\/p>\n<p>x = ; \u00a0y = ; \u00a0z = ; \u00a0&#8230;and then your line &#8220;cube([x,y,z]);&#8221;&#8230;<\/p>\n<p>Now, you can simply open &#8220;box.scad&#8221; and change the numbers for x=, y=, z= at the beginning, and the code will automatically generate the box to those dimensions.<\/p>\n<p>Obviously this isn&#8217;t the best example &#8211; it&#8217;s not hard to type &#8220;cube([##,##,##]);&#8221; multiple times. \u00a0But if you&#8217;re familiar with OpenSCAD (or any other programming), you know that the code is much more than one simple cube line. \u00a0The model you&#8217;re generating likely passes x,y,z dimensions into several functions\/modules to render the final piece. \u00a0It&#8217;d be a total pain to hunt down all the functions that use the dimensions you want to change and manually alter them. \u00a0So that&#8217;s why we define those variables at the beginning and pass them into all our functions. \u00a0Then you can simply change the variables at the top of the code anytime you want to reuse it for a slightly different size.<\/p>\n<p><strong><span style=\"text-decoration: underline;\">BACK TO THE STAND-OFF<\/span><\/strong><\/p>\n<p>We promised some example code. \u00a0So here it is, albeit extremely simple:<\/p>\n<p><strong><span style=\"color: #ff0000;\">r = 5; h = 20; thickness = 2;<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #ff0000;\">difference(){<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #ff0000;\">cylinder(r=r,h=h);<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #ff0000;\">cylinder(r=r-thickness,h=h);<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #ff0000;\">}<\/span><\/strong><\/p>\n<p>&nbsp;<\/p>\n<div id=\"attachment_201\" style=\"width: 283px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.comvolt.com\/eblog\/wp-content\/uploads\/2015\/07\/standoff.png\"><img data-recalc-dims=\"1\" decoding=\"async\" aria-describedby=\"caption-attachment-201\" loading=\"lazy\" class=\"wp-image-201 size-full\" src=\"https:\/\/i0.wp.com\/www.comvolt.com\/eblog\/wp-content\/uploads\/2015\/07\/standoff.png?resize=273%2C459\" alt=\"Simple stand-off generated from the above code in OpenSCAD\" width=\"273\" height=\"459\" srcset=\"https:\/\/i0.wp.com\/www.comvolt.com\/eblog\/wp-content\/uploads\/2015\/07\/standoff.png?w=273 273w, https:\/\/i0.wp.com\/www.comvolt.com\/eblog\/wp-content\/uploads\/2015\/07\/standoff.png?resize=178%2C300 178w\" sizes=\"auto, (max-width: 273px) 100vw, 273px\" \/><\/a><p id=\"caption-attachment-201\" class=\"wp-caption-text\">Simple stand-off generated from the above code in OpenSCAD<\/p><\/div>\n<p>If you download <a href=\"http:\/\/www.openscad.org\" target=\"_blank\">OpenSCAD<\/a>, you can copy-paste this code right into the editor to make a simple stand-off. \u00a0Note that simply changing the numbers for <strong>r<\/strong>adius, <strong>h<\/strong>eight, and <strong>thickness<\/strong>\u00a0is all that&#8217;s needed to scale this stand-off to your liking.<\/p>\n<p>There are a ton of resources out there on the internet to assist you in learning 3D modeling. \u00a0But, if you need a specific model and lack the time\/will to design it yourself, email info@<a href=\"http:\/\/www.comvolt.com\" target=\"_blank\">comvolt.com<\/a> for any inquiries!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often times in electronic assemblies, printed circuit boards (PCB) are spatially separated from one another through the use of stand-offs. \u00a0These stand-offs are usually quite prone to breaking, especially if you&#8217;re replacing\/repairing\/generally manipulating the PCBs attached to them. Finding a\u00a0stand-off &hellip; <a href=\"http:\/\/www.comvolt.com\/eblog\/example-code-how-to-3d-print-your-own-stand-offs-for-electronics\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[215,223,216,221,222,219,220,217,218],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-3d","tag-3d-model","tag-3d-print","tag-model","tag-modelling","tag-openscad","tag-scad","tag-stand-off","tag-standoff"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":7,"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":208,"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/posts\/195\/revisions\/208"}],"wp:attachment":[{"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.comvolt.com\/eblog\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}