Designing your own boxes for 3D printing isn't difficult. We'll show you how!
Two significant things have happened in recent years that have been revolutionary in today’s electronics: access to low-cost and powerful microcontrollers, and the evolution of the 3D printer. We now have easy access to rapid prototypes, and enclosures are fundamental in the makerspace. It takes your pride and joy into the real world, enabling other people to experience your hard work, even if only in proof of concept. It’s equally crucial to make the right decision for housing our devices, as it is to ensure a positive user experience.
Primitive or prism?
This article led to some debate here in the DIYODE office. What defined a box? For some it was a rectangular prism yet others presented that it was a cube at it’s base and then expanded upon. We Google'd it and the result was “a container with a flat base and sides, typically square or rectangular and having a lid.” This did not really help us out in definition and the debate continues. We did however agree that for the purpose of this article when we say cube, it also refers to a box or a rectangular prism. This is because most 3D design pieces of software lay three primitives; the cube, the sphere and the cylinder. We have stuck with terminology of cube throughout this article, but do refer to the overall printed object as a “box”.
THE BROAD OVERVIEW
There are many options when it comes to enclosing a project. The Jiffy Box is your ready-to-go “one-stop-box-shop”, as they exist in various sizes and different plastics. They have a standard size pattern to which they adhere to, but should come close to fitting most projects. Other options include the Clamshell, which is similar to the Jiffy Box but split down the middle to create two identical halves; and our personal favourite, the rack case, which are designed to conform to a specific height, and be placed in a server rack unit along with your servers – many a time we’ve just sat and watched the pretty lights blink on the racks in the server room.
You may find that none of these options meet the needs that you require. So what should we do about that? Build one of course!
HOW IT WORKS
As simple as it sounds a box is merely a collection of three to four basic cubes.
All boxes and enclosures start with the simple question: “What’s in the box?” Now while the question itself is simple, it’s crucial that we know what is going inside, what size it is, what wires are involved, and what is the interface required by the human who will be using it? At a very simple level, we will create a box in Tinkercad with a matching lid and some simple mounts.
HOW AND WHAT TO MEASURE
Before we start designing our box we need to measure the objects that will be going inside it. We will be placing the circuit board in the bottom of the box, and building to an arbitrary height. However, we cannot do that without first identifying the information marked in the diagrams below.
A. Length (X)
B. Width (Y)
C. Mounting hole diameter
D. X-distance to centres
E. Y-distance to centres
F. Y-edge to centre
G. X-edge to centre
I. Overall height required (including box and clearance space)
We need to measure the X and Y. Then measure the diameter of the holes and the centres.
|Our board X, Y:||67mm x 47mm|
|Centres X, Y:||60mm x 36|
|X-edge distance to centre:||2.5mm|
|Y-edge distance to centre:||5mm|
Now that we have our box requirements to fit our PCB, we need to decide on the thickness of the walls. We will be using 2mm walls in this case, so our 67mm x 47mm PCB will need a box that measures 71mm x 51mm. We will leave the height at 20mm for the base, and we will add another 2mm on the top.
Once you create a new design or box that works, you may want to be able to resize it each time, to suit the needs of different projects. This is where the use of parametrics comes into play. Parametric design refers to defining a set of variables that may change for any given project, while other elements remain the same. For example, we want to build a box. The length (X) and the width (Y) will change for every project, but the height will always be 20mm, and the wall thickness will always be 2mm. Using software such as OpenScad you can define these and then just enter the variables each time to create the size of the box you need. A few extra minutes of design work can save hours in the long run.
Firstly we will build a box in Tinkercad. We have chosen to use Tinkercad due to its ease of use and its fantastic price tag of free! If you have never used Computer Aided Design (CAD) software before this is the place to start. The learning curve is nowhere near as steep as other pieces of software and it produces easily exported files that work with all popular slicing programs.
To build the bottom of our “box” we start by creating a cube the size of our calculated requirements (71x51x20mm), and then a second cube using the “hole” cube. (Alternatively you can create a cube then change its color to “hole”) Make this second cube to be the original dimensions we needed, 67x47x22mm. Select the new cube and make sure it is a hole and move it up (Z-axis) 2mm. This will ensure that we have a floor in our final print. Select both cubes and then use the align tool to align the X and Y to ensure they are sitting correctly and we will have even walls. Finally select both cubes and group; you will now have an empty bottom box with even sidewalls.
To build our lid or “box” top we create the third cube, making the dimension the same but the thickness 2mm. Place this object just off to the side of our original. Add a fourth cube this time the dimensions of the internal measurements, making it 4mm high. Select both cube objects and align so that the second site in the centre of the first. Next group them together, now we have a “box” with matching lid.
We need a to have a platform to support our project, in this case our veroboard. The holes are 5mm in diameter so we will need at least 6mm to support them. We will make the supports 5mm high to give clearance to soldering or wires that will run underneath. This will vary of course based on your board and wiring. As we are using 2.5mm screws, we need to have 2mm holes. We start by creating a cylinder, 6mm in diameter, 5mm high, before adding a second cylinder and setting it to “hole”. Make it 2mm in diameter and also 5mm high.
Make sure the second cylinder is selected and move it up 1 mm in the Z-axis. Next select both cylinders and align to centres before grouping them together.
Select the grouped object and the duplicate it four times. Select each one and move them in a rough rectangle pattern.
Select ruler and then select the support in the lower left. Make sure that you have selected midpoint on this tool. We use the ruler to ensure that the items are spaced, centre to centre as per our original measurements. Once aligned and set out, group the four supports, raise them in the Z-axis 2mm.
Select the group and the bottom of the box and align. You should now have the four supports in the bottom of your “box”.
Note: This “box” is designed to be snug and the top a friction lock. However, all printers will vary slightly, and different PLAs and filaments will cool at different rates. We found there was about 0.1mm shrinkage. This was enough for such a snug fit to not work. A quick Dremel along the top edge made it fit in a matter of seconds. However, if you were printing this on a regular basis, then we would recommend reducing the top lip by a small amount.
Tinkercad is great, and for quick one-off jobs it is fast. However, OpenSCAD is another tool for designing 3D objects but lends a lot from the programming world to allow the creation of parametric 3D designs. It does lack the drag and drop elements of Tinkercad, and hence many people find the interface intimidating. However, we recommend taking the time, even if only to do this tutorial, to see how simple it really is.
OpenSCAD has three primitive objects: the cube, the sphere and the cylinder, and everything is made up from these starting points. For our purpose, we will just be using the cube object. Like any program we start by declaring the variables that we will be using.
We will be building the same simple box from the previous tutorial. Unlike Tinkercad though, we will start by declaring the variables that we want to change.
We will define the four items we want to change on the fly, length, width, height and the thickness of the walls. Once complete, this is all we need to change in order to create any future box to any size we need.
Length = 100; // X axis
Width = 50; // Y
Height = 50; // Z
Wall = 2; // Wall thickness
Next, we define the main box. The code below can be broken down into four distinct sections, but due to the way OpenSCAD takes its commands, we need to start at line 2 with the “cube” command. This creates our first box, with the parameters of length, width and height.
Next, we create the second box; but before that can take place we need to change the box’s point of origin. This is done with the “translate” command and defining the point we want to start.
We then create our new cube, which is inside the first box we created. The definition for this second cube is a little more complex. You can see that the length dimension is now “Length-(Wall*2)”. So by offsetting our original “translate” command – to start the second cube inside the first by the distance – we set out in “Wall” and we then shorten its overall length by multiplying wall x 2. If our length is 100, then it results in the second cube being 96 long. This means we will have a 2mm wall at each end.
The same is repeated for the width, to shorten and create the walls.
The height is used without modification.
Now, because we started with the “difference” command, OpenSCAD makes the second cube subtract itself away from the first, resulting in a void. We now have the bottom section of our box.
To create the top, we start out with the “translate” command again, but we’ll offset the Y-axis to the current width +10. Next, we use a “union” instead of the “difference” command. A union will join two objects together – in this case, our two cubes. We create the first cube with the same length and width, but instead use the wall variable instead of the height. We then create the instep by introducing another cube. We set the translate again but leave the Z-axis as zero. This way, when we add the cube itself we’ll add the wall height, as that is the current height of the top; then add 2mm to the top to create the instep.
Once you’re complete, you can export the file to an STL, ready for printing. However, where this comes into its own is the ability to easily share it with others. You could share the source code, but others would need to use OpenSCAD to change the variables then export to an STL. Alternatively, you can upload the STL to Thingiverse and create an online parametric object. This allows other users to simply use dropdowns and enter their required values and download the object that suits their needs.
Length = 100;//X axis
Width = 50; //Y
Height = 50; //Z
Wall = 3; //Wall thickness