Python package that generates hardware pinout diagrams as SVG images

Overview

PinOut

A Python package that generates hardware pinout diagrams as SVG images. The package is designed to be quite flexible and works well for general 'pinning' labels to an image.

How to use

Some demonstration code and notes are a quick way to get started. Browsing the source code is recommended in the absence of more detailed explaination. The guide here walks through creating a diagram, add an image and some labels. Then finally exporting the resulting SVG graphic.

Setup

Using a virtual environment is recommended; Start by installing the PinOut diagram package. Either clone this repo and pip install it or it can be installed directly from github...

pip install git+https://github.com/j0ono0/pinout@main

You will need an image and a stylesheet to complete this guide. Some sample files are included with the package and can be duplicated for your use. Launch Python at the location you intend to work and enter the following:

from pinout import resources
resources.duplicate()

# expected output:
# >>> sample_diagram.py duplicated.
# >>> sample_hardware_board.png duplicated.
# >>> sample_styles.css duplicated.

Spoiler Alert: 'sample_diagram.py' is a completed script that duplicates the code in this guide. Running it will create a sample SVG pinout diagram.

Starting a pinout diagram

Start by importing the pinout diagram module

from pinout import diagram

Create a new diagram and add a stylesheet.

pinout_diagram = diagram.Diagram()
pinout_diagram.stylesheet = 'sample_styles.css'

TIP: Component coordinates

On export the final diagram dimensions are calculated and all components shifted into view (via the SVG viewBox). Consequently, component 'x' and 'y' positioning is relative to each other and not the parent diagram. It is recommended to position your image to make easier calculations for subsequent pin placements.

Add an image to the diagram

The image is linked in the final diagram (not embedded or copied to the export destination). If a relative path is used it must be relative to where the diagram is exported to.

pinout_diagram.add_image(0, 0, 220, 300, 'sample_hardware_board.png')

Create a pin

This is slow way, included to provide an idea of the steps going on behind the scene.

leftpin = diagram.Pin(16, 80, 'left')

Add some labels to the pin Note: label width, height, and gap to next label, can be controlled per label and override default settings.

leftpin.add_label('#1', 'gpio', 60, 20, 60)
leftpin.add_label('A1', 'analog')
leftpin.add_label('PWM', 'pwm')

Add this pin to the diagram

pinout_diagram.components.append(leftpin)

Create a Pin and Labels in a single action

The fast - and recommended - way.

label_data = [('#2', 'gpio',60, 20, 60),('GPI', 'gpi')]  
pinout_diagram.add_pin(16, 120, 'left', label_data)

With a little 'python-foo' this process can be streamlined dramatically

custom_specs = (60, 20, 60) 
pin_label_data = [
        [('Vss', 'pwr-mgt', 40, 20, 190)], 
        [('GND', 'pwr-mgt', 40, 20, 190)], 
        [('#6', 'gpi',*custom_specs),('A3', 'analog'),('CLK', 'gpi')], 
        [('#5', 'gpio',*custom_specs),('A2', 'analog')], 
    ]

Hardware headers have evenly spaced pins - which can be taken advantage of in a loop. These variables were determined by measuring pin locations on the image.

y_offset = 80
x_offset = 204
pitch = 40

for i, label_data in enumerate(pin_label_data):
    y = y_offset + pitch * i
    pinout_diagram.add_pin(x_offset, y, 'right', label_data)

Export the diagram

The final diagram can be exported as a graphic in SVG format. This vector format and excellent for high quality printing but still an effecient size for web-based usage. Note: the 'overwrite' argument is a safeguard to prevent unintentionally losing existing files. Set it to True for easier tinkering on a single SVG graphic.

pinout_diagram.export('sample_diagram.svg', overwrite=False)

# expected output:
# > 'sample_diagram.svg' exported successfully.
Comments
  • Double row connectors

    Double row connectors

    I have not seen a sample with double row connectors.

    Can Pinout work on boards like this one ?
    https://github.com/infphyny/FpgaRiscV/blob/main/data/Deca/Deca.svg

    opened by somhi 14
  • PNG / SVG export differences

    PNG / SVG export differences

    When exporting there is following differences of text not center aligned inside labels in the SVG version whereas PNG version left is Ok. Any clues? pngsvg

    opened by somhi 7
  • Random thoughts on 0.0.9

    Random thoughts on 0.0.9

    These are a few random thoughts I had while working with 0.0.9, not sure how useful they are, so take them as you will, 0.0.9 is great as-is anyways! :)

    Feels a bit weird to have YAML and the py files, in the main branch the data is in py and just the style stuff is in CSS, that makes sense to me. It also feels weird that half of the legend info (i.e. position) is in py but then width and radius are in YAML. I guess my confusion comes from the fact that the YAML mixes two types of information: styles (colors, fonts, etc.) and data (tag names).

    It feels a bit weird that the tags info is spread between YAML and py, I get that the categories param for add_legend is optional and only useful if you want to hide some tags, but if you want to add a new tag, you have to do it in two places. Maybe it would be better to add a visible property to the tags in YAML, have them be true by default s you only set false for the ones you want to hide.

    I wish I could provide colors as #112233 hex values for the tags :D

    I was surprised to find out that the labels don't adjust their width to fit the whole text they contain, but I do understand it might be hard to calculate that dynamically with custom fonts, weights, and all that. Not a big deal.

    It would be great to be able to provide background AND text colors for tags as I did in my fork. Some colors don't work as well with black text, but some do.

    Can't wait to be able to add custom text in random places!

    • the stuff I did in my work: parallelogram labels, a bullet at the end of the leaderline, hiding leaderlines between labels, having all the leaderlines be one color, and injecting raw svg code

    Thanks!

    opened by arturo182 6
  • ideas for image x-y positional documentation

    ideas for image x-y positional documentation

    I had somewhat of a difficult time getting started with my first board. The issue was a repeated edit file, run pinout, reload image process as I tried to position pinout items on my image with a trial-and-error process. I wrote a little script to automate the first two (then manually refresh the browser):

    #!/usr/bin/env bash
    
    while  [ 1 -eq 1 ]; do 
      inotifywait -e modify styles.css pinout_ulx3s.py data.py
      echo "Change! $(date)"
      rm pinout_ulx3s.svg
      python3 -m pinout.manager --export pinout_ulx3s pinout_ulx3s.svg
    done
    

    Perhaps this would be useful to others... but I'm also wondering if better documentation on the positioning parameters would help? What do you think of taking the quickstart data file, and having it notated in an image with all the respective data file <x,y> coordinates as defined in the respective data file?

    documentation 
    opened by gojimmypi 4
  • file based user config

    file based user config

    Enable users to provide config settings in their own config module. This will allow better styling portability between diagrams. Potentially useful where entire config requires amendment/swapping - eg. where unit measurements are changed from px to mm, cm or in.

    AND ...Update all modules to refer to revised config

    enhancement 
    opened by j0ono0 3
  • Extract KiCad data

    Extract KiCad data

    Explore possibilities for extracting data direct from a kicad_pcb file. Options/ideas:

    • Create pinout KiCad footprint library for documenting label coordinates and content
    • Add "pinout-data" to existing footprint instances (modules) as an "fp_text" entry
    • Extract and draw CutLines and nominated components

    Related Note: pcbdraw looks promising as a source for PCB images - as suggested by others. Windows (my dev env) is not well supported by current KiCad release and consequently I've not tried it out yet.

    enhancement 
    opened by j0ono0 3
  • SVGs of Arduino boards

    SVGs of Arduino boards

    As commented in Twitter (https://twitter.com/dcuartielles/status/1396565190007824385) there are some SVGs of Arduino boards available in Fritzing sources/packages: https://github.com/fritzing/fritzing-parts/tree/develop/svg/core/breadboard. Some other are available in the Arduino documentation site, but not all of the boards provide "Fritzing Files". See, for instance, https://docs.arduino.cc/hardware/nano-every and https://docs.arduino.cc/hardware/nano.


    I was about to try using one of those with pinout, but the quick start is not working for me:

    # git clone https://github.com/j0ono0/pinout
    # cd pinout
    # PYTHONPATH=$(pwd) python -m pinout.file_manager --duplicate quick_start
    Traceback (most recent call last):
      File "C:/msys64/mingw64/lib/python3.8/runpy.py", line 194, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:/msys64/mingw64/lib/python3.8/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "T:\pinout/pinout/file_manager.py", line 3, in <module>
        import pkg_resources
    ModuleNotFoundError: No module named 'pkg_resources'
    
    opened by umarcor 3
  • quick_start instructions do not work with Python 3.8.6

    quick_start instructions do not work with Python 3.8.6

    tried to follow instructions. "Open a command line in the location you plan to work and enter the following: py -m pinout.file_manager --duplicate quick_start"

    I do not know how to fix this or what is complaining

    $ py -m pinout.file_manager --duplicate quick_start

    /usr/bin/py:16: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working (not working in 3.8.6!) from collections import Iterable usage: py [-x] [-l] [-c PRE_CMD] [-C POST_CMD] [-V] [-h] [expression] py: error: unrecognized arguments: -m --duplicate quick_start

    $ python --version Python 3.8.6

    opened by davidoccam 3
  • enable default settings

    enable default settings

    current method of documenting pin-labels is (possibly) unnecessary verbose where labels share many common geometry features. Review and amend method of label configuration.

    enhancement 
    opened by j0ono0 2
  • Label customisations

    Label customisations

    Enable easier method of inserting custom components into a label if possible. ...or a method of 'assembling' labels from user defined elements

    key ideal outcomes:

    • custom label body
    • custom leaderline
    enhancement 
    opened by j0ono0 2
  • Samples have inaccuracies: fix

    Samples have inaccuracies: fix

    annotations sample labels a micro usb-c --don't think this exists! hardware board 'microcontroller' has an unlikely pin-count - add more pins to match a popular component.

    bug 
    opened by j0ono0 2
  • add 'new project' instructions

    add 'new project' instructions

    Add a method to get started quickly on a project as an alternative to the quick_start files (which are more oriented as a tutorial of the basics). Focus on 'best practice' file structure and a recommended starting point for a new project.

    enhancement 
    opened by j0ono0 0
  • enable alternative units (in, cm, mm)

    enable alternative units (in, cm, mm)

    Enable users to input dimensions in physical units.

    Might be desirable because aspects of the diagram are intrinsically measured in physical/defined scales: PCBs are created according to physical dimensions Diagrams are likely to be printed out on standardized paper sizes (and at dpi higher than screen dpi)

    enhancement 
    opened by j0ono0 2
  • access KiCad title_block content

    access KiCad title_block content

    title block content is an obvious source of content that might be useful in a pinout diagram - Providing access to the title block will remove need for doubling up on content input.

    enhancement 
    opened by j0ono0 0
  • Tomu Pinouts

    Tomu Pinouts

    Create a pinout template example that can be used for similar boards. Use the Tomu family as an example.: https://tomu.im/

    Project goals:

    • Source data from spreadsheet(s)
    • Maximise automation
    documentation 
    opened by j0ono0 0
Owner
UI and UX designer with some developer garnish on top.
null
erdantic is a simple tool for drawing entity relationship diagrams (ERDs) for Python data model classes

erdantic is a simple tool for drawing entity relationship diagrams (ERDs) for Python data model classes. Diagrams are rendered using the venerable Graphviz library.

DrivenData 129 Jan 4, 2023
Simple python implementation with matplotlib to manually fit MIST isochrones to Gaia DR2 color-magnitude diagrams

Simple python implementation with matplotlib to manually fit MIST isochrones to Gaia DR2 color-magnitude diagrams

Karl Jaehnig 7 Oct 22, 2022
Draw tree diagrams from indented text input

Draw tree diagrams This repository contains two very different scripts to produce hierarchical tree diagrams like this one: $ ./classtree.py collectio

Luciano Ramalho 8 Dec 14, 2022
A toolkit to generate MR sequence diagrams

mrsd: a toolkit to generate MR sequence diagrams mrsd is a Python toolkit to generate MR sequence diagrams, as shown below for the basic FLASH sequenc

Julien Lamy 3 Dec 25, 2021
UNMAINTAINED! Renders beautiful SVG maps in Python.

Kartograph is not maintained anymore As you probably already guessed from the commit history in this repo, Kartograph.py is not maintained, which mean

null 1k Dec 9, 2022
GitHubPoster - Make everything a GitHub svg poster

GitHubPoster Make everything a GitHub svg poster 支持 Strava 开心词场 扇贝 Nintendo Switch GPX 多邻国 Issue

yihong 1.3k Jan 2, 2023
A program that analyzes data from inertia measurement units installed in aircraft and generates g-exceedance curves.

A program that analyzes data from inertia measurement units installed in aircraft and generates g-exceedance curves.

Pooya 1 Dec 2, 2021
YOPO is an interactive dashboard which generates various standard plots.

YOPO is an interactive dashboard which generates various standard plots.you can create various graphs and charts with a click of a button. This tool uses Dash and Flask in backend.

ADARSH C 38 Dec 20, 2022
A small script written in Python3 that generates a visual representation of the Mandelbrot set.

Mandelbrot Set Generator A small script written in Python3 that generates a visual representation of the Mandelbrot set. Abstract The colors in the ou

null 1 Dec 28, 2021
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 394 Dec 18, 2022
nptsne is a numpy compatible python binary package that offers a number of APIs for fast tSNE calculation.

nptsne nptsne is a numpy compatible python binary package that offers a number of APIs for fast tSNE calculation and HSNE modelling. For more detail s

Biomedical Visual Analytics Unit LUMC - TU Delft 29 Jul 5, 2022
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 356 Feb 16, 2021
nptsne is a numpy compatible python binary package that offers a number of APIs for fast tSNE calculation.

nptsne nptsne is a numpy compatible python binary package that offers a number of APIs for fast tSNE calculation and HSNE modelling. For more detail s

Biomedical Visual Analytics Unit LUMC - TU Delft 24 Feb 3, 2021
Python package for hypergraph analysis and visualization.

The HyperNetX library provides classes and methods for the analysis and visualization of complex network data. HyperNetX uses data structures designed to represent set systems containing nested data and/or multi-way relationships. The library generalizes traditional graph metrics to hypergraphs.

Pacific Northwest National Laboratory 304 Dec 27, 2022
A Python package that provides evaluation and visualization tools for the DexYCB dataset

DexYCB Toolkit DexYCB Toolkit is a Python package that provides evaluation and visualization tools for the DexYCB dataset. The dataset and results wer

NVIDIA Research Projects 107 Dec 26, 2022
A minimal Python package that produces slice plots through h5m DAGMC geometry files

A minimal Python package that produces slice plots through h5m DAGMC geometry files Installation pip install dagmc_geometry_slice_plotter Python API U

Fusion Energy 4 Dec 2, 2022
eoplatform is a Python package that aims to simplify Remote Sensing Earth Observation by providing actionable information on a wide swath of RS platforms and provide a simple API for downloading and visualizing RS imagery

An Earth Observation Platform Earth Observation made easy. Report Bug | Request Feature About eoplatform is a Python package that aims to simplify Rem

Matthew Tralka 4 Aug 11, 2022
Python Package for CanvasXpress JS Visualization Tools

CanvasXpress Python Library About CanvasXpress for Python CanvasXpress was developed as the core visualization component for bioinformatics and system

Dr. Todd C. Brett 5 Nov 7, 2022
Python package to Create, Read, Write, Edit, and Visualize GSFLOW models

pygsflow pyGSFLOW is a python package to Create, Read, Write, Edit, and Visualize GSFLOW models API Documentation pyGSFLOW API documentation can be fo

pyGSFLOW 21 Dec 14, 2022