Skip to content

Instantly share code, notes, and snippets.

@probonopd
Last active December 29, 2022 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save probonopd/5a3fa855498af0d3224c110723781efe to your computer and use it in GitHub Desktop.
Save probonopd/5a3fa855498af0d3224c110723781efe to your computer and use it in GitHub Desktop.

Simple Parametrized Snap-fit Enclosure for a PCB in Onshape

One killer application for 3D printing is building enclosures for electronics prototypes. Many hobbyists use tools like TinkerCAD to build simple project boxes that are held together using screws.

A more elegant solution is to use snapfit enclosures that consist of two parts that can be snapped together with a satisfying click and without the need for additional parts or tools. Depending on how these snap-fits are designed, pulling the parts apart can be very easy to next to impossible.

Key principles

  • The part must not be under stress after being snapped together. PLA slowly deforms over time if it is under pressure for a prolonged period of time. Hence avoid "friction fits" where to parts are joined simply due to the friction betwee them
  • Always use clearance, at least in x and y dimensions. 0.1mm for a well-tuned FDM printer to 0.2mm for larger nozzles and/or faster printing situations
  • Never type in any numbers for dimensions directly, always make a habit of using variables. This makes your design consistent and configurable
  • Remember three shortcuts that are huge time-savers in Onshape: s to bring up a context menu with the most commonly used tools next to the mouse pointer, n to rotate the workspace normal to the selected sketch or surface, and Alt+c to search for tools by name

Creating the 2-part box in Onshape

  1. Click "Create" and create a new document
  2. Create a Sketch by pressing s, clicking on the first icon, and clicking on the Top plane. Press n to make the view normal to that plane. Press r and draw a corner point rectangle by clicking on the center point, then dragging outward. Enter #x and press Enter to create a new variable called x. As the value, enter 40. Press Enter three times. Repeat for #y with value 30. Make sure the sketch is black; if it is blue, then something is unconstrained (random). Confirm the sketch with the green checkmark.
  3. Extrude by pressing s, clicking on the second icon, clicking on the rectangle. Enter #z with a value 20. Select "symmetric". Confirm with the green checkmark.
  4. Split the shape by pressing Alt+c, typing split, Enter, clicking on the body, clicking on "Entity to split with", clicking on the Top plane. Confirm with the green checkmark.
  5. Hide Part 2.
  6. Extrude the top face of the lower half by pressing s, clicking on the second icon, and clicking on the top surface of the lower half. Enter #shell*3 as the value for Depth, with #shell having the value of 0.8 (twice the nozzle size). Confirm with the green checkmark.
  7. Fillet all edges of the upper and the lower part by pressing s, clicking on the first icon in the lower row, and then each relevant edge. Unhide Part 1 to apply the fillets there, too. As the Radius enter #radius with a value of 2. Confirm with the green checkmark.
  8. Hide Part 2 again.
  9. Shell the part by pressing Alt+c, typing shell, Enter, clicking on the underside of the upper part, and entering #shell as the Shell Thickness. Confirm with the green checkmark.
  10. Create a Sketch by pressing s, clicking on the first icon, and clicking on the longer vertical inner side of the top part. Press n to make the view normal to that plane. Press r and draw a corner point rectangle by clicking on the center point of the bottom edge, then dragging outward. Enter #x/2 and press Enter. Enter #shell*4 and press Enter. Confirm with the green checkmark.
  11. Extrude the top one of the resulting rectangles by pressing s, clicking on the second icon, and clicking on the top rectangle. Select "New", check "Draft", Click on the rotation symbol so it changes to counter-clickwise, enter 45 for the degrees. Confirm with the green checkmark.
  12. Mirror the snap we just created by pressing Alt+c, typing mirror, Enter, clicking on the snap, clicking on "Mirror plane", cliking on the Front plane. Confirm with the green checkmark.
  13. Perform a Boolean operation by by pressing Alt+c, typing bool, Enter, clicking on "Subtract", clicking on the top part, clicking on "Targets", clicking on "Part 1" in the sidebar, checking "Offset", "Offset all", and "Keep tools". Enter #clearance under "Offset distance" with a value of 0.1. Confirm with the green checkmark.
  14. Hide Part 2, show Part 1 (the lower part).
  15. Shell the part by pressing Alt+c, typing shell, Enter, clicking on the top side of the lower part, and entering #shell as the Shell Thickness. Confirm with the green checkmark.
  16. Richt-click on the underside of the lower part, select "Section view..." and move the arrow a bit to the inside of the box so that you don't see the bottom shell anymore. Confirm with the green checkmark.
  17. Apply a Chamfer to the part that would be unprintable due to overhangs by pressing s, clicking on the second icon in the second row, and clicking on the edge betwee the wall and the overhanging surface. Unter "Distance" enter #shell+#clearance. Confirm with the green checkmark.
  18. Since we don't need the clearance in z direction, Extrude the outer section of the lower part by pressing s, clicking on the second icon, and clicking on the outer section of the lower part. Enter #clearance under "Depth". Confirm with the green checkmark.
  19. Apply a Chamfer to the outer side of the lip by pressing s, clicking on the second icon in the second row, and clicking on the outer side of the lip. Unter "Distance" enter #shell/2. Confirm with the green checkmark.

Done!

Fitting the PCB

Now, to bring a PCB into the box, switch to the "Assembly 1" tab and import a PCB, e.g., a NodeMCU board. Also bring in the two parts we created above. Join them together in a suitable way. The details of this still need to be written down.

Use "Edit in place" to adjust the enclosure until it fits the PCB perfectly. Don't forget to use #clearance.

Prior Art

@npike
Copy link

npike commented Dec 26, 2022

Great instructions, thank you! I printed this on an Ender 3v2 in PLA and the top fits fairly loosely to the bottom. Any suggestions for improving how tight the "snap" is?

@probonopd
Copy link
Author

Hello @npike. If it is loose in the sense that it can move when you shake it, you can reduce the clearance from e.g., 0.2 mm to 0.1 mm.

If you want it so that you need more force to pry the halves apart, you can either increase the dimensions of the snap and the hook by a factor of 1.5-2, or can change the angle from 45 degrees to approx. up to 33 degrees (depending on the printer).

The best settings depend on the kind of model you are making and may require some experimentation.

@npike
Copy link

npike commented Dec 29, 2022

33 degrees worked pretty well, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment