3D part design with OpenSCAD # 152: How to make your own 3d models for Kicad from scratch.

3D part design with OpenSCAD # 152: How to make your own 3d models for Kicad from scratch.

Quite often when I am designing a circuit and I want to make a 3d rendering of it there are models missing and if you look online most places with free models want you to sign up or the models are pretty basic, there are a lot of free models online if you can find them but if you are like me it's more fun to make your own.

Recently I needed a model of an OP amp so I used OpenSCAD to make a customizer that I can add text and a logo to the IC, adjust the number of pins, etc. As with all of the stuff I make it's a work in progress and I will be adding features and fixing some errors over time.

I am using the latest version of Kicad:

Download
A Cross Platform and Open Source PCB Design Suite

And the latest development snapshot of OpenSCAD:

OpenSCAD - Downloads

Here is the code:


//Dual Inline Package IC customizer for Kicad V1 by InfinityPlays.com//


/*[Scale for Output to Kicad]*/
Scale_all=.395;//[.001:.001:1]

/*[Main Body]*/
Number_of_pins=8;//[4:2:20]
Pin_length=5;//[1:.01:5]
Body_length_adjust=-2.5;//[-3:.01:3]

/*[Text]*/
Input_text="U1";
Font_style="";
text_size=2;//[.1:.1:3]
Text_rotate=90;//[0:.01:180]

/*[SVG Logo]*/
Show_logo=false;
Path_to_SVG_file="";
Scale_logo=1;//[.001:.001:1]
Move_logoX=0;//[-10:.01:10]
Move_logoY=0;//[-10:.01:10]
Move_logoZ=0;//[-10:.01:10]

module body(){
minkowski(){
 linear_extrude(1.3,scale=.6)
 square([2,2],center=true);
 mirror([0,0,1])
 linear_extrude(1.3,scale=.95)
 square([4.8,Number_of_pins+2.54+Body_length_adjust],center=true);
 sphere(.2,$fn=100);
}}

module pins(){
 translate([0,13.31,0])
 color("azure")
 for(i=[-Number_of_pins/4:1:Number_of_pins/4-1])
 translate([0,i*2.54,0])
union(){
 translate([-3.8,-12,-1])
 cube([.5,1,2],center=true);
 translate([-3.8,-12,-2.5])
 cube([.4,.4,Pin_length],center=true);
 translate([-3.05,-12,0])
 rotate([90,0,0])
 cylinder(1,1,1,$fn=100,center=true);
}}

module Text(){
 color("white")
 linear_extrude(1.6)
 rotate([0,0,Text_rotate])
 translate([0,0,1.3])
 text(Input_text,font=Font_style,spacing=1,
 size=text_size,valign="center",halign="center",$fn=50);
 color("white")
 linear_extrude(1.6)
 translate([2.3,-Number_of_pins/2.1,.6])
 circle(.4,$fn=100);
}
 module Logo(){
  if(Show_logo)
  color("white")
  rotate([0,0,90])
  translate([Move_logoX,Move_logoY,1])
  linear_extrude(.65)
  scale([Scale_logo,Scale_logo,0])
  import(Path_to_SVG_file);

 }
translate([0,0,2.4]){
scale([Scale_all,Scale_all,Scale_all]){
color("black")
body();
mirror([1,0,0])
pins();
pins();
Text();
Logo();
}}

I added the option to load an svg so it can have an image or custom logo:

The logo I used for this example came from here:

File:TexasInstruments-Logo.svg - Wikimedia Commons

I am using the Texas Instruments logo for informational and education purposes only, and as a long time user of their products I can confidently say they are an excellent company that provides high quality components at extremely affordable prices for hobbyists. Plus I think their logo looks cool on my finished 3d model.

I also added a text input feature to make labels for the IC:

To change the font just open the font selector window, copy the font name and paste it in the font style box:

It's pretty easy to add custom svg files:

There is also a scale option for Kicad, I'm sure there's a reason the scaling is set so small and maybe I'm missing something (it's probably to save space and so they load faster) but it was pretty easy to fix with OpenSCAD, here is a socket model from the standard Kicad library and I have adjusted the scale of my model to fit it:

Here it is at normal size on a perfboard with 2.54mm hole spacing, you can see the yellow legs of the model from Kicad, there is an option in Kicad to move and scale the model so this isn't necessary but it was easy to add so added it anyway

Once the file was rendered I exported it as a .WRL file so it can be imported into Kicad:

In the PCB editor double click on the outline of the component and a dialog will open:

Click the plus sign to add a new component:

Then click the file Icon to open the folder location where you saved the file:

Once the file loads you can adjust the position with the selectors:

And now the space that was missing the component has a nice looking model that can be rendered:

And that's how easy it is to make your own custom Component with OpenSCAD for Kicad. Notice that the resistors and transistors look pretty bare so of course I will be making a custom resistor and transistor generator also.