Kicad PCB fitment testing using 3D printing

For the T602-FSBoard project, it is crucial that I'm sure that the PCB will actually fit before I order anything. Any fitment and alignment mistakes will be very bad, because I will need to make a new board revision and that takes even more time and money.

So I had a thought: would it be possible to 3D print the whole PCB with all of its components to test if it would fit? The answer is yes, and it isn't difficult. Before we begin, we need to be certain of a couple of things:

  • The 3D printer we want to use will actually fit the dimensions of the board (obviously).
  • All components on the board have a corresponding 3D model.
  • All 3D models are aligned on the board properly (e.g. not upside down) and this is tested with the 3D viewer.

Converting STEP to STL

KiCad can not export an STL directly that 3D printing slicers expect. So, to actually 3D print the PCB, follow these steps:

  1. Open your PCB in KiCad PCB editor.
  2. Export the board as a STEP file with File -> Export -> STEP....
    Next, we need to convert this non-meshed STEP file to a meshed 3D file:
  3. Install trimesh and gmsh (and their dependencies) on your system. (Arch: gmsh(aur) and trimsesh(aur))
  4. Copy this Python script into a Python file:
import trimesh, gmsh
import sys

if __name__ ==  "__main__":
    if "-i" not in sys.argv or "-o" not in sys.argv:
        print("Usage: {} -i <input> -o <output>".format(sys.argv[0]))
        exit(1)

    mesh = trimesh.Trimesh(**trimesh.interfaces.gmsh.load_gmsh(file_name = (sys.argv[sys.argv.index("-i")+1]), gmsh_args = [
        ("Mesh.Algorithm", 2),
        ("Mesh.CharacteristicLengthFromCurvature", 1),
        ("General.NumThreads", 4),
        ("Mesh.MinimumCirclePoints", 25)]))

    mesh.export(sys.argv[sys.argv.index("-o")+1])
  1. Run the Python script with the correct input and output parameters. Example:
python converter.py -i input.step -o output.stl

Printing

Now that we have the STL file, we can 3D print the PCB. For big PCBs, it will obviously take a long time (for me it took ~12 hours). This is because PCBs are too thin to have any infill. The PCB part will be printed with 100% infil. On my Ender 3 Pro, I used 10% infill and used Dynamic Quality in the Cura slicer.


386 Words

2024-03-22