So KiCads Library management system ist not free of controversy and has been criticized A LOT. Thus let’s see if we can do anything about that …
Let’s for example take a capacitor. The symbol in the shipped library offers you to set its value after it has been placed in the schematic and in the later process steps add a footprint to your taste. But that has a serious drawback: You practically need to design your stuff with the ordering system of your supplier at hand – use their parametric search to see if the desired properties are actually available in the package. BOM-creation becomes a pain in the ass and so on ...
Hence let’s do something different. Using the library editor, let’s load the “C” symbol and add some fields to it. I simply ‘abused’ the value field for the part-name. Yes – there is a designated footprint field – so let’s use that. And create additional fields for tolerance, ratings and dielectric material. However instead of typing in values directly I used placeholders instead. Here is what the result looks like:
I can export the single component and name the file ‘C_template.lib’. It now has the following content:
#encoding utf-8
#
# ###PARTNAME###
#
DEF ~###PARTNAME### C 0 10 N Y 1 F N
F0 "C" 25 100 50 H V L CNN
F1 "###PARTNAME###" -150 0 39 V I C CNN
F2 "###FOOTPRINT###" 50 -200 39 H I L CNN
F3 "###DATASHEET###" 50 -400 39 H I L CNN
F4 "###VALUE###" 50 -100 60 H V L CNN "P_Value"
F5 "###RATING###" 50 -250 39 H I L CNN "P_Rating_U"
F6 "###TOLERANCE###" 50 -300 39 H I L CNN "P_Tolerance"
F7 "###MATERIAL###" 50 -350 39 H I L CNN "P_Material"
DRAW
P 2 0 1 20 -80 -30 80 -30 N
P 2 0 1 20 -80 30 80 30 N
X ~ 1 0 150 110 D 50 50 1 1 P
X ~ 2 0 -150 110 U 50 50 1 1 P
ENDDRAW
ENDDEF
#
#End Library
Ok, now let’s get to the real deal. Let’s create the library. Of course, as a good engineer, we start with Excel :-) Or rather with OOCalc, if you prefer. And now I cant put all the parameters in it, like so:
… and save it as plain csv.
Convenient Bash-skills are convenient …
echo "EESchema-LIBRARY Version 2.3" > Capacitors_SMD.lib; echo "EESchema-DOCLIB Version 2.0" > Capacitors_SMD.dcm; for i in $(cat Capacitors_SMD.csv); do IFS='; ' read -r -a array <<< "$i"; cat ${array[2]}_template.lib | tail -n +3 | head -n -2 | sed -e "s/###PARTNAME###/${array[0]}/g" -e "s/###FOOTPRINT###/${array[3]}/g" -e "s/###VALUE###/${array[4]}/g" -e "s/###RATING###/${array[5]}/g" -e "s/###TOLERANCE###/${array[7]}/g" -e "s/###MATERIAL###/${array[6]}/g" -e "s,###DATASHEET###,${array[8]},g" >> Capacitors_SMD.lib; echo "\$CMP ${array[0]}" >> Capacitors_SMD.dcm; echo "K ${array[3]} ${array[4]} ${array[5]} ${array[6]}" >> Capacitors_SMD.dcm; echo "\$ENDCMP" >> Capacitors_SMD.dcm; done
This transforms the csv into KiCad library format using the template. The result looks like this:
~/kicad_partlib$ head Capacitors_SMD.dcm
EESchema-DOCLIB Version 2.0
$CMP 0603N1R0C500CT
K SMD0603 1p0 50V NP0
$ENDCMP
$CMP 0603N1R5C500CT
K SMD0603 1p5 50V NP0
$ENDCMP
$CMP 0603N1R8C500CT
K SMD0603 1p8 50V NP0
$ENDCMP
~/kicad_partlib$ head -n 24 Capacitors_SMD.lib
EESchema-LIBRARY Version 2.3
#
# 0603N1R0C500CT
#
DEF ~0603N1R0C500CT C 0 10 N Y 1 F N
F0 "C" 25 100 50 H V L CNN
F1 "0603N1R0C500CT" -150 0 39 V I C CNN
F2 "SMD0603" 50 -200 39 H I L CNN
F3 "
http://www.passivecomponent.com/document/MLCC/MLCC_catalog_200503.pdf" 50 -400 39 H I L CNN
F4 "1p0" 50 -100 60 H V L CNN "P_Value"
F5 "50V" 50 -250 39 H I L CNN "P_Rating_U"
F6 "0.25p" 50 -300 39 H I L CNN "P_Tolerance"
F7 "NP0" 50 -350 39 H I L CNN "P_Material"
DRAW
P 2 0 1 20 -80 -30 80 -30 N
P 2 0 1 20 -80 30 80 30 N
X ~ 1 0 150 110 D 50 50 1 1 P
X ~ 2 0 -150 110 U 50 50 1 1 P
ENDDRAW
ENDDEF
#
# 0603N1R5C500CT
#
DEF ~0603N1R5C500CT C 0 10 N Y 1 F N
Loading this library and you get a nice search frontend in eeschema:
Or you can search by other parameters.
Placing the component and you have an innocent looking capacitor…
Or you can go full tilt and set everything to visible …
So what do you think? Could that be a viable way to work with components in KiCAD? Suggestions?