-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPCBEnclosure.scad
More file actions
374 lines (332 loc) · 11.6 KB
/
PCBEnclosure.scad
File metadata and controls
374 lines (332 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// preview[view:south east, tilt:top diagonal]
/* [Basic Settings] */
case_type = "arduino"; // [arduino:Arduino Uno,custom:Custom]
feet = "mag"; // [raised:Raised,mag:Magnetic,hole:Holes,wing:Wings,none:None]
attachment_type = "nothread"; // [hotinsert:Hot Insert,nothread:Undersized Hole]
bolt_size = 2.5; // [2.5:2.5mm,3:3mm,4:4mm]
/* [Case Options] */
// Include a slot for the PCB at the bottom of the case
bottom_board_cutout = "include"; // [include:Include,exclude:Exclude]
// Add an extra slot for a PCB at the top of the case
top_board_cutout = "exclude"; // [include:Include,exclude:Exclude]
// Add an extra slot for a PCB at mid-height
middle_board_cutout = "exclude"; // [include:Include,exclude:Exclude]
// Include the top of the case
top_cap = "exclude"; // [include:Include,exclude:Exclude]
// Include the two end caps
end_caps = "include"; // [include:Include,exclude:Exclude]
// Include vents in the top of the case (if available)
vents = "exclude"; // [include:Include,exclude:Exclude]
// Include ribs on the side of the case
rib_type = "outer"; // [inner:Inner,outer:Outer,none:None]
/* [Custom PCB Dimensions] */
// PCB width in mm
custom_width = 65;
// Case height above PCB in mm
custom_height = 30;
// PCB length in mm
custom_length = 75;
// PCB thickness in mm
pcb_height = 1.6; // Height of all PCB's in mm
/* [Print Details] */
// Wall thickness in mm
wall = 1.7;
// Percent of shrink in non-threaded holes
hole_shrink = 0.85;
// Clearance in mm around X, Y and Z of PCB cutouts
pcb_clearance = 0.15; // The clearance amount for the PCB in mm
// Clearance in mm around hot insert holes
hot_insert_clearance = 0.25; // The clearance amount for hot inserts in mm
through_factor = 1.05; // Factor to enlarge holes for bolts
/* [Hidden] */
hole = bolt_size/2;
fillet = hole * (attachment_type == "hotinsert" ? 5 : 4.5);
width = custom_width;
height = custom_height;
length = custom_length;
width = case_type == "arduino" ? 53.50 : custom_width;
height = case_type == "arduino" ? 30 : custom_height;
length = case_type == "arduino" ? 68.8 : custom_length;
color("orange")
union() {
if (feet == "raised") {
rotate([90,0,180])
translate([width/2-10,length-10,-(height/2)-wall-1])
cylinder(h=2, r1=2.5, r2=5, center=false, $fn = 20);
rotate([90,0,180])
translate([-width/2+10,length-10,-(height/2)-wall-1])
cylinder(h=2, r1=2.5, r2=5, center=false, $fn = 20);
rotate([90,0,180])
translate([width/2-10,10,-(height/2)-wall-1])
cylinder(h=2, r1=2.5, r2=5, center=false, $fn = 20);
rotate([90,0,180])
translate([-width/2+10,10,-(height/2)-wall-1])
cylinder(h=2, r1=2.5, r2=5, center=false, $fn = 20);
}
else if (feet == "mag") {
difference() {
rotate([90,0,180])
translate([width/2-10,length-10,-(height/2)-wall-1])
cylinder(h=2, r1=3, r2=5, center=false, $fn = 20);
rotate([90,0,180])
translate([width/2-10,length-10,-(height/2)-wall])
cylinder(2,2.75,2.75,true, $fn = 20);
}
difference() {
rotate([90,0,180])
translate([-width/2+10,length-10,-(height/2)-wall-1])
cylinder(h=2, r1=3, r2=5, center=false, $fn = 20);
rotate([90,0,180])
translate([-width/2+10,length-10,-(height/2)-wall])
cylinder(2,2.75,2.75,true, $fn = 20);
}
difference() {
rotate([90,0,180])
translate([width/2-10,10,-(height/2)-wall-1])
cylinder(h=2, r1=3, r2=5, center=false, $fn = 20);
rotate([90,0,180])
translate([width/2-10,10,-(height/2)-wall])
cylinder(2,2.75,2.75,true, $fn = 20);
}
difference() {
rotate([90,0,180])
translate([-width/2+10,10,-(height/2)-wall-1])
cylinder(h=2, r1=3, r2=5, center=false, $fn = 20);
rotate([90,0,180])
translate([-width/2+10,10,-(height/2)-wall])
cylinder(2,2.75,2.75,true, $fn = 20);
}
}
else if (feet == "wing") {
translate([width/2,-height/2-wall/2,0])
difference() {
cube(size = [8,wall,length]);
translate([4,0,10])
rotate([90,90,0])
cylinder(15,hole*through_factor,hole*through_factor,true,$fn=20);
translate([4,0,length-10])
rotate([90,90,0])
cylinder(15,hole*through_factor,hole*through_factor,true,$fn=20);
}
translate([-(width/2)-8,-height/2-wall/2,0])
difference() {
cube(size = [8,wall,length]);
translate([4,0,10])
rotate([90,90,0])
cylinder(15,hole*through_factor,hole*through_factor,true,$fn=20);
translate([4,0,length-10])
rotate([90,90,0])
cylinder(15,hole*through_factor,hole*through_factor,true,$fn=20);
}
}
difference() {
linear_extrude(length) {
// Draw two squares and offset to shell
difference() {
offset(r = (wall/2)) {
square([width+pcb_clearance,height], center = true);
}
offset(delta = -(wall/2), chamfer = true) {
square([width+pcb_clearance,height], center = true);
}
}
// Draw the corners for the attachment holes
polygon(points=
[[-(width/2)+fillet,(height/2)],
[-(width/2),(height/2)-fillet],
[-(width/2),(height/2)]]
);
polygon(points=
[[(width/2)-fillet,-(height/2)],
[(width/2),-(height/2)+fillet],
[(width/2),-(height/2)]]
);
polygon(points=
[[(width/2)-fillet,(height/2)],
[(width/2),(height/2)-fillet],
[(width/2),(height/2)]]
);
polygon(points=
[[-(width/2)+fillet,-(height/2)],
[-(width/2),-(height/2)+fillet],
[-(width/2),-(height/2)]]
);
}
// Drill the holes for the attachment points, size depends on type
if (attachment_type == "hotinsert")
drill_holes(hole+hot_insert_clearance, length+(wall*3));
else if (attachment_type == "undersize")
drill_holes(hole*hole_shrink, length+(wall*3));
else
drill_holes(hole, length+(wall*3));
// Carve out the inner ribs
if (rib_type == "inner")
make_ribs();
// Extrude the bottom board for later difference
if (bottom_board_cutout) {
translate([0,-(height/2-fillet-2),length/2])
rotate([90,0,0]) {
linear_extrude(pcb_height+pcb_clearance) {
square([width+pcb_clearance,length+pcb_clearance], center=true);
}
}
}
// Extrude the top board for later difference
if (top_board_cutout == "include") {
translate([0,(height/2-fillet-2),length/2])
rotate([90,0,0]) {
linear_extrude(pcb_height+pcb_clearance) {
square([width+pcb_clearance,length+pcb_clearance], center=true);
}
}
}
// Extrude the middle board for later difference
if (middle_board_cutout == "include") {
translate([0,0,length/2])
rotate([90,0,0]) {
linear_extrude(pcb_height+pcb_clearance) {
square([width+pcb_clearance,length+pcb_clearance], center=true);
}
}
}
// Remove the top if selected
if (top_cap == "exclude") {
translate([0,(height/2)+(wall/2)+1,length/2]) {
rotate([90,0,0]) {
linear_extrude(wall*2) {
square([width-(fillet*2.5),length], center=true);
}
}
}
rotate([90,0,180])
translate([(width/2)-fillet+1,length-3,(height/2)-0])
cylinder(10,hole*hole_shrink,hole*hole_shrink,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([(width/2)-fillet+1,3,(height/2)-0])
cylinder(10,hole*hole_shrink,hole*hole_shrink,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([-(width/2)+fillet-1,length-3,(height/2)-0])
cylinder(10,hole*hole_shrink,hole*hole_shrink,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([-(width/2)+fillet-1,3,(height/2)-0])
cylinder(10,hole*hole_shrink,hole*hole_shrink,true, $fn = 20, $fn = 20);
}
// Make holes feet if selected
if (feet == "hole") {
rotate([90,0,180])
translate([width/2-10,length-10,-(height/2)-0])
cylinder(5,hole,hole,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([-width/2+10,length-10,-(height/2)-wall])
cylinder(5,hole,hole,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([width/2-10,10,-(height/2)-wall])
cylinder(5,hole,hole,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([-width/2+10,10,-(height/2)-wall])
cylinder(5,hole,hole,true, $fn = 20, $fn = 20);
}
if (vents == "include") {
for (a =[0:4]) {
translate([-(width/5)+(a*(width/11)),10,height/3])
cube([2,10,length*.66]);
}
}
}
// Extrude ribs if selected
if (rib_type == "outer")
make_ribs();
}
color("gray")
if (end_caps == "include") {
translate([0,height*2.50,wall])
difference() {
translate([0,0,-wall])
linear_extrude(wall) {
offset(r = (wall/2)) {
square([width,height], center = true);
}
}
drill_holes(hole*through_factor, length+(wall*3));
if (case_type == "arduino") {
translate([width/2-5.5-9.8,-(height/2-fillet-2)+5.5,0])
cube(size = [13,11,10], center = true);
translate([-width/2+4.5+3.3,-(height/2-fillet-2)+5.5,0])
cube(size = [9.5,11,10], center = true);
}
}
translate([0,height*1.25,-length])
difference() {
translate([0,0,length])
linear_extrude(wall) {
offset(r = (wall/2)) {
square([width,height], center = true);
}
}
drill_holes(hole*through_factor, length+(wall*3));
}
}
if (top_cap == "exclude") {
translate([0,height*5.5,-height/2-wall/2])
rotate([90,0,0])
difference() {
translate([0,(height/2)+(wall)+1,length/2]) {
rotate([90,0,0]) {
linear_extrude(wall) {
square([width-2,length], center=true);
}
}
}
rotate([90,0,180])
translate([(width/2)-fillet+1,length-3,(height/2)-0])
cylinder(10,hole,hole*hole_shrink,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([(width/2)-fillet+1,3,(height/2)-0])
cylinder(10,hole,hole,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([-(width/2)+fillet-1,length-3,(height/2)-0])
cylinder(10,hole,hole,true, $fn = 20, $fn = 20);
rotate([90,0,180])
translate([-(width/2)+fillet-1,3,(height/2)-0])
cylinder(10,hole,hole,true, $fn = 20, $fn = 20);
}
}
module make_ribs() {
rib_count = height >= 40 ? 2 : 1;
if (rib_count > 0) {
for (a =[-rib_count:rib_count]) {
linear_extrude(length) {
translate([-(width/2)-wall/2,4*a,0])
circle(1, $fn = 5);
}
}
for (a =[-rib_count:rib_count]) {
linear_extrude(length) {
translate([(width/2)+wall/2,4*a,0])
rotate([0,0,35])
circle(1, $fn = 5);
}
}
}
}
module drill_holes(drill_size, drill_length) {
echo(drill_size);
translate([0,0,-wall]) {
linear_extrude(drill_length) {
translate([-(width/2)+fillet/4,(height/2)-fillet/4,0])
circle(drill_size, $fn = 20);
}
linear_extrude(drill_length) {
translate([(width/2)-fillet/4,(height/2)-fillet/4,0])
circle(drill_size, $fn = 20);
}
linear_extrude(drill_length) {
translate([(width/2)-fillet/4,-(height/2)+fillet/4,0])
circle(drill_size, $fn = 20);
}
linear_extrude(drill_length) {
translate([-(width/2)+fillet/4,-(height/2)+fillet/4,0])
circle(drill_size, $fn = 20);
}
}
}