Skip to the content
PCBKitNew board
2 layers18 × 20 mmUsbPower, the printed circuit board in 3D

A PegJS parser for Kicad Modules

Size
18 × 20 mm
Copper layers
2
Thickness
1.6 mm
Parts
6
Nets
8
Pads
42
Tracks, vias
0, 0
Routed
Not yet
KiCad
KiCad 5 (file 20171130)
Created
9 Aug 2020
Updated
17 Nov 2024

Overview

UsbPower is an open-source printed circuit board by jdthorpe, from the jdthorpe/kicad-module-parser repository on GitHub. It is a 2-layer board of 18 × 20 mm with 6 parts on 8 nets.

Its parts include 2 capacitors, 2 resistors and 2 connectors.

README

README.md

Convert Kicad Board and Module files to JSON

Do you love working with S-Expressions? Me either. Convert your Kicad board and module files to JSON or YAML and use your favorite tools to work with your Kicad board and module file data!

CLI Usage

When installed globally (npm i -g kicad-to-json), npm installs the k2j command line tool, which converts your kicad files to json like so:

sh
k2j ./my_module_file.kicad_mod
# creates ./my_module_file.json in compact format

k2j ./my_board_file.kicad_pcb --yaml --format long
# creates ./my_board_file.yaml in long format

Use the -h flag for the usual help:

txt
usage: index.js [-h] [-o OUTPUT] [-f {compact,long,bare}] [-v] [--yaml] file

Convert Kicad board and module files to JSON/YAML

positional arguments:
  file                  The Kicad pcb or module file to convert to json

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output file (defaults to input file with '.json' or '.yaml' extension)
  -f {compact,long,bare}, --format {compact,long,bare}
                        Set the output format
  -v, --verbose         verbose output
  --yaml                set output to yaml

Javascript / Typescript Usage

User friendly data

ts
import { parse } from "kicad-module-parser"

// convert the module (string) to compact format
const my_module = parse.module(kicad_mod_contents_string)

// convert the board (string) to long format
const my_board = parse.board(kicad_pcb_contents_string,"long")

Output Formats

Background

The kicad_mod and kicad_pcb files are S-Expressions based which have the general format (name ...contents ) where the contents are either individual values or nested s-expressions (e.g. ( pts (xy 1 1) (xy 2 2))). Some s-expressions are singletons, such as the pts expression within a polygon and others can appear multiple times, such as the individual xy pairs within an array of points.

bare Notation

In the bare notation the first token in the s-expresion appears as it's type attribute, and the remaining sub-expression appear in the value attribute. This format is quite literal, but generally hard to work with. Here is a brief example (in yaml format):

yaml
type: kicad_pcb
value:
  - type: version
    value:
      type: number
      value: '20171130'
  - type: general
    value:
      - type: thickness
        value:
          type: number
          value: '1.6'
      - type: drawings
        value:
          type: number
          value: '605'
      - type: tracks
        value:
          type: number
          value: '2555'
      - type: zones
        value:
          type: number
          value: '0'

compact Notation

In the compact format, s-expression types and values from the bare format are used as key-value pairs of a JSON object This works for s-expressions that are singletons, but for expressions like (add_net GND) (add_net +3v3) which may appear multiple times within the parent s-expression, the contents of the expression are included in an array of the same name, such as :

json
{
    "add_net":[
        {"net_name": "GND"},
        {"net_name": "+3v3"}
    ]
}

Here is the same example from above in compact format:

yaml
kicad_pcb:
  version: 20171130
  general:
    thickness: 1.6
    drawings: 605
    tracks: 2555
    zones: 0
    modules: 172
    nets: 143

long Notation

The long format is a hybrid between the Compact and Bare formats, and recoginses that module and board files are special, in that nearly every file will have many repeating entities (such as gr_lines) where preserving the order of the entites may be useful. Hence, the immediate children of boards and modules (and modules nested within boards) are represent in bare format, and everything else is represented in compact format. Here is the same example from above in long format:

yaml
kicad_pcb:
  - type: version
    value: 20171130
  - type: general
    value:
      thickness: 1.6
      drawings: 605
      tracks: 2555
      zones: 0
      modules: 172
      nets: 143

bare Format Details

There are 4 primitives in the bare format which have type "string", "hex", "number" and "boolean", such as:

json
{ "type": "string", "value": "GND" }
{ "type": "hex", "value": "1234ABCD" }
{ "type": "number", "value": "3.2" } // yes, numbers are represented as strings
{ "type": "boolean", "value": true }

The array type has a type attribute of "array" and a value contianing an aray of primitives, such as:

json
{ "type": "array", "value": [ { "type": "string", "value": "GND" } ] }

The container type is like the array type but it's type attribute has a value other than "string", "hex", "number", "boolean" or "array", and the value can contain any type (including other containers), or an array containing any of the types, sucy as:

json
{
  "type": "xy",
  "value": [
    {
      "type": "x",
      "value": {
        "type": "number",
        "value": "117.4"
      }
    },
    {
      "type": "y",
      "value": {
        "type": "number",
        "value": "28"
      }
    }
  ]
}

Final notes

There are a handfule of sub-parsers and things I was not personally interested in (such as page formatting) which result in a value like "page info": "unsupported". If you despirately need page info (or any other unsupported features), I welcome your pull request!

If your board or module results in an error, please put it in a github repo (or a minimal example that raises the same error), and open an issue with a link to that github repo.

Parts

6
QtyValueFootprintReferences
20.47uFCapacitor_SMD:C_0402_1005MetricC1, C2
25.1KResistor_SMD:R_0402_1005MetricR1, R2
1Conn_01x04Connector_PinHeader_1.27mm:PinHeader_1x04_P1.27mm_Vertical_modifiedJ2
1USB_C_Receptacle_USB2.0Connector_USB:USB_C_Receptacle_Amphenol_12401548E4-2AJ1

Questions

How big is the UsbPower PCB?

It measures 18 × 20 mm and has 2 copper layers, 1.6 mm thick.

What parts does the UsbPower use?

6 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the UsbPower KiCad files?

From the jdthorpe/kicad-module-parser repository on GitHub, at the commit this page was made from: the board is data/pcb/custom/UsbPower.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the UsbPower design in my own project?

Its repository states no licence, so its author keeps all rights: ask jdthorpe before reusing the design.

More from jdthorpe/kicad-module-parser

4
  • 4 layers85 × 57.5 mmFirefly, the printed circuit board in 3D

    Firefly

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    104 parts12
  • 4 layers43 × 24 mmDisco, the printed circuit board in 3D

    Disco

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    21 parts12
  • 4 layers16 × 13 mmBoard simple, the printed circuit board in 3D

    Board simple

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    2 parts12
  • 4 layers16 × 13 mmBoard2, the printed circuit board in 3D

    Board2

    jdthorpe/kicad-module-parser

    A PegJS parser for Kicad Modules

    2 parts12

Similar boards

  • 2 layers18.5 × 11.1 mmSwitch, the printed circuit board in 3D

    Switch

    byrantech/laptop

    anyon_e, a highly integrated, high end, open source laptop. Attempt the impossible.

    6 parts4.3kMIT
  • 2 layers14.6 × 33 mmBrain board SD Card 1, the printed circuit board in 3D

    Brain board SD Card 1

    rusefi/rusefi

    rusefi - GPL internal combustion engine control unit

    6 parts1.2k
  • 2 layers9 × 9 mmDpoint, the printed circuit board in 3D

    Dpoint

    Jcparkyn/dpoint

    Open-source digital stylus using camera tracking and inertial measurements

    6 parts1.1kMIT
  • 2 layers51.5 × 16.6 mmMicroswitchXY Endstop, the printed circuit board in 3D

    MicroswitchXY Endstop

    VoronDesign/Voron-Hardware

    Cool Hardware designed by the Voron Design group

    6 parts1.1kGPL-3.0
  • 2 layers21.9 × 76.7 mmAmiga External, the printed circuit board in 3D

    Amiga External

    hoglet67/RGBtoHDMI

    Bare-metal Raspberry Pi project that provides pixel-perfect sampling of Retro Computer RGB/YUV video and conversion to HDMI

    6 parts1kGPL-3.0
  • 2 layers88.9 × 50.8 mmBusinesscard, the printed circuit board in 3D

    Businesscard

    hackclub/OnBoard

    💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

    6 parts915
  • 2 layers20.3 × 15.2 mmL0 RGB led, the printed circuit board in 3D

    L0 RGB led

    Luos-io/luos_engine

    Open-source and real-time orchestrator for cyber-physical-systems, to easily design, test and deploy embedded applications and digital twins.

    6 parts546MIT
  • 2 layers9 × 3.6 mmOpticalEncoder, the printed circuit board in 3D

    OpticalEncoder

    adamb314/ServoProject

    Getting the most out of your hobby servo

    6 parts545