Yet Another Parametric Projectbox generator

[ 92 views ]

Een Nederlandse vertaling van deze post kun je hier vinden.

With every electronic circuit I make, there comes a moment when the project is “finished”…. almost!

The last step is always to find a suitable projectbox and even then it is difficult to provide a (often plastic) projectbox with cutouts of the right size and in the right place.

Fortunately I have a 3D printer and in theory I can make a projectbox myself, but it always takes a lot of time. For standard processor boards you can find 3D STL files on the internet, but if you have “designed” a printed circuit board yourself, the only way is a “parameter controlled” solution that you can read in Fusion 360 or in openSCAD. Then you can specify the size of the box via parameters and sometimes a little more, but it never really “fits” well or it is so complex that you have to graduate before you can make something useful with it.

I think I’ve found a solution that can provide almost any printed circuit board with a nice projectbox: the YAPP generator!

In this post I explain what the principles of this YAPP generator are and how you can use it to 3D print beautiful projectboxes!

What you need

  • openSCAD
    A recent version of “openSCAD” can be downloaded here.
  • the YAPP generator
    You can download this as a “.zip” file from github. Extract the “YAPP_Box-main.zip” file into your openSCAD projects folder. You now have a new folder “YAPP_Box-main” containing several sample files. In “YAPP_Box-main” there is also a folder “library” that contains the YAPP generator (so don’t throw it away!). It is wise to leave the folder structure as it is and save new box designs in this “YAPP_Box-main” folder.

Design philosophy

Most box generators that you can find on the internet allow you to specify the size of the box. Sometimes you have to give inside measurements and sometimes outside measurements.

YAPP does this differently and starts from the printed circuit board for which you need a projectbox. The most important measurements are therefore the length, width and thickness of the printed circuit board. Then you specify where the holes are with which the printed circuit board should be secured. The holes can be used to secure the PCB with screws or you can clamp the PCB between the standoffs in the bottom and top of the projectbox. Then you can specify for all surfaces (lid, base, front, back, left and right) of the projectbox where rectangular and/or round cutouts should be placed.

Finally, texts can be entered that will be printed at the lid of the projectbox.

Coördination System

Before going further it is necessary to understand what the orientation of the projectbox is. It should be clear that the projectbox has six “planes”.

The top is called “lid” the bottom is called “base”. The plane closest to the Y-axis is the “back”. “left” is closest to the X-axis. The plane opposite “back” (which is furthest from the Y-axis) is called “front” and the plane opposite “left” is called “right”

The “zero point” ([x=0, y=0, z=0]) is always left-back at the top of the PCB.

For each plane there is an array in which you can specify where the cutouts should be in that plane. These cutouts all have (pcb)[0,0,0] as their starting point. So if at any time it is decided to enlarge the edges around the PCB (padding) or to make the “pcbStandoffs” higher, the cutouts will move neatly with the position of the PCB.

Cutouts

There are two types of cutouts: “rectangles” and “circles”. Rectangles can be created in two ways, either with the corners at coordinates or with coordinates in the center of the rectangle. For “circles” the coordinates are always the center point.

Standoffs

The “pcbStandoffs” defines the distance between the top of the “base plane” and the bottom of the printed circuit board. Opposite the “standoffs” are automatically made “pushdowns” on the “lid” that are exactly so long that the circuit board is neatly clamped between them.

The standoffs can be fitted with “pins” so that the printed circuit board is also fixed on the X and Y axes. How many “pcb standoffs” should come and where they should be is specified in the array “pcbStands”. Each pcbStand is specified in one line and the properties of a pcbStand are defined per line.
This is how you use the pcbStands arrayt:

Each line in the array provides one standoff.

The third (2) element has the following meaning:

 yappBoth:       place both below a pcbStand and above a pcbStand.
 yappLidOnly:    the pcbStand is only printed above (lidHalf)
 yappBaseOnly:   the pcbStand will only be printed at the base (baseHalf). 

The meaning of the fourth (3) element is:

 yappHole:    the pcbStand is provided with a “hole” (hole)
 yappPin:     the pcbStand is provided with a “pin” 

If the third (2) element is “yappBoth” and the fourth (3) element is specified as “yappPin” then the pin will be printed on the baseHalf and a hole on the lidHalf.

It is possible to print both below and above a hole by specifying “yappHole” as the fourth (3) element:

 [3, 12, yappBoth, yappHole]

Cutouts in the other six faces

For each face there is an array in which you can specify per line where cutouts should come, what the origin of such a recess is (for rectangles) and what shape the recess should have (rectangle or circle). Depending on the “plane”, the first element is the position on the X-axis (lid-, base-, left- or rightPlane) or the Y-axis (front- or backPlane) and the second element is the position on the Y-axis (lid-, base-, left- or rightPlane) and the Z-axis (front-, back-, left- or rightPlane). The third element always indicates the width of the rectangle or the diameter of the circle. The fourth element is, again depending on the plane, the width (lid- or basePlane) or the height (front-, back-, left- or rightPlane) of the rectangle.

Cutouts in the Front Plane

Cutouts in the Back Plane

Cutouts in the Lid Plane

Cutouts in the Base Plane

Cutouts in the Left Plane

Cutouts in the Right Plane

Connectors to connect Base and Lid together

The connectors are ideal for connecting the two halves with so-called “inserts”.

A life real example

In this example we are going to create a projectbox for an Arduino UNO.

We start in openSCAD by opening the file “YACC_template.scad” and immediately save it again (“[Save as]) with the name “ArduinoUNO”.
Make sure that the new file is saved in the folder “YAPP_Box-main”.

Now edit the comment lines at the top of the file so that it is clear that a projectbox for an Arduino UNO can be generated with this file. The first real line of code inserts the YACC generator after which the YAPPgenerate() module from this library can be used.

     include <./library/YAPPgenerator_v10.scad> 

Outer dimensions and stand-offs

Now all variables that determine the final projectbox must be measured one by one and entered into the “ArduinoUNO.scad” file.

pcbLength    = 68.5; 
pcbWidth     = 53.3; 
pcbThickness = 1.5;                              

pcbStands = [
                 [14.0, 2.5,  yappBoth,     yappPin]  // back-left 
               , [15.3, 50.7, yappBaseOnly, yappPin]  // back-right 
               , [66.1, 7.6,  yappBoth,     yappPin]  // front-left  
               , [66.1, 35.5, yappBoth,     yappPin]  // front-right 
            ];

Connectors

The height of both the USB plug and the powerJack is 11mm.


To add some slack, let’s start the USB plug and the powerJack 1mm closer to the X-axis and increase the width of the cutout for the USB plug by 2mm and the cutout for the powerJack by 3mm. We will also increase the length of both cutouts slightly.

cutoutsLid = [ 
                 [0, 31.5-1, 12.2+2, 11.0, yappRectOrg] // USB 
               , [0, 3.5-1,  12.0,   13.5, yappRectOrg] // Power Jack  
             ]; 

cutoutsBack = [ 
                 [31.5-1, -1, 12.2+2, 12, yappRectOrg] // USB  
               , [ 3.5-1,  0, 12.0,   11, yappRectOrg] // Power Jack  
             ]; 

Headers and ATmega

cutoutsLid = [
                [0, 31.5-1, 12.2+2, 11.0,           yappRectOrg] // USB
              , [0, 3.5-1,  12.0,   13.5,           yappRectOrg] // Power Jack
              , [29-1,      12.5-1,  8.5+2, 35.0+2, yappRectOrg] // ATmega328
              , [17.2-1,    49.5-1,  5.0, 47.4+2,   yappRectOrg] // right headers
              , [26.5-1,     1.0-1,  5.0, 38.0+2,   yappRectOrg] // left headers
             ];

Other cutouts

Finally, the positions and size of the ICSP connectors, reset button and LEDs must be measured.

The total definition of the cutoutsLid array then looks like this:

cutoutsLid =  [
                 [0,      31.5-1, 12.2+2, 11.0,   yappRectOrg]    // USB
               , [0,       3.5-1, 12.0,   13.5,   yappRectOrg]    // Power Jack
               , [29.0-1, 12.5-1, 8.5+2,  35+2,   yappRectOrg]    // ATmega328
               , [17.2-1, 49.5-1, 5.0,    47.4+2, yappRectOrg]    // right headers
               , [26.5-1,  1.0-1, 5.0,    38.0+2, yappRectOrg]    // left headers
               , [65.5,   28.5,   8.0,     5.5,   yappRectCenter] // ICSP1
               , [18.0,   45.5,   6.5,     8.0,   yappRectCenter] // ICSP2
               , [6.0,    49.0,   8.0,     0.0,   yappCircle]     // reset button
//-- if space between pcb and lidPlane > 5.5 we don't need holes for the elco's --
//             , [18.0,    8.6,   7.2,     0.0,   yappCircle]     // elco1
//             , [26.0,    8.6,   7.2,     0.0,   yappCircle]     // elco2
//             , [21.5,    8.6,   7.2,     7.0,   yappRectCenter] // connect elco's
               , [28.2,   35.2,   5.0,     3.5,   yappRectCenter] // TX/RX leds
               , [28.2,   42.5,   3.0,     3.5,   yappRectCenter] // led13
               , [58.5,   37.0,   3.0,     3.5,   yappRectCenter] // ON led
              ];

In order to actually generate the projectbox, this module call must be placed at the bottom of the program:

     //--- this is where the magic happens --- 
     YAPPgenerate(); 

Then click on [F5] or [F6] to see the result of your work.

Second example (Wemos D1)

In this example we will create a projectbox for a Wemos D1 mini (V3.0.0). The starting point is again the YAPP_template.scad file which we read in and immediately write back as “WemosD1Mini.scad“.

First we have to measure all sizes again.

The “outer dimensions” are put at the top of the script.

 wallThickness        = 1.5;
 basePlaneThickness   = 1.0;
 lidPlaneThickness    = 1.0;

 baseWallHeight       = 4;
 lidWallHeight        = 4;

 pcbLength            = 35.0;
 pcbWidth             = 26.0;
 pcbThickness         = 1.0; 

 // padding between pcb and inside wall
 paddingFront         = 1;
 paddingBack          = 1;
 paddingRight         = 1.5;
 paddingLeft          = 1.5;

 // ridge where base and lid off box can overlap
 // Make sure this isn't less than lidWallHeight
 ridgeHeight          = 2; 

 pinDiameter          = 1.8;
 standoffDiameter     = 4;

 // How much the PCB needs to be raised from the bottom 
 // to leave room for solderings and whatnot
 standoffHeight       = 2.0; 

The positions and size of the cutouts are included in the cutoutsLid, cutoutsBase, cutoutsFront, and cutoutsRight arrays.

//-- pcb standoffs -- origin is pcb-0,0
pcbStands =    [
                   [3.4,         3.0,        yappBoth, yappPin]  // back-left
                 , [3.4,         pcbWidth-3, yappBoth, yappHole] // back-right
                 , [pcbLength-3, 7.5,        yappBoth, yappHole] // front-left
                 , [pcbLength-3, pcbWidth-3, yappBoth, yappPin]  // front-right
               ];

//-- front plane -- origin is pcb-0,0 (red)
cutoutsFront = [
                    [14.0, 1.0, 12.0, 10.0, yappRectCenter] // microUSB
               ];

//-- top plane -- origin is pcb-0,0
cutoutsLid =   [
                    [6.0, -1.0,       6.0, pcbLength-12, yappRectOrg] // left-header
                  , [6.0, pcbWidth-4, 6.0, pcbLength-12, yappRectOrg] // right-header
                  , [18.7, 8.8,       2.0, 0.0,          yappCircle]  // blue led
               ];

//-- bottom plane -- origin is pcb-0,0
cutoutsBase =  [ 
                    [6.0, -1.0,       6.0, pcbLength-12, yappRectOrg] // left-header
                  , [6.0, pcbWidth-4, 6.0, pcbLength-12, yappRectOrg] // right-header
               ];

//-- left plane -- origin is pcb-0,0
cutoutsLeft =  [
                    [31.0, 0.5, 4.5, 3, yappRectCenter] // reset button
               ];

Note that there are only two holes in the circuit board. To keep the printed circuit board in place, four pcbStand are made, but two of them have no pins. Because there is a reset switch in the left front corner, the pcbStand must also be placed in a slightly shifted place in this corner.

Finally, the YAPPgenerate() module must be called:

   //--- this is where the magic happens ---
   YAPPgenerate();

Then press [F5] or [F6] to check if the project box looks as you imagined.

Debug options

There are several options for viewing additional information about the generated projectbox so that it can be checked during the design phase whether the script does what it should do.

  printLidShell    = true; 
  printBaseShell   = true; 

  //-- D E B U G -------------------- default 
  showSideBySide      = true;      // true 
  hideLidShell        = false;     // false 
  colorLid            = "yellow";  // yellow 
  hideBaseShell       = false;     // false
  colorBase           = "white";   // white 
  showPCB             = false;     // false 
  showMarkers         = false;     // false 
  inspectX            = 0;         // 0=none, -pcbLength .. +pcbLength 
  inspectY            = 0;         // 0=none, -pcbWidth .. +pcbWidth 
  //-- D E B U G ------------------- 

The first two variables (printLid and printBase) indicate whether the top half of the projectbox or the bottom half should be printed. This can be useful if your 3D printer is not large enough to print both halves side by side or if you have only made adjustments in one of the two and (so) only want to 3D print that half again.

showSideBySide

hideLidShell / hideBaseShell

This setting provides insight into the “inside” of the projectbox.

showPCB

This option is especially useful in side-by-side presentation or when showLid and/or showBase are “false”.

showMarkers

Markers are displayed on the four corners of the circuit board and on the rear left corner of the box.

inspectX / inspectY

With a value of -pcbLength to +pcbLength, a cross section of the projectbox is shown.


This entry was posted in 3D printing, Arduino, Computer, ESP8266, Hardware, Scripts. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 4 MB. You can upload: image, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here

This site uses Akismet to reduce spam. Learn how your comment data is processed.