Guides design and generation of 3D-printable enclosures for Arduino/ESP32/RP2040 projects. Use when user needs a case, box, housing, or enclosure for their electronics project. Provides parametric design guidance, OpenSCAD templates, STL generation tips, and print settings.
Creates 3D-printable enclosures for electronics projects.
This skill includes bundled tools and templates:
Generate for specific PCB:
uv run --no-project scripts/generate_enclosure.py --pcb "Arduino Uno" --output uno_case.scad
uv run --no-project scripts/generate_enclosure.py --pcb "ESP32 DevKit" --output esp32_case.scad
Custom dimensions:
uv run --no-project scripts/generate_enclosure.py --width 100 --depth 60 --height 30 --output custom.scad
uv run --no-project scripts/generate_enclosure.py --interactive
List supported PCBs:
uv run --no-project scripts/generate_enclosure.py --list
Ask user for:
1. Main board dimensions (L × W × H in mm)
2. Component clearances (tallest component height)
3. Connectors/ports that need access (USB, power jack, etc.)
4. Mounting holes (positions, diameters)
5. Any displays, buttons, LEDs that need cutouts
6. Environment (indoor/outdoor, waterproof?)
Enclosure Type: [Box/Clamshell/Snap-fit/Screw-mount]
Material: [PLA/PETG/ABS]
Wall Thickness: [2-3mm typical]
Mounting Style: [Standoffs/Clips/Rails]
Ventilation: [None/Slots/Holes]
Access: [Top-remove/Front-panel/Side-openings]
Choose approach:
// === PARAMETRIC PROJECT BOX ===
// Customize these values for your project
// Internal dimensions (mm)
inner_length = 70; // X axis
inner_width = 50; // Y axis
inner_height = 30; // Z axis (internal depth)
// Wall and tolerances
wall = 2.5; // Wall thickness
lid_tolerance = 0.4; // Gap for lid fit
corner_radius = 3; // Rounded corners
// Mounting standoffs
standoff_height = 5; // PCB clearance from bottom
standoff_dia = 6; // Standoff outer diameter
screw_hole_dia = 2.5; // M2.5 screw hole
// PCB mounting hole positions (from corner)
// Measure from your board!
pcb_holes = [
[5, 5], // Bottom-left
[65, 5], // Bottom-right
[5, 45], // Top-left
[65, 45] // Top-right
];
// Lid attachment
lid_screw_dia = 3; // M3 screws
lid_screw_positions = [
[5, 5],
[inner_length-5, 5],
[5, inner_width-5],
[inner_length-5, inner_width-5]
];
// Cutouts (add as needed)
usb_cutout = true;
usb_x = 35; // Center position
usb_width = 12;
usb_height = 8;
// === MODULES ===
module rounded_box(l, w, h, r) {
hull() {
for (x = [r, l-r])
for (y = [r, w-r])
translate([x, y, 0])
cylinder(h=h, r=r, $fn=32);
}
}
module standoff(h, outer_d, inner_d) {
difference() {
cylinder(h=h, d=outer_d, $fn=24);
cylinder(h=h+1, d=inner_d, $fn=24);
}
}
module box_base() {
outer_l = inner_length + 2*wall;
outer_w = inner_width + 2*wall;
outer_h = inner_height + wall; // Bottom wall
difference() {
// Outer shell
rounded_box(outer_l, outer_w, outer_h, corner_radius);
// Inner cavity
translate([wall, wall, wall])
rounded_box(inner_length, inner_width, inner_height+1, corner_radius-wall);
// USB cutout
if (usb_cutout) {
translate([wall + usb_x - usb_width/2, -1, wall + standoff_height])
cube([usb_width, wall+2, usb_height]);
}
}
// Add standoffs
for (pos = pcb_holes) {
translate([wall + pos[0], wall + pos[1], wall])
standoff(standoff_height, standoff_dia, screw_hole_dia);
}
}
module box_lid() {
lid_wall = wall - lid_tolerance;
outer_l = inner_length + 2*wall;
outer_w = inner_width + 2*wall;
lip_h = 5; // How deep lid inserts
// Lid top
rounded_box(outer_l, outer_w, wall, corner_radius);
// Lid lip (inserts into box)
translate([wall + lid_tolerance, wall + lid_tolerance, -lip_h])
difference() {
rounded_box(inner_length - 2*lid_tolerance,
inner_width - 2*lid_tolerance,
lip_h, corner_radius - wall);
}
}
// === RENDER ===
// Uncomment one at a time for printing:
box_base();
// translate([0, inner_width + 20, 0]) box_lid();
// === CUTOUT LIBRARY ===
// Round hole (for buttons, LEDs)
module round_cutout(x, y, z, diameter, depth) {
translate([x, y, z])
rotate([90, 0, 0])
cylinder(h=depth, d=diameter, $fn=32);
}
// Rectangle (for displays, SD cards)
module rect_cutout(x, y, z, width, height, depth) {
translate([x - width/2, -0.1, z])
cube([width, depth + 0.2, height]);
}
// Slot (for ventilation, cables)
module slot_cutout(x, y, z, width, height, depth) {
translate([x, y, z])
hull() {
translate([0, 0, 0])
cylinder(h=depth, d=height, $fn=24);
translate([width-height, 0, 0])
cylinder(h=depth, d=height, $fn=24);
}
}
// OLED display cutout (128x64 module)
module oled_cutout() {
// Visible area
rect_cutout(inner_length/2, wall, inner_height - 15, 26, 14, wall+1);
// Mounting holes (if needed)
}
// Common connector dimensions
usb_micro = [8, 3]; // USB Micro
usb_c = [9, 3.5]; // USB-C
barrel_jack = [12, 12]; // 5.5mm DC jack (round)
sd_card = [15, 3]; // SD card slot