cpu_case.scad 16 KB

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