Creating a 3D model for Kicad
I recently built a project where a PCB was required. I’ve moved over from Eagle to KiCAD since Eagle changed their licensing. I’m not creating enough boards to justify a monthly subscription.
One of the cool features of KiCAD is the 3D viewer. Once you’ve created your schematic and converted it to a PCB you can choose View -> 3D Viewer and as long as you’ve got standard components then you’ll see a 3D model.
However, I had one component a the 32.768Khz AB38T crystal that was missing a 3D model.
I did a call out on Twitter, and Adrian McEwen came to my help with the suggestion of a plugin for FreeCAD. But whilst I was happy to give that a try I also managed to find a simple video from Chris Gamell from Contextual Electronics that suggested all you needed to do was add in the model in STEP format, a portable format for exchanging 3D models. The latest KiCAD also supports the VRML format and the above StepUp module does also support that.
I’m using 5.1 so it’s slightly different but nothing that caused me an issue.
Building the model
It is often possible to find the engineering models and drawings for components and in fact I found the crystal on Digikey. But I thought it might be more fun to build one from scratch. I started by measuring the key parts, I also measured the pad separation which was 1.9mm between centres.
Over in Fusion, I started with a simple cylinder, 3mm diameter and 8mm long. I added a small chamfer on the ends to make it look a bit nicer. To create the legs I first added a tangent plane alongside the cylinder. On this, I sketched the bent line that the pins needed to follow.
Next was to sketch a couple of 0.3mm diameter circles onto the end of the crystal. The sweep command combines those with the sketched line to form the bent pins.
Because the pins were 1.8mm apart I then needed to do some tuning. I move the pins so they were 1.8mm apart then rotated them back so they pointed at the body. The pins were extended using the pull command.
I assigned an aluminium material for the body and copper for the legs. Just for fun, I added a decal with the frequency. And thanks to Pete Lomas for spotting that the end of the can needed some insulation.
Finally, I added a simple PCB model with the correct hole spacing to check my model.
Note that the PCB needed to be removed before I exported the model as a “STEP” format file.
From the main KiCad screen I located the 3D models folder and copied in my file, renaming it to Crystal_AB38T_D3.0mm_L8.0mm_Horizontal.step to match the convention used by the the other files.
Over in the PCB editor for KiCad, I found the crystal and entered the footprint editor and the footprint properties. In the 3D settings, I browsed to my Step file and loaded it in. This needed a bit of rotation and positioning to align it with the PCB in the preview. Note that you need to highlight the file first before you can position it. I expect that you would be able to design in these rotations and offsets to avoid this step.
The footprint was saved and the 3D view automatically refreshed to show the new model. The decal did not get brought through but the material colours did.
The purpose of the 3D viewer is to check that your components don’t clash with each other. I notice that my crystal sticks beyond the outline marked on the board so it is a good thing that I did not put any other components too close. So perhaps I should swap to a different footprint or design that too but I am happy with the results for this board.
[…] I tried this out by creating a board with lots of vias (drilled holes). I first created one and the used the create array tool to duplicate that all over the board. I did find myself fighting the the design tool, it did not want me to join the pads together. Even when I swapped the router settings to “highlight” instead of avoid it still caused problems. I did find that deleting the pads that were overlapping the components helped. KiCad had the parts I needed by did not have any wire components. However, it should be possible to design a “wire” component in the same way I’ve made other 3D components for KiCad. […]