cpu_case.scad 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. SHOW_PLUNGERS = true;
  11. SHOW_BATTERY = true;
  12. EXPLODE = 65; // mm to pull lid out in Y- for inspection (try 40)
  13. /* [Board Dimensions — from EE04 STL] */
  14. PCB_L = 80.00; // board length (case_x axis)
  15. PCB_W = 41.22; // board width (case_y axis)
  16. PCB_T = 1.93; // PCB thickness
  17. // Component heights measured from PCB bottom face:
  18. COMP_MAX_Z = 7.29; // tallest component (XIAO module)
  19. COMP_SIDE_Z = 3.82; // tallest component on +Y wall (buttons, USB-C)
  20. /* [Cutout Positions — from STL geometry, PCB-origin-relative] */
  21. // ---- +Y wall: Sliding power switch ----
  22. // TODO: measure actual switch body dimensions from STL (as done for USB-C) before next print
  23. PWR_CX = 10.3; // PCB-relative case_x centre
  24. PWR_W = 5.0; // slot width
  25. PWR_H = 2.5; // slot height
  26. PWR_CZ = 3.8; // height above PCB bottom
  27. PWR_COVER_T = 0.6; // exterior skin over switch pocket (switch not user-accessible)
  28. // ---- +Y wall: USB-C port ----
  29. USBC_CX = 65.65;
  30. USBC_W = 9.0; // port body width from STL
  31. USBC_H = 3.22; // port body height from STL
  32. USBC_CZ = 4.31;
  33. USBC_CBL_CLEAR = 1.5; // added per side for cable plug + routing clearance
  34. // ---- Y- edge: FPC connector — notch in lid Y+ stop rib ----
  35. FPC_CX = 50.0; // PCB-relative case_x centre
  36. FPC_NOTCH_W = 20.0; // notch width for cable routing clearance
  37. FPC_U_T = 1.5; // U-rib arm and bar thickness
  38. FPC_U_DEPTH = 20.0; // how far Y- the U arms extend into the lid interior
  39. // ---- +Y wall: 3× user buttons + 1× reset ----
  40. BTN_CX = [48.4, 39.075, 29.725, 20.425]; // PCB-relative case_x centres
  41. BTN_D = 2.3; // HOLE_D from hat.scad: PLUNGER_D(2.0) + 2×SLIP_CLEAR(0.15)
  42. BTN_CZ = 3.85;
  43. /* [Plunger] */
  44. PLUNGER_D = 2.0; // body and head diameter — matches button actuator
  45. FLANGE_D = 2.9; // retention flange OD
  46. FLANGE_T = 1.2; // flange thickness (axial)
  47. PLUNGER_HEAD_H = 1.5; // exterior head protrusion past wall face
  48. /* [Case Parameters] */
  49. WALL = 2.0; // wall thickness
  50. FLOOR = 2.0; // base floor thickness (thicker for thread engagement)
  51. CORNER_R = 2.5; // XY corner fillet radius
  52. SCREW_D = 3.2; // M3 tap drill diameter
  53. BOSS_D = 6.0; // PCB standoff boss outer diameter
  54. BOSS_H = 2.0; // standoff boss height; PCB bottom sits flush on boss top
  55. /* [Locating Studs] */
  56. STUD_CLEAR = 0.10; // radial clearance per side — close (non-interference) fit in SLA resin
  57. STUD_H = PCB_T + 1.0; // stud cylinder height above boss top: through PCB + 1 mm proud
  58. STUD_R = (SCREW_D - 2*STUD_CLEAR) / 2; // stud pin radius (= cylinder + dome radius)
  59. /* [PCB Standoff Positions — relative to PCB origin] */
  60. PCB_BOSS_X1 = 2.5;
  61. PCB_BOSS_X2 = PCB_L - 2.5;
  62. PCB_BOSS_Y1 = 2.5;
  63. PCB_BOSS_Y2 = PCB_W - 2.5;
  64. /* [Interior Clearances — PCB edge to interior wall face] */
  65. CLR_XN = 2.0; // X- side
  66. CLR_XP = 42.0; // X+ side (JST cable routing)
  67. CLR_YN = 15.0; // Y- side (FPC routing; lid inserts from here)
  68. CLR_YP = 1.77; // Y+ side: calibrated contact(1.565) + rest clearance(0.20)
  69. CLR_LID = 5.0; // from tallest component top to lid underside
  70. BATT_W = 34.5; // 603449 LiPo width (X)
  71. BATT_D = 51.0; // 603449 LiPo depth (Y)
  72. BATT_T = 6.3; // 603449 LiPo thickness (Z)
  73. CLR_BATX = 1.5; // battery X clearance from X+ wall
  74. CLR_BATY = 1.5; // battery Y clearance from Y+ wall
  75. /* [Sliding Lid] */
  76. LID_T = 1.5; // lid ceiling thickness
  77. FLANGE_H = 3.0; // Z height of retention flanges (base + lid); drives lid placement and Y- wall step
  78. FLANGE_W = FLANGE_H * tan(30); // flange width — 30° from vertical (60° from horizontal), printable without support
  79. SLIDE_CLEAR = 0.40; // clearance between flange/rib and groove/channel on all mating faces (0.4 mm suits typical FDM tolerances)
  80. /* [Computed] */
  81. PCB_Z = FLOOR + BOSS_H;
  82. // Base inner height: floor to lid underside ≈ BASE_H (flange rests on groove floor)
  83. BASE_INNER_H = BOSS_H + COMP_MAX_Z + CLR_LID;
  84. BASE_H = FLOOR + BASE_INNER_H;
  85. PCB_OX = WALL + CLR_XN;
  86. PCB_OY = WALL + CLR_YN;
  87. CAV_L = CLR_XN + PCB_L + CLR_XP;
  88. CAV_W = CLR_YN + PCB_W + CLR_YP;
  89. OUT_L = CAV_L + 2*WALL;
  90. OUT_W = CAV_W + 2*WALL;
  91. LID_H = FLANGE_H + LID_T;
  92. LID_Y_LEN = CAV_W; // flange length; lid Y+ end stops against Y+ interior wall
  93. // ============================================================
  94. // HELPERS
  95. // ============================================================
  96. module rounded_box(l, w, h, r) {
  97. hull()
  98. for (dx = [r, l-r], dy = [r, w-r])
  99. translate([dx, dy, 0]) cylinder(r=r, h=h, $fn=32);
  100. }
  101. // Standoff boss: screw variant has through-hole; stud variant has locating pin instead.
  102. // Diagonal (X1,Y1)+(X2,Y2) → studs; (X1,Y2)+(X2,Y1) → screws.
  103. module pcb_boss(px, py, stud=false) {
  104. translate([PCB_OX + px, PCB_OY + py, FLOOR]) {
  105. difference() {
  106. cylinder(d=BOSS_D, h=BOSS_H + 0.01, $fn=24);
  107. if (!stud)
  108. translate([0, 0, -0.1])
  109. cylinder(d=SCREW_D * 0.7, h=BOSS_H + 0.2, $fn=18);
  110. }
  111. if (stud)
  112. translate([0, 0, BOSS_H]) {
  113. cylinder(r=STUD_R, h=STUD_H, $fn=24);
  114. translate([0, 0, STUD_H])
  115. sphere(r=STUD_R, $fn=24);
  116. }
  117. }
  118. }
  119. // Button plunger — origin at hole centre on the interior wall face.
  120. // At rest: flange flush with interior face, head proud of exterior face.
  121. module plunger() {
  122. color("orange") union() {
  123. translate([0, -FLANGE_T, 0])
  124. rotate([-90, 0, 0])
  125. cylinder(d = PLUNGER_D, h = FLANGE_T + WALL + PLUNGER_HEAD_H, $fn = 32);
  126. translate([0, -FLANGE_T, 0])
  127. rotate([-90, 0, 0])
  128. cylinder(d = FLANGE_D, h = FLANGE_T, $fn = 32);
  129. translate([0, WALL, 0])
  130. rotate([-90, 0, 0])
  131. cylinder(d = PLUNGER_D, h = PLUNGER_HEAD_H, $fn = 32);
  132. }
  133. }
  134. // ============================================================
  135. // BASE
  136. // ============================================================
  137. module base() {
  138. color("#004B49") {
  139. difference() {
  140. rounded_box(OUT_L, OUT_W, BASE_H, CORNER_R);
  141. // Interior cavity (open top)
  142. translate([WALL, WALL, FLOOR])
  143. cube([CAV_L, CAV_W, BASE_H]);
  144. // ---- Boss screw holes through 50 % of floor (screw diagonal only) ----
  145. for (pos = [[PCB_BOSS_X1, PCB_BOSS_Y2], [PCB_BOSS_X2, PCB_BOSS_Y1]])
  146. translate([PCB_OX + pos[0], PCB_OY + pos[1], FLOOR * 0.5 - 0.1])
  147. cylinder(d=SCREW_D * 0.7, h=FLOOR * 0.5 + 0.2, $fn=18);
  148. // ---- +Y wall cutouts ----
  149. // Sliding power switch pocket — closed exterior face, interior clearance only
  150. translate([PCB_OX + PWR_CX - PWR_W/2,
  151. OUT_W - WALL - 0.1,
  152. PCB_Z + PWR_CZ - PWR_H/2])
  153. cube([PWR_W, WALL - PWR_COVER_T + 0.1, PWR_H]);
  154. // USB-C slot
  155. translate([PCB_OX + USBC_CX - (USBC_W + 2*USBC_CBL_CLEAR)/2,
  156. OUT_W - WALL - 0.1,
  157. PCB_Z + USBC_CZ - (USBC_H + 2*USBC_CBL_CLEAR)/2])
  158. cube([USBC_W + 2*USBC_CBL_CLEAR, WALL + 0.2, USBC_H + 2*USBC_CBL_CLEAR]);
  159. // 4× button holes (3 user + 1 reset)
  160. for (bcx = BTN_CX)
  161. translate([PCB_OX + bcx,
  162. OUT_W + 0.1,
  163. PCB_Z + BTN_CZ])
  164. rotate([90, 0, 0])
  165. cylinder(d=BTN_D, h=WALL + 0.3, $fn=32);
  166. // ---- Y- wall step for lid flange clearance ----
  167. // Remove the full Y- wall above z=BASE_H-FLANGE_H-SLIDE_CLEAR so the lid
  168. // flanges can enter freely from Y-.
  169. translate([-0.1, -0.1, BASE_H - FLANGE_H - SLIDE_CLEAR])
  170. cube([OUT_L + 0.2, WALL + 0.2, FLANGE_H + SLIDE_CLEAR + 0.1]);
  171. }
  172. // Standoff bosses (added outside diff so cavity doesn't subtract them)
  173. pcb_boss(PCB_BOSS_X1, PCB_BOSS_Y1, stud=true); // stud diagonal
  174. pcb_boss(PCB_BOSS_X2, PCB_BOSS_Y2, stud=true); // stud diagonal
  175. pcb_boss(PCB_BOSS_X1, PCB_BOSS_Y2, stud=false); // screw diagonal
  176. pcb_boss(PCB_BOSS_X2, PCB_BOSS_Y1, stud=false); // screw diagonal
  177. }
  178. // Lid-retention flanges — right triangles, wide face flush with case top (z=BASE_H),
  179. // tip pointing down to (WALL, BASE_H-FLANGE_H). Hypotenuse faces down-into-cavity;
  180. // lid flanges slide underneath it for Z retention.
  181. color("#2C3863") {
  182. hull() {
  183. translate([WALL, WALL, BASE_H - 0.01])
  184. cube([FLANGE_W, CAV_W, 0.01]);
  185. translate([WALL, WALL, BASE_H - FLANGE_H])
  186. cube([0.01, CAV_W, 0.01]);
  187. }
  188. hull() {
  189. translate([OUT_L - WALL - FLANGE_W, WALL, BASE_H - 0.01])
  190. cube([FLANGE_W, CAV_W, 0.01]);
  191. translate([OUT_L - WALL - 0.01, WALL, BASE_H - FLANGE_H])
  192. cube([0.01, CAV_W, 0.01]);
  193. }
  194. }
  195. }
  196. // ============================================================
  197. // LID (slide-on; enters from Y- face, closes toward Y+)
  198. // Print upside-down (ceiling on build plate).
  199. // z=0 = bottom of flanges; z=FLANGE_H = ceiling underside.
  200. // Flanges sit inside cavity and ride on base retention flange hypotenuses.
  201. // ============================================================
  202. module lid() {
  203. // Flanges: right triangles in XZ; hypotenuse at reciprocal angle to base retention flanges.
  204. // Wide vertical face at x=WALL+FLANGE_W (inner), tip at bottom-wall-face — same
  205. // (-FLANGE_W, -FLANGE_H) hypotenuse slope as base flanges so they mate when lid slides in.
  206. color("#2C3863") {
  207. // Left (X-) flange
  208. hull() {
  209. translate([WALL + FLANGE_W - SLIDE_CLEAR - 0.01, 0, 0])
  210. cube([0.01, LID_Y_LEN, FLANGE_H - SLIDE_CLEAR]);
  211. translate([WALL + SLIDE_CLEAR, 0, -0.005])
  212. cube([0.01, LID_Y_LEN, 0.01]);
  213. }
  214. // Right (X+) flange
  215. hull() {
  216. translate([OUT_L - WALL - FLANGE_W + SLIDE_CLEAR, 0, 0])
  217. cube([0.01, LID_Y_LEN, FLANGE_H - SLIDE_CLEAR]);
  218. translate([OUT_L - WALL - SLIDE_CLEAR - 0.01, 0, -0.005])
  219. cube([0.01, LID_Y_LEN, 0.01]);
  220. }
  221. // Interior ribs — 2 mm wide, on cavity face of each flange
  222. translate([WALL + FLANGE_W - SLIDE_CLEAR, 0, 0])
  223. cube([2.0, LID_Y_LEN, FLANGE_H]);
  224. translate([OUT_L - WALL - FLANGE_W + SLIDE_CLEAR - 2.0, 0, 0])
  225. cube([2.0, LID_Y_LEN, FLANGE_H]);
  226. // Y+ stop rib — split around FPC cable notch at PCB_OX+FPC_CX
  227. translate([WALL + FLANGE_W - SLIDE_CLEAR + 2.0, LID_Y_LEN - 3, FLANGE_H - 3])
  228. cube([PCB_OX + FPC_CX - FPC_NOTCH_W/2 - (WALL + FLANGE_W - SLIDE_CLEAR + 2.0), 3, 3]);
  229. translate([PCB_OX + FPC_CX + FPC_NOTCH_W/2, LID_Y_LEN - 3, FLANGE_H - 3])
  230. cube([OUT_L - WALL - FLANGE_W + SLIDE_CLEAR - 2.0 - (PCB_OX + FPC_CX + FPC_NOTCH_W/2), 3, 3]);
  231. // U-rib bridging the notch — arms outside gap edges, bar closing Y- end
  232. // Left arm
  233. translate([PCB_OX + FPC_CX - FPC_NOTCH_W/2 - FPC_U_T, LID_Y_LEN - 3 - FPC_U_DEPTH, FLANGE_H - 3])
  234. cube([FPC_U_T, FPC_U_DEPTH, 3]);
  235. // Right arm
  236. translate([PCB_OX + FPC_CX + FPC_NOTCH_W/2, LID_Y_LEN - 3 - FPC_U_DEPTH, FLANGE_H - 3])
  237. cube([FPC_U_T, FPC_U_DEPTH, 3]);
  238. // Bottom bar
  239. translate([PCB_OX + FPC_CX - FPC_NOTCH_W/2 - FPC_U_T, LID_Y_LEN - 3 - FPC_U_DEPTH, FLANGE_H - 3])
  240. cube([FPC_NOTCH_W + 2*FPC_U_T, FPC_U_T, 3]);
  241. }
  242. color("#004B49")
  243. difference() {
  244. union() {
  245. // Ceiling plate — matches base footprint (OUT_L × OUT_W) with CORNER_R rounding
  246. translate([0, -WALL, FLANGE_H])
  247. rounded_box(OUT_L, OUT_W, LID_T, CORNER_R);
  248. // Y- lip — same rounded_box profile clipped to the Y- wall zone so the
  249. // lip corners match the base exterior corners
  250. intersection() {
  251. translate([0, -WALL, -SLIDE_CLEAR])
  252. rounded_box(OUT_L, OUT_W, FLANGE_H + SLIDE_CLEAR, CORNER_R);
  253. translate([-0.1, -WALL - 0.1, -SLIDE_CLEAR - 0.1])
  254. cube([OUT_L + 0.2, WALL + 0.2, FLANGE_H + SLIDE_CLEAR + 0.2]);
  255. }
  256. }
  257. // FPC cable slot — from Y+ face of U-rib bottom bar, 3 mm toward Y+
  258. translate([PCB_OX + FPC_CX - FPC_NOTCH_W/2,
  259. LID_Y_LEN - 3 - FPC_U_DEPTH + FPC_U_T,
  260. FLANGE_H - 0.1])
  261. cube([FPC_NOTCH_W, 3, LID_T + 0.2]);
  262. }
  263. }
  264. // ============================================================
  265. // BOARD PLACEMENT
  266. // EE04() XY-normalises the STL (board left/front at origin).
  267. // +1.925 corrects for STL native Z (PCB bottom at Z=−1.925) so
  268. // the PCB bottom face lands exactly at PCB_Z.
  269. // ============================================================
  270. module stl_board() {
  271. translate([PCB_OX, PCB_OY, PCB_Z])
  272. EE04();
  273. }
  274. module battery() {
  275. translate([CAV_L - BATT_W - CLR_BATX,
  276. CAV_W - BATT_D - CLR_BATY,
  277. FLOOR])
  278. cube([BATT_W, BATT_D, BATT_T]);
  279. }
  280. // ============================================================
  281. // ASSEMBLY
  282. // ============================================================
  283. if (SHOW_BASE) base();
  284. if (SHOW_BATTERY) battery();
  285. if (SHOW_LID)
  286. translate([0,
  287. WALL - EXPLODE,
  288. BASE_H - FLANGE_H])
  289. lid();
  290. if (SHOW_BOARD) stl_board();
  291. if (SHOW_PLUNGERS)
  292. for (bcx = BTN_CX)
  293. translate([PCB_OX + bcx, OUT_W - WALL, PCB_Z + BTN_CZ])
  294. plunger();