====== 2023-09-26 - 3D printing enclosures ====== [[https://vay.io|at work]] i recently did a short talk about designing enclosures for 3D printing. as usual [[https://www.youtube.com/watch?v=JNMgx_casLI|i use OpenSCAD]] for my designs. here are a couple of tricks that can be used to make it more efficient. ===== mock ===== first and foremost -- make sure you have a mock/model of what you want to design around. just look at this example from [[wp>OpenSCAD]] team: {{:blog:2023:09:26:preview.jpg?400|preview mode in grey}} thanks to this u can use the mock, to make sure all the key dimensions do match between enclosure and thing u design. ===== calipers ===== typical theme around custom enclosures is that you do them for custom electronics. :) in it's simplest form you can just measure a couple of key dimensions: PCB's outer size, holes, board height, highest elements (eg. capacitors), etc... here's an example mock i did last week for one such cases: {{:blog:2023:09:26:custom_electronics.png?400|custom electronics mock}} while it visually looks nothing alike a real PCB, dimension-wise it totally does the job! enclosure built around it worked in the very 1st shot. job done! ===== the internet ===== another common case is doing some special design around a common part. this is where the internet comes in. need a RasPi model? turns out there are [[https://www.printables.com/model/252088-raspberry-pi-4b-models-and-template/files|detailed models of RasPi boards]] out there. just grab one, put into OpenSCAD and you're off to the races! {{:blog:2023:09:26:raspi.png?400|RasPi 4 model}} if you want, there even are models that put each hole and each resistor there. sky is the limit! :) ===== 3D scanning ===== [[https://www.youtube.com/watch?v=g41Kyl4Zp8w|3D scanner can also be used to scan template]] element, or environment design should match. provided that you have scanner that's decent enough, of course. if you want PCB with holes +-1mm is not good enough, though. ===== 2D scanning ===== for things that are flat, you can also use flatbed 2D scanner, to digitize. case in point -- [[https://github.com/el-bart/mini/tree/master/sorting_box_fix|sorting box fix]] for my son. broken surface plate needed replacement, but i did not want to go through the hassle of betting each and every dimension right. instead i've put together broken part on scanner, scanned it, cleaned up and binarized with [[wp>GIMP]], and vectorized with [[wp>Inkscape]]. final product i was able to pull into OpenSCAD, scale and [[https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#linear_extrude|linear_extrude()]] into a proper, 3D element. again - printed and worked fine in 1st shot. {{:blog:2023:09:26:template.png?200|sorting box cover template}} ===== KiCad ===== now last but not least -- if you design custom PCB with [[wp>KiCad]], there's an option to visualize PCB in 3D. {{:blog:2023:09:26:kicad_3d.png?400|KiCad 3D visualization of PCB}} and btw: if you see PCB but no elements on it, [[https://forum.kicad.info/t/solved-kicad-6-0-all-the-3d-models-are-not-loaded/32664|make sure KISYS3DMOD path variable is set correctly]]. as an example i can use [[:blog:2022:08:21:2022-08-21_-_toy_satellite_project|toy satellite project]] i made for my sons some time ago. using [[https://github.com/el-bart/kicad_sdk|dockerized KiCad SDK]] ([[:blog:2022:08:27:2022-08-27_-_kicad_sdk|see blog post]]) STL can be exported automatically from a PCB design: {{:blog:2023:09:26:pcb_stl.png?400|toy satellite PCB in STL format}} and then used as a mock directly, greatly simplifying things. :) {{:blog:2023:09:26:toy_satellite_preview.png?400|preview of enclosure with board inside}}