Tutorial: Creating a new SCHEMATIC SYMBOLS library
(Page's name: tssmf1main (Tutorial, Schematic Symbols, Make File for definitions))
I don't usually SHOUT. But I did in the heading because I wanted to stress that there are two sorts of library: Libraries for schematic symbols and libraries for footprints. Schematic symbols and footprints are similar, but not the same. The files which hold their definitions are similar in some ways, and quite different in others. (I have written a separate tutorial for you on getting started with making your own footprints.)
It may seem, particularly in this tutorial, and particularly at the start of it, that I "ramble" an awful lot. If you bear with me, I think it will reward you. The topic we are considering requires a pretty good understanding of what's going in inside KiCad, if you want to do the things explained here without much pulling of hair. There's some abstract stuff going on, and KiCad actually works just fine… the way it was programmed… but not necessarily the way you might assume it is working.
You don't need to make a schematic symbol library early in your days of learning to use KiCad. There are little bodges which all but the most virtuous of us will spot to get you by.
However, don't put off making your own, custom, schematic symbols too long. They are very useful. But when you want to make one, you will first have to create a library for it to be held in.
Until then, if you are working on a schematic, and want to insert, say, a polarized capacitor, but can't fine a schematic symbol for that, use the schematic symbol for an LED. A kludge, but it will get you through. (The issue isn't very great, in regard to schematic symbols. However, a similar issue comes up when you start working on PCB designs. In that context, footprints are analogous to schematic symbols, and you will need custom footprints sooner… but you can kludge yourself out of the need for a little while.
Making custom schematic symbols and custom footprints isn't terribly hard. As I said, don't avoid either of them for too long. (And you don't need to tackle both at once, when the time comes.) But getting some bits and pieces in place, in a mostly "once and for all" exercise is a little tedious. Hence this guide, to help you! (And remind me, the next time I am setting up KiCad on a new machine!)
What is here
Remember: this page is about establishing "a container" for schematic symbol definitions. You do that only once in a while. You could do it just once, if you (foolishly!) didn't want to organise you library of schematic symbol definitions, or if you wanted all of your definitions to be available globally, didn't want ever to have a set of schematic symbols which were relevant only to one project.
But. to get started, one "container" is fine. You might call it "FirstSSLibrary", or somesuch.
In this work, shut all thought of footprints out of your mind. It is easy to get them confused with schematic symbols. Start with:
schematic symbols: Used with eeSchema, for circuit diagrams
footprints: Used with PcbNes, for PCB artwork.
Although while you are using them they seem similar in many ways, the ways the definitions are held inside the computer are quite differents.
More Good News
KiCad is heavily based on "simple" programs which don't "mess about" with "clever stuff". Most of the things KiCad needs to remember, like the definition of a schematic symbol or footprint, is held in a simple textfile. So if the management of text files is within your skills, you are halfway to managing KiCad.
Don't let that encourage you to go wild, "fooling" directly with KiCad's text files, but here's the thing:
As you start to learn about "containers" for schematic symbols and footprints, you will probably make mistakes. Do a few "scratch" containers, to see if you understand "things". When you are happy, shut down all of the KiCad modules, and then you can go into your hard drive with your operating system's ordinary file management tools, and "tidy up" the scraps of your early fumbling.
If you made a schematic symbol or footprint during those early stages that you want to keep, there are ways, inside KiCad, to copy them from a "scratch" library to one that you are going to keep, going forward.
If you've completed a project with something in one of yhour "scratch" containers, don't worry! The project will have taken a copy of the definition, and is happy to work from that, even if the "master definition" is no longer available.
One thing that may arise, and scare you:
Within KiCad, you set a preference for what libraries (both schematic symbol and footprint) you want consulted in the work you are doing at the moment. And the list of those libraries is saved.
So, let's say that you'd told KiCad, for now, to include the "MyFootprintDefinitionsLearningWork" library in the ones it consults.
Then you shut down KiCad, delete the things on the hard drive (you'll know what they are when you've completed the "Making Folders for Footprints" tutorial), and then re-start the project.
It will complain. It will say, in effect, "You told me to consult (that) footprint library, and I can't find it."
Not a problem! Just, inside KiCad, go into the list of libraries to be consulted, and remove the line for the now-deceased library!
Easy! Well… the concept is almost easy. Getting every tiny bit of the process exactly right can be a bit trying. But we wouldn't be playing with computers if we liked the easy live, would we?
Libraries of schematic symbols
You've used schematic symbols from the libraries which come "as standard". Now it is time to create, define, a custom schematic symbol for something "they" didn't provide for you.
Easy! But first, and "once and for all" (or at least "only once in a while"), you need a "container" for that schematic symbol definition to live it. A container which you will later add more schematic symbols too.
Having told you to forget footprints for now, I will (foolishly?) bring them up. But only to mention in passing: Custom footprint defintions also need "containers"… but footprints are "contained" by a very different system. Back to schematic symbols…
In the case of schematic symbols, a single text file can hold definitions of many schematic symbols. The file will have ".lib" as its extension, which is an unfortunate name. The schematic symbol libraries, in their .lib files, are not the only libraries used by KiCad. Footprints are stored in libraries, too. (By the way: "component" and "part" are alternative names for schematic symbols and footprints, but I recomment you try to use the latter names, as they are less ambiguous.)
How (and where) to create a new .lib file, and make the system aware of it.
KiCad can "know" about multiple .lib files, each with one or more schematic symbol definitions. They can be in multiple places, i.e. different folders on your hard drive.
I would suggest that "you" use at least two locations: I put "you" in quotes because without any action by you, the system will have set up at least one location, deep in the disk, where it keeps the "standard" libraries. I like it when such things are "out of the way". But you don't have to put your .lib files there.
I have a folder in the "MyDocuments" part of my hard drive called "Kicad-TKB-4-0-4".
"TKB" is my initials. I tend to put it on things to confirm that I created that, unlike, say "MyDocuments". The 4-0-4 part is the version of KiCad I was working on at the time.
It isn't directly relevant to the matter we are working on, but, to set the context:
Within "Kicad-TKB-4-0-4", I have a folder called "Prj", for "Projects". Within that, I create a new folder for every project, and all of its files go there.
Now, back to what we are discussing…
Also in "Kicad-TKB-4-0-4", I have a folder called "Lib"… and this is where I put the library files which hold the definitions of all of the schematic symbols and footprints I have either designed myself, or collected from other developers who make libraies available on the web.
How to DO IT….
Establish the folders discussed above.
Start KiCad, and use it to start "Schematic library editor"…
…which should give rise to the following…..
Note the alias in the title bar: "Part library editor". ("Parts" being a synonym for "schematic symbol".)
It is also worth noting that while, in a sense, you are (sometimes) editing the libraries of the schematic symbols (parts), you are actually usually editing the definitions of the schematic symbols (parts) which are in the libraries! So many ways to get confused! I don't mean to criticize the designers of the interface. There is just only so much you can do when you have to use very short designators.
Now… I told you we were going to create a container for one or more schematic symbol. And we will. But… the way KiCad works, we must put a schematic symbol into the editor before we try to save it. It is during the saving that we will create the new container. (After you've once done that, next time things are more intuitive.)
We will load an existing component, just because that's easier than starting something from scratch.
But to do that, we must first….
Just about any library would do, but to follow along, select the "device" library. Have a look at the Part Library Editor window's title bar after you've done that. It tells you what library is the current working library, including the information about where that is on your hard disk. (It also informs us that the "Device" library is read only… a sensible precaution that was put in place for us. Our library of schematic symbol won't be read only. We will also be able to write to it to add new schematic symbols or edit the definitions stored there.)
Once we've said which library we want to work with, we can use….
… to load a "component", to use the dialog's term for something better referred to as a schematic symbol. Just about any schematic symbol would do, but to follow along in the rest if the tutorial, select the "C" schematic symbol…
(And click "OK"). Which should lead, almost, to the following…
How is that different from what you should have? See the short vertical line, lower right? I added that to the schematic symbol after I loaded it. Well. To the schematic symbol as it is in the editor at the moment. (I used the "Add lines and polygons…" tool, which you can see "on" low on the right hand toolbar.) The line serves no purpose; it is just there to show that we can do something to a schematic symbol.
We have a schematic symbol in the editor!
Now we are going to save it! BUT! Not back into the library it came from. We're going to use our very slightly modified "C" schematic symbol as the "founding member" of our first schematic symbol (component)) //library!
You DON'T want either "File | "Current Library", or "File | Save Current Library As". (The latter would save our revised "C", to a new library, even… but it would also save all the other things that were in the library called "device".) (If you do accidentally create a useless .lib file, then at a time when no module of KiCad is running, just delete that file. Whew!)
What you DO want is the button for "Save current component to a new library"….
Happily, that just brings up a normal "SaveAs" dialog. The same as you've seen many times over your computing years.
The file the computer is going to save should be saved with a ".lib" extension, as provided for by the dialog's default. But before you click "OK" to save it, you should use the SaveAs dialog's normal provisions to navigate to the folder you prepared earlier for your own (and third party) libraries. (Not that yours will be the same, but, to remind you of the earlier discussion, mine is….
(If you want to be "clever", and you initials were TKB, and you'd intended to call this MyFirstSchSym, then a better name would be "AtkbMyFirstSchSym". The "A" will put the library at the top of alphabetized lists of libraries. (They arise in your KiCad work.) (The alphabetizing is case sensitive: "ZAnotherLib" would (sometimes) comebefore "atkbMyFirst", if the "a" is lower case, like that.) The tkb (or uncommon initials of your choice) would flag the library as "yours", and group all of yours together.)
I will use the "clever" name, AtkbMyFirstSchSym, in the examples.
Sigh. Headache yet? Nearly there, despite a few more things. Get a cup of coffee before you click "OK".
So. In a moment, click "OK" to execute the "SaveAs" type operation…. but prepare yourself for a warning message. The following is normal. It is, in fact, quite helpful.
It reminds us of a little detail we might have negected. It is the last thing we have to stuggle with, I am pleased to say. When this is taken care of, our new library is in place. Our "new" (very sliightly) modified "C" schematic symbol is available to our design. And… best of all… adding MORE custom schematic symbols to our library is child's play.
So. Say "OK" (thanks) to the info message.
Remember that usually, when you are using KiCad, you will be working with only a subset of the many scores of schematic symbols available, even in "just" the "basic" KiCad installation?
"Inside" KiCad, there is a list which tells it which libraries to give you access to. (If you had access to all of them, it would slow execution of the program down.)
You need to add our new library to that list. There are several ways to get to the relevant dialog, but, given where we are, here's the route I'd use at this time…
You may not get the same list of libraries, but you should see something similar in the top part of the dialog that opens. (There's more stuff at the bottom… not important to us.) Click the "Add" button indicated….
… and use the "Open" dialog which results to navigate to your newly created custom schematic symbols, and "open" it… which will add it to the list your KiCad installation uses. It will be at the bottom of the list, unless you were clever (okay if you were) or use the "up" button after selecting the newly added library name. (neither is "necessary", but you may wish to have your libraries easy to notice, at the top of the list.)
We did it!
We have a new schematic symbol library.
I know I'm repeating myself… but I do it by way of celebration. You've spent… how long?… stuggling, to get here. Think how long I spent, writing it!
At the moment there's just one (not very useful) schematic symbol ("component") in it. But now that we have the library "container" in place, it is easy to add further schematic symbol definitions. EASY. Nothing like as tedious as establishing the container.
We can also delete schematic symbols from a library.
Let's just be sure…
Let's test whether we really accomplished that.
Go into eeSchema.
Try to place a new schematic symbol on the design. You should have your new library available to you in the list, and within that a schematic symbol called "C". Ah! But is it our "C"? If it has the extra little line we added, it is!
Don't be alarmed if the library isn't there on the first try. It "should" be, and I imaging it was on the two occasions when I paniced when I didn't see it at first, and shut down KiCad, restarted it. It was there on the second try, both times. I'd be interested if anyone has the same experience, and is really, really sure it wasn't in the list of available libraries until the restart.
If you made a few "bish" libraries that you want to get rid of, that's fine. Shut down KiCad. Delete the .lib files (and any .dcm files of the same name in the same folder.) Make notes as you go along of what you remove. Restart KiCad. Don't be alarmed by things like…
The file(s) it is complaining about should be the ones you deleted. (See why you made the list?) Just go into "Preferences | Component Libraries" again, find the library in the "Component library files" list, click on them (use ctrl-click after the first one to do several), and click "Remove". Bingo! Done! (This step wouldn't remove the .lib file from the hard drive, were it still present. It only removes it from KiCad's "what do I use?" list.)