BOM (Bill Of Materials) generation is an important and usually cumbersome part of doing electronics. KiCad has two ways to generate a BOM: from the schematic and from the layout.
In pcbnew select from the menu: File -> Fabrication outputs -> BOM file.
This generates a simple CSV (Comma Separated Value) file with the components grouped by type and value.
"Id";"Designator";"Package";"Quantity";"Designation";"Supplier and ref"; 1;"C1,C24";"0402_C";2;"10nF";;; 2;"C2,C5,C8,C9,C10,C15,C16,C17,C18,C19,C20,C22,C23,C28,C32";"0402_C";15;"100nF";;; 3;"C3,C4";"0402_C";2;"8pF";;;
While useful for simple boards and experiments, in practice you usually want more detail e.g. capacitor voltage in the BOM, as explained nicely in this article from Spark.
KiCad also allows generating a BOM from the schematic. This works by it generating an XML exporting all the data fields for all used components and post-processing this XML with a script. This is nice as it allows to document everything in one place: the schematic.
The biggest disadvantage is that currently it seems to be impossible to save these extra fields as part of a component meaning it involves manual entering for each schematic. Automating this in some way would be nice.
The actual generation of the BOM is done with the menu: Tools -> Generate Bill Of Materials
This gives the following screen:
This may seem a bit daunting but it is actually quite simple. What KiCad does is just generate an XML file with all the components with all the fields. Each plugin is just a script that is passed that XML file as an argument and the output is the resulting BOM.
An example XML fragment:
<comp ref="C12"> <value>2.2uF</value> <footprint>passive:0402_C</footprint> <fields> <field name="Voltage">10V</field> <field name="Package">0402</field> <field name="Identifier">capacitor</field> <field name="Tolerance">X5R +-10%</field> </fields> <libsource lib="passive" part="C"/> <sheetpath names="/" tstamps="/"/> <tstamp>54FF2106</tstamp> </comp>
This example python code generates a BOM from the XML, assuming a bunch of standard fields and allowing for extra fields, groups by Identifier and Value.
It uses the beautifulsoup python library for easy parsing of the XML.
P.S.: for the language purists out there: yes, this code is very inefficient (quadratic complexity) but it still runs in milliseconds on a modern computer so it doesn’t matter 😉
It is possible to generate a nice and detailed BOM from KiCad but there is still work making it more automated.