Skip to content

Instantly share code, notes, and snippets.

@unixbigot
Created May 5, 2024 02:42
Show Gist options
  • Save unixbigot/7cea02228c81fd7b37bf3d0b65a5f68a to your computer and use it in GitHub Desktop.
Save unixbigot/7cea02228c81fd7b37bf3d0b65a5f68a to your computer and use it in GitHub Desktop.
an openscad file to generate a 2d cutting template for use by CNC operators
// Layout for a control panel consisting of a number of
// identical circuit boards laid out in a grid.
//
// variables which can be twiddled in this file or using the "customizer" panel
// Hit F6 to do the 'render' operation after any changes
output = "3d"; // [3d, 2d]
/* [Module Size] */
pcb_length = 68.2;
pcb_width = 38.8;
hole_sep_x = 61;
hole_sep_y= 33;
margin_left = 15;
margin_right = 15;
margin_top = 10;
margin_bottom = 10;
/* [Wiring hole location and size] */
wire_margin = 8;
switch_margin = 8;
panel_drill = 3.5;
switch_drill = 11;
cable_drill = 6;
/* [Panel size] */
panel_cols = 2;
panel_rows = 4;
panel_thickness = 6;
/* [Hidden] */
// making holes a little longer than the material makes preview look better
fuz=0.01; fuzz=2*fuz;
// number of segments to use for circles
$fn=60;
// Modules (subroutines)
// one cell of the repeating layout
module pcb(col=0) {
cube([
margin_left+pcb_length+margin_right,
margin_bottom+pcb_width+margin_top,
panel_thickness
]);
}
// The negative space associated with one cell (subtracted from the solid geometry)
module pcb_drills(col=0) {
inset_x = (pcb_length-hole_sep_x)/2;
inset_y = (pcb_width-hole_sep_y)/2;
// relief for pcb
translate([0,0,panel_thickness-1.6]) cube([pcb_length,pcb_width,1.6+fuz]);
// screw holes
translate([inset_x, inset_y, -fuz]) cylinder(d=panel_drill, h=panel_thickness+fuzz);
translate([pcb_length - inset_x, inset_y, -fuz]) cylinder(d=panel_drill, h=panel_thickness+fuzz);
translate([inset_x, pcb_width - inset_y, -fuz]) cylinder(d=panel_drill, h=panel_thickness+fuzz);
translate([pcb_length - inset_x, pcb_width-inset_y, -fuz]) cylinder(d=panel_drill, h=panel_thickness+fuzz);
// wire input
translate([-wire_margin, pcb_width-margin_top, -fuz]) cylinder(d=cable_drill, h=panel_thickness+fuzz);
// wire output
translate([pcb_length+wire_margin, pcb_width-margin_top, -fuz]) cylinder(d=cable_drill, h=panel_thickness+fuzz);
// swtich in alternate rows
if ((col % 2) == 0) {
translate([pcb_length+switch_margin, switch_margin, -fuz]) cylinder(d=switch_drill, h=panel_thickness+fuzz);
}
else {
translate([-switch_margin, switch_margin, -fuz]) cylinder(d=switch_drill, h=panel_thickness+fuzz);
}
}
// One column of the repeating layout
module column(col=0) {
cell_length = margin_left+pcb_length+margin_right;
cell_width = margin_bottom+pcb_width+margin_top;
for (i=[0:panel_rows-1]) {
translate([0, i * cell_width, 0]) pcb(col=col);
}
}
// Negative space for one column
module column_drills(col=0) {
for (i=[0:panel_rows-1]) {
translate([margin_left, margin_bottom+i*(margin_bottom+pcb_width+margin_top), 0]) pcb_drills(col=col);
}
}
// A panel consisting of repeading columns, each of several cells, with the
// holes then subtracted from the total (because some of the holes for a cell
// actualy protrude into neighbouring cells)
module panel() {
difference() {
for (i=[0:panel_cols-1]) {
translate([i*(margin_left+pcb_length+margin_right),0,0]) column(col=i);
}
for (i=[0:panel_cols-1]) {
translate([i*(margin_left+pcb_length+margin_right),0,0]) column_drills(col=i);
}
}
}
// Main render output
if (output == "3d") {
panel();
}
else {
projection() panel();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment