cpu_case.scad 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // ============================================================
  2. // XIAO ePaper Display Board EE04 — 3D-Printed Case
  3. // OpenSCAD parametric model
  4. // ============================================================
  5. use <ee04.scad>
  6. /* [Preview] */
  7. SHOW_BOARD = true;
  8. SHOW_LID = true;
  9. SHOW_BASE = true;
  10. EXPLODE = 65; // mm to pull lid out in Y- for inspection (try 40)
  11. /* [Board Dimensions — from EE04 STL] */
  12. PCB_L = 80.00; // board length (case_x axis)
  13. PCB_W = 41.22; // board width (case_y axis)
  14. PCB_T = 1.93; // PCB thickness
  15. // Component heights measured from PCB bottom face:
  16. COMP_MAX_Z = 7.29; // tallest component (XIAO module)
  17. COMP_SIDE_Z = 3.82; // tallest component on +Y wall (buttons, USB-C)
  18. /* [Cutout Positions — from STL geometry, PCB-origin-relative] */
  19. // ---- +Y wall: Sliding power switch ----
  20. PWR_CX = 10.3; // PCB-relative case_x centre
  21. PWR_W = 5.0; // slot width
  22. PWR_H = 2.5; // slot height
  23. PWR_CZ = 3.8; // height above PCB bottom
  24. // ---- +Y wall: USB-C port ----
  25. USBC_CX = 65.65;
  26. USBC_W = 11.5;
  27. USBC_H = 4.8;
  28. USBC_CZ = 4.4;
  29. // ---- +Y wall: 3× user buttons + 1× reset ----
  30. BTN_CX = [48.4, 39.1, 29.8, 20.4]; // PCB-relative case_x centres
  31. BTN_D = 4.5;
  32. BTN_CZ = 3.7;
  33. /* [Case Parameters] */
  34. WALL = 2.0; // wall thickness
  35. FLOOR = 2.0; // base floor thickness (thicker for thread engagement)
  36. CORNER_R = 2.5; // XY corner fillet radius
  37. SCREW_D = 3.2; // M3 tap drill diameter
  38. BOSS_D = 6.0; // PCB standoff boss outer diameter
  39. BOSS_H = 2.0; // standoff boss height; PCB bottom sits flush on boss top
  40. /* [Locating Studs] */
  41. STUD_CLEAR = 0.10; // radial clearance per side — close (non-interference) fit in SLA resin
  42. STUD_H = PCB_T + 1.0; // stud height above boss top: through PCB + 1 mm proud
  43. /* [PCB Standoff Positions — relative to PCB origin] */
  44. PCB_BOSS_X1 = 2.5;
  45. PCB_BOSS_X2 = PCB_L - 2.5;
  46. PCB_BOSS_Y1 = 2.5;
  47. PCB_BOSS_Y2 = PCB_W - 2.5;
  48. /* [Interior Clearances — PCB edge to interior wall face] */
  49. CLR_XN = 5.0; // X- side
  50. CLR_XP = 15.0; // X+ side (JST cable routing)
  51. CLR_YN = 15.0; // Y- side (FPC routing; lid inserts from here)
  52. CLR_YP = 0.5; // Y+ side (snug against button/USB-C wall)
  53. CLR_LID = 5.0; // from tallest component top to lid underside
  54. /* [Sliding Lid] */
  55. LID_T = 1.5; // lid ceiling thickness
  56. FLANGE_H = 3.0; // Z height of retention flanges (base + lid); drives lid placement and Y- wall step
  57. FLANGE_W = FLANGE_H * tan(30); // flange width — 30° from vertical (60° from horizontal), printable without support
  58. SLIDE_CLEAR = 0.40; // clearance between flange/rib and groove/channel on all mating faces (0.4 mm suits typical FDM tolerances)
  59. /* [Computed] */
  60. PCB_Z = FLOOR + BOSS_H;
  61. // Base inner height: floor to lid underside ≈ BASE_H (flange rests on groove floor)
  62. BASE_INNER_H = BOSS_H + COMP_MAX_Z + CLR_LID;
  63. BASE_H = FLOOR + BASE_INNER_H;
  64. PCB_OX = WALL + CLR_XN;
  65. PCB_OY = WALL + CLR_YN;
  66. CAV_L = CLR_XN + PCB_L + CLR_XP;
  67. CAV_W = CLR_YN + PCB_W + CLR_YP;
  68. OUT_L = CAV_L + 2*WALL;
  69. OUT_W = CAV_W + 2*WALL;
  70. LID_H = FLANGE_H + LID_T;
  71. LID_Y_LEN = CAV_W; // flange length; lid Y+ end stops against Y+ interior wall
  72. // ============================================================
  73. // HELPERS
  74. // ============================================================
  75. module rounded_box(l, w, h, r) {
  76. hull()
  77. for (dx = [r, l-r], dy = [r, w-r])
  78. translate([dx, dy, 0]) cylinder(r=r, h=h, $fn=32);
  79. }
  80. // Standoff boss: screw variant has through-hole; stud variant has locating pin instead.
  81. // Diagonal (X1,Y1)+(X2,Y2) → studs; (X1,Y2)+(X2,Y1) → screws.
  82. module pcb_boss(px, py, stud=false) {
  83. translate([PCB_OX + px, PCB_OY + py, FLOOR]) {
  84. difference() {
  85. cylinder(d=BOSS_D, h=BOSS_H + 0.01, $fn=24);
  86. if (!stud)
  87. translate([0, 0, -0.1])
  88. cylinder(d=SCREW_D * 0.7, h=BOSS_H + 0.2, $fn=18);
  89. }
  90. if (stud)
  91. translate([0, 0, BOSS_H])
  92. cylinder(d=SCREW_D - 2*STUD_CLEAR, h=STUD_H, $fn=24);
  93. }
  94. }
  95. // ============================================================
  96. // BASE
  97. // ============================================================
  98. module base() {
  99. color("#004B49") {
  100. difference() {
  101. rounded_box(OUT_L, OUT_W, BASE_H, CORNER_R);
  102. // Interior cavity (open top)
  103. translate([WALL, WALL, FLOOR])
  104. cube([CAV_L, CAV_W, BASE_H]);
  105. // ---- Boss screw holes through 50 % of floor (screw diagonal only) ----
  106. for (pos = [[PCB_BOSS_X1, PCB_BOSS_Y2], [PCB_BOSS_X2, PCB_BOSS_Y1]])
  107. translate([PCB_OX + pos[0], PCB_OY + pos[1], FLOOR * 0.5 - 0.1])
  108. cylinder(d=SCREW_D * 0.7, h=FLOOR * 0.5 + 0.2, $fn=18);
  109. // ---- +Y wall cutouts ----
  110. // Sliding power switch slot
  111. translate([PCB_OX + PWR_CX - PWR_W/2,
  112. OUT_W - WALL - 0.1,
  113. PCB_Z + PWR_CZ - PWR_H/2])
  114. cube([PWR_W, WALL + 0.2, PWR_H]);
  115. // USB-C slot
  116. translate([PCB_OX + USBC_CX - USBC_W/2,
  117. OUT_W - WALL - 0.1,
  118. PCB_Z + USBC_CZ - USBC_H/2])
  119. cube([USBC_W, WALL + 0.2, USBC_H]);
  120. // 4× button holes (3 user + 1 reset)
  121. for (bcx = BTN_CX)
  122. translate([PCB_OX + bcx,
  123. OUT_W + 0.1,
  124. PCB_Z + BTN_CZ])
  125. rotate([90, 0, 0])
  126. cylinder(d=BTN_D, h=WALL + 0.3, $fn=32);
  127. // ---- Y- wall step for lid flange clearance ----
  128. // Remove the full Y- wall above z=BASE_H-FLANGE_H-SLIDE_CLEAR so the lid
  129. // flanges can enter freely from Y-.
  130. translate([-0.1, -0.1, BASE_H - FLANGE_H - SLIDE_CLEAR])
  131. cube([OUT_L + 0.2, WALL + 0.2, FLANGE_H + SLIDE_CLEAR + 0.1]);
  132. }
  133. // Standoff bosses (added outside diff so cavity doesn't subtract them)
  134. pcb_boss(PCB_BOSS_X1, PCB_BOSS_Y1, stud=true); // stud diagonal
  135. pcb_boss(PCB_BOSS_X2, PCB_BOSS_Y2, stud=true); // stud diagonal
  136. pcb_boss(PCB_BOSS_X1, PCB_BOSS_Y2, stud=false); // screw diagonal
  137. pcb_boss(PCB_BOSS_X2, PCB_BOSS_Y1, stud=false); // screw diagonal
  138. }
  139. // Lid-retention flanges — right triangles, wide face flush with case top (z=BASE_H),
  140. // tip pointing down to (WALL, BASE_H-FLANGE_H). Hypotenuse faces down-into-cavity;
  141. // lid flanges slide underneath it for Z retention.
  142. color("#2C3863") {
  143. hull() {
  144. translate([WALL, WALL, BASE_H - 0.01])
  145. cube([FLANGE_W, CAV_W, 0.01]);
  146. translate([WALL, WALL, BASE_H - FLANGE_H])
  147. cube([0.01, CAV_W, 0.01]);
  148. }
  149. hull() {
  150. translate([OUT_L - WALL - FLANGE_W, WALL, BASE_H - 0.01])
  151. cube([FLANGE_W, CAV_W, 0.01]);
  152. translate([OUT_L - WALL - 0.01, WALL, BASE_H - FLANGE_H])
  153. cube([0.01, CAV_W, 0.01]);
  154. }
  155. }
  156. }
  157. // ============================================================
  158. // LID (slide-on; enters from Y- face, closes toward Y+)
  159. // Print upside-down (ceiling on build plate).
  160. // z=0 = bottom of flanges; z=FLANGE_H = ceiling underside.
  161. // Flanges sit inside cavity and ride on base retention flange hypotenuses.
  162. // ============================================================
  163. module lid() {
  164. // Flanges: right triangles in XZ; hypotenuse at reciprocal angle to base retention flanges.
  165. // Wide vertical face at x=WALL+FLANGE_W (inner), tip at bottom-wall-face — same
  166. // (-FLANGE_W, -FLANGE_H) hypotenuse slope as base flanges so they mate when lid slides in.
  167. color("#2C3863") {
  168. // Left (X-) flange
  169. hull() {
  170. translate([WALL + FLANGE_W - SLIDE_CLEAR - 0.01, 0, 0])
  171. cube([0.01, LID_Y_LEN, FLANGE_H - SLIDE_CLEAR]);
  172. translate([WALL + SLIDE_CLEAR, 0, -0.005])
  173. cube([0.01, LID_Y_LEN, 0.01]);
  174. }
  175. // Right (X+) flange
  176. hull() {
  177. translate([OUT_L - WALL - FLANGE_W + SLIDE_CLEAR, 0, 0])
  178. cube([0.01, LID_Y_LEN, FLANGE_H - SLIDE_CLEAR]);
  179. translate([OUT_L - WALL - SLIDE_CLEAR - 0.01, 0, -0.005])
  180. cube([0.01, LID_Y_LEN, 0.01]);
  181. }
  182. // Interior ribs — 2 mm wide, on cavity face of each flange
  183. translate([WALL + FLANGE_W - SLIDE_CLEAR, 0, 0])
  184. cube([2.0, LID_Y_LEN, FLANGE_H]);
  185. translate([OUT_L - WALL - FLANGE_W + SLIDE_CLEAR - 2.0, 0, 0])
  186. cube([2.0, LID_Y_LEN, FLANGE_H]);
  187. // Y+ stop tabs — two 10 mm tabs at 1/3 and 2/3 of OUT_L, press against Y+ interior wall
  188. translate([OUT_L/4 - 5, LID_Y_LEN - 3, FLANGE_H - 3])
  189. cube([10, 3, 3]);
  190. translate([3*OUT_L/4 - 5, LID_Y_LEN - 3, FLANGE_H - 3])
  191. cube([10, 3, 3]);
  192. }
  193. color("#004B49") {
  194. // Ceiling plate — matches base footprint (OUT_L × OUT_W) with CORNER_R rounding
  195. translate([0, -WALL, FLANGE_H])
  196. rounded_box(OUT_L, OUT_W, LID_T, CORNER_R);
  197. // Y- lip — same rounded_box profile clipped to the Y- wall zone so the
  198. // lip corners match the base exterior corners
  199. intersection() {
  200. translate([0, -WALL, -SLIDE_CLEAR])
  201. rounded_box(OUT_L, OUT_W, FLANGE_H + SLIDE_CLEAR, CORNER_R);
  202. translate([-0.1, -WALL - 0.1, -SLIDE_CLEAR - 0.1])
  203. cube([OUT_L + 0.2, WALL + 0.2, FLANGE_H + SLIDE_CLEAR + 0.2]);
  204. }
  205. }
  206. }
  207. // ============================================================
  208. // BOARD PLACEMENT
  209. // EE04() XY-normalises the STL (board left/front at origin).
  210. // +1.925 corrects for STL native Z (PCB bottom at Z=−1.925) so
  211. // the PCB bottom face lands exactly at PCB_Z.
  212. // ============================================================
  213. module stl_board() {
  214. translate([PCB_OX, PCB_OY, PCB_Z])
  215. EE04();
  216. }
  217. // ============================================================
  218. // ASSEMBLY
  219. // ============================================================
  220. if (SHOW_BASE) base();
  221. if (SHOW_LID)
  222. translate([0,
  223. WALL - EXPLODE,
  224. BASE_H - FLANGE_H])
  225. lid();
  226. if (SHOW_BOARD) stl_board();