15
\$\begingroup\$

I'm just getting into PCB design and I generally have trouble learning how to use GUIs with menus and mouse clicking. Do some engineers use something more like code to generate PCBs?

\$\endgroup\$
9
  • 7
    \$\begingroup\$ I wouldn't recommend writing plain gerber files... \$\endgroup\$
    – Huisman
    Jul 31, 2019 at 13:37
  • 32
    \$\begingroup\$ PCB layout is mostly a visual task - moving and rotating stuff to make it fit. Doing it by code sounds painful. \$\endgroup\$
    – JRE
    Jul 31, 2019 at 13:38
  • 3
    \$\begingroup\$ There are usually hot keys for most (if not all) menu items; most tools allow text input for location and orientation (but it is a lot more painful to do that than just move things with a mouse). I use the text tools to get precise placement of things like vias and differential pairs. \$\endgroup\$ Jul 31, 2019 at 13:42
  • 4
    \$\begingroup\$ Some CAD packages are more clicky than others. In my experience, Orcad Allegro is the worst for making you go through a lot of pointless GUI actions to get the simplest things done. Diptrace is pretty much the easiest and most fluid user experience. PADS is a very nice toolchain with an intuitive UI and a lot of high-end features. PADS is for engineers who like to get things done, Orcad is for masochists. :D \$\endgroup\$
    – user98663
    Jul 31, 2019 at 13:56
  • 2
    \$\begingroup\$ There are keyboard shortcuts and unique cases where programmatic generation of patterns make sense, but PCB layout is mostly an interactive graphical task. In contrast situations where the logic dominates over the physical embodiment like FPGA and (many parts of) ASIC design typically are driven by hardware description languages feeding logic compilers feeding automated place & route tools. If we were still building mainframe processors from big boards full of TTL there might be a comparable design flow for HDL to PCB... but fortunately we aren't. \$\endgroup\$ Jul 31, 2019 at 15:08

5 Answers 5

20
\$\begingroup\$

Altium has a scripting language, several different languages, in fact. In some cases it may make sense to use algorithms, for example to create repetitive layouts or parts placed precisely in certain positions.

For example, I've seen it used to place parts (LEDs) in a circular pattern, though with their introduction of polar coordinate snap grids that's much less likely to be worth the hassles.

We've used algorithms to create shapes (think antennas and that kind of thing) directly in .dxf format which can then be imported into a copper layer.

In general, code is poorly suited for PCB layout purposes, particularly so for the routing task.

\$\endgroup\$
17
\$\begingroup\$

In EAGLE CAD, everything you can do with a mouse you can do from the command line. It also has a user language that you can essentially program in.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Very useful when doing patterns, etc. Even if you do 99% of the layout manually you can still arrange parts/features with code. \$\endgroup\$
    – Wesley Lee
    Jul 31, 2019 at 16:20
  • 1
    \$\begingroup\$ Often, I code in Matlab or a text processor to output scripting language. \$\endgroup\$ Jul 31, 2019 at 16:21
  • 3
    \$\begingroup\$ Yes! I used to do it in Python :) \$\endgroup\$
    – Wesley Lee
    Jul 31, 2019 at 16:21
  • 1
    \$\begingroup\$ This is one of the key advantages of Eagle. Once you start, you'll only use the command line. \$\endgroup\$
    – D Duck
    Aug 1, 2019 at 8:25
7
\$\begingroup\$

I use code to generate the netlist for my PCBs. (It's far, far quicker to write a for-loop to build an N-bit multiplexer than to laboriously draw all that stuff in a schematic.) Fortunately, KiCAD netlist files are just text, in a format that's undocumented but reasonably easy to reverse-engineer.

I wrote a small C# library that lets me type in what I want connected to what (in terms of reusable parametric blocks of circuitry), and it automatically spits out a netlist. Now I can just import that straight into KiCAD and start building the PCB, without having to waste an hour or so uselessly drawing a schematic for it. (The library even does some very basic checks to ensure my instructions aren't completely bogus, although I suspect KiCAD itself would do that job better.)

KiCAD PCB files, on the other hand, are also text, but appear to be far too complex to generate programmatically. Which is a shame, because KiCAD defaults to dumping all the components directly on top of each other, requiring me to spend 20+ minutes tediously separating them out again so I can see what the hell I'm doing. (KiCAD has a nasty habit of trying to move the text rather than the component it's attached to, presumably just to make PCBs harder to design?)

Perhaps some day I'll manage to also automate the initial component layout; I suspect, as others have said, that the actual "PCB design" bit will always involve the GUI though.

\$\endgroup\$
2
  • \$\begingroup\$ It would be nice to hook one of graphviz's layout engines up to KiCAD for the initial placement. I've used graphviz to make LTspice files for very simple layouts and it worked reasonably well. \$\endgroup\$
    – pipe
    Jul 31, 2019 at 16:24
  • 3
    \$\begingroup\$ There are some tools in kicad to spread out the components initially, it's called "Global spread and place". To avoid moving text, I just usually disable the text layers for layout. After all one can see the text by clicking if needed. \$\endgroup\$
    – jpa
    Aug 1, 2019 at 8:32
4
\$\begingroup\$

I wouldn't recommend it, but if you really desire you can write PCB artwork yourself, without any PCB program. The code looks like this:

G90*
1 G70*
2 G54D10*
3 G01X0Y0D02*
4 X450Y330D01*
5 X455Y300D03*
6 G54D11*
7 Y250D03*
8 Y200D03*
9 Y150D03*
10 X0Y0D02*
11 M02*
12

The line numbers at far right are not part of the file. Examining this file without any prior knowledge of Gerber one would correctly deduce that each line represents a particular machine command and that the asterisk (*) is the end of command character. There seems to be different kinds of commands: instructions beginning with G, D, M and x,y coordinate data.

Source: https://www.artwork.com/gerber/appl2.htm

Here is a spec that shows the different commands

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Gerber (RS-274X) is related to the G-code (RS-274) files used in CNC programming. I do sometimes write G-code directly with a text editor for simple 2.5D tasks. \$\endgroup\$ Jul 31, 2019 at 15:39
  • 5
    \$\begingroup\$ Just an observation: if you are direct coding gerbers, then there is no design rule check taking place other than you visualizing in your head. I can't imagine typing out a text gerber file, sending it to fab house without ever opening the file in a GUI tool at just looking at it, unless you are a next level savant of some sort. \$\endgroup\$
    – user57037
    Jul 31, 2019 at 15:43
  • 1
    \$\begingroup\$ I wasn't sure if Gerber was related to G-code, but I had a suspicion. If one needed to write a simple top layer for an antenna or filter it might not be too bad to code something up yourself. I've only edited G-code, but never tried to write it. \$\endgroup\$
    – Voltage Spike
    Jul 31, 2019 at 15:44
  • 6
    \$\begingroup\$ Anyone who can work better with G-code than a visual tool of some sort for a complex board would definitely be an exceptional person. Anyone who can work directly in G-code and be productive would have to be considered a savant, I think. \$\endgroup\$
    – user57037
    Jul 31, 2019 at 15:55
  • 1
    \$\begingroup\$ I don't know all 7.5 billion people in the world, but I can say confidently there is not a single person in existence that would do a better job looking at gerber code than a graphical display for any serious, multi-layer professional-purpose boards. \$\endgroup\$ Jul 31, 2019 at 22:18
1
\$\begingroup\$

If you are using Kicad, see some of the videos from the talks at the first KiCon (2019) on Youtube. A couple of the talks were explicitly about the presenters writing tools to generate the parts, one also about the connections. At least one used python, which is baked in as a scripting language.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Could you please elaborate and add links to videos, and to the tools. (Waving towards a conference might be a worthwhile comment, but it doesn't quite qualify as an answer.) \$\endgroup\$ Aug 2, 2019 at 4:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.