Close

part 3 of n

A project log for Eagle parts, by family, using python

A quick collection of python scripts to make a whole family of parametric parts in eagle.

bveinabveina 04/22/2017 at 04:250 Comments

The humble header device in eagle.


If you've made your own components in EAGLE you already know the process, if you havent (you should), there are 3 basic steps

  1. make footprint (for pcb)
  2. make symbol (for schematic)
  3. connect them pin to pin to make a device

multiple footprints can be connected to a single symbol. and this is handy for many reasons. By the end of the last log i had made 5 variants for each of 20 different pin counts. That's a lot of pin to pin connections. Naturally Im going to want to script this as well.

the overall approach is the same as making footprints, but the EAGLE commands get a little more involved.

basic psudo code first:

for each pinCount from 2 to 20:
  delete old device
  create new device
  add schematic symbol
  for each footprint
    create a device 'variant'
    connect the pins 1-to-1

first off how to delete and create devices?

REMOVE deviceName;
ADD deviceName;

well that settles that. i settled on a very generic HeaderNN where NN is the number of pins, zero padded.


I thought that adding the schematic symbol would be harder than it turned out to be. turns out to be relatively straightforward. as long as your not too picky about your origin point.

ADD deviceName (0 0);

all of this requires a bit of careful object naming.

Devices: HEADERnn

Symbols: Hn

Packages: see previous post insanity...

so the code to create all the package variants is:

nameTemplates = {"SABN":"G*C{0:02d}SABN-M30",
                 "AB":"XX*C0{0:02d}ABC-M30RC",
                 "FB":"XX*C0{0:02d}FBC-M30RC",
                 "ZS":"XX*C0{0:02d}ZSC-M30RC",
                 "ZT":"XX*C0{0:02d}ZTC-M30RC"}
cmd1="""remove header{0:02d}.dev;
        edit header{0:02d}.dev;
        add H{0:d} (0 0);"""
cmd2="package {0} {1};"
myCMDs=[]
for p in range(2,20+1):
  myCMDs.append(cmd1.format(p))
  for typeKey,typeVal in nameTemplates.items():
    myCMDs.append(cmd2.format(typeVal.format(p),typeKey))

This adds in the package command. every package must have a "variant" name. this helps differentiate parts. I created a dictionary with my "variant" as the key and the package name for that variant as the value. This tells EAGLE to have all 5 variants available for use with one schematic symbol. They still need to be connected pin to pin.

Connection is simplified by the naming scheme on both the devices and the footprints. i use the numbers 1-20, period.

the EAGLE command "CONNECT" lets you connect multiple pins with a single command, due to my clever naming scheme, to connect a 4 pin variant the command is

CONNECT 1 1 2 2 3 3 4 4 

in python i can build the command for any number of pins as:

connectCMD="connect "
    for x in range(1,p+1):
      connectCMD+="{0} {0} ".format(x)

this is not optimal string handling in python, but

At this point i can see the finish line, lets get this done!

nameTemplates = {"SABN":"G*C{0:02d}SABN-M30","AB":"XX*C0{0:02d}ABC-M30RC","FB":"XX*C0{0:02d}FBC-M30RC","ZS":"XX*C0{0:02d}ZSC-M30RC","ZT":"XX*C0{0:02d}ZTC-M30RC"}

cmd1="remove header{0:02d}.dev;edit header{0:02d}.dev;add H{0:d} (0 0);"
cmd2="package {0} {1};"

myCMDs=[]
for p in range(2,20+1):
  myCMDs.append(cmd1.format(p))
  for typeKey,typeVal in nameTemplates.items():
    myCMDs.append(cmd2.format(typeVal.format(p),typeKey))
    connectCMD="connect "
    for x in range(1,p+1):
      connectCMD+="{0} {0} ".format(x)
    myCMDs.append(connectCMD)

    myCMDs.append("write")
      
with open("test.scr","wt") as f:  
  for x in myCMDs:
    f.write(x+"\n")

and with that i now have all my variants nicely setup:

This wraps up this build log. I've posted the scripts in the files section and i hope this inspires someone to make other scripts to deal with product families that are parametrically similar.

I may tackle double row headers in a later post.

Discussions