Parts Placement Guide

One of the most grueling aspects of putting together a surface mount board is that of locating where all those little parts are to go! Not only that, but getting all the parts lined up before you start so you are not fumbling to open packages.

The first board I built took me an hour and a half to put parts on the each of the two boards! I was groping around looking for the next package to tear open and then to find where the parts where suppose to go on the board.

As EagleCAD has a scripting language, and I have an apache server available, I decided to build an series of scripts to produce an HTML based placement guide. Check out this demo of the resulting placement guide.' Cool, huh?

The rest of this page will detail how I use Gimp and Eagle, plus some perl scripts and a text editor, to create my board placement guide. It is assumed that you are familiar with Gimp, enough so that you can do simple image manipulation. It will also be assumed that you have an apache server available to put the files I am to give you.

I will detail the operation of building the page content, not how to use Gimp or to configure apache.


TopGetting started, setup apache and PHP

My server has been running for a while now with virtual domains. For myself, I just created another virtual domain to render my board "pages". The index.php script was written for PHP version 5.0.4. You will need to install the PHP gd module ('php-gd-5.0.4'), there may be some other PHP modules missing from your configuration. Use this tarball of my demo and use that to test your setup, and get the basic files into place for apache.

Also get this tarball of the necessary scripts that will be used to manipulate and generate the needed data files.

Make sure that you make all files in the "demo" directory owned by the apache user. The PHP scripts need to have write priviliges in that directory to manipulate the image file (colorize the parts) so you may want to make the directory owned, and write-able, by the apache user.


TopCreate the basic files from EagleCAD

We will create two files using EagleCAD, so, run eagle now and open your project, switch to the board layout. It is important that the lower left corner of your dimension line is at 0,0. It cannot be more or less than that as the PHP script has to invert the eagle X/Y co-ordinates to match the PNG co-ordinates.

Run my "dumpBoardData.ulp" from the "File | Run" menu. This will create a file, in the project directory, named "board-data.txt". The "board-data.txt" contains the components: NAME, FOOTPRINT, VALUE, X-POSITION, and Y-POSITION. From this data, we will generate the needed files.

Next, within eagle, print a postscript file of the board image. Turn off any layers that are not needed, you will want only the: DIMENSION, TNAMES, and TPLACE layers. Do not enable any other layers, and definately not the TORIGINS layer!!! From the menu: "File | Print", select 'BLACK' and 'SOLID', press and choose the "Print to file", 'print.ps' is fine. Leave "Print in grayscale" selected. Go ahead and print the board to the postscript file now.


TopUsing Gimp to: Crop, Colorize and Translate

The title here just about summarizes what to do next. The postscript image read into gimp, "File | Open" the 'print.ps'. Use a resolution of 500dpi, Coloring set to "B/W", "Bounding Box", Aliasing "NONE", and AnitAliasing "NONE". Don't bother the Width & Height values. Choose OK.

Your image should come in now... Now, crop the image with "Image | AutoCrop". Then, rotate the image to match how it was oriented in the eagle layout with "Image | Transform | Rotate ...".

Next we will colorize the image. Instead of using the painting tools of Gimp, let's take a shortcut for this. Do a "File | Save", save it as 'image.xpm'. Use a text editor and edit 'imagpe.xpm', change the color field for WHITE (the spaces) from #FFFFFF to #8000FF (you can mess with color later, for now use this one), save the file out.

Re-open 'image.xpm', the WHITE color should now be a violet-blue. Save this image as 'image.png' ("File | SaveAs"), the png format is needed for the PHP script in apache.

Copy 'image.png' into that demo directory of the apache server. Give the server a try from your browser and you should see your board as it looked from eagle (orientation is most important).


TopExtract Parts Data

Colorizing the chosen parts will need to know where the part is within the PNG file. I use a floodfill (actually fill color) to fill the inside area of the parts with YELLOW.

Copy the file "board-data.txt" that was created when eagle ran the "dumpBoardData.ulp" program into that demo directory. Here comes the "fun" part, not all of this process is automated.

Cat the "board-data.txt" into the "extract-board-data-textfile.pl" script with cat board-data.txt | ./extract-board-data-textfile.pl. This will have created two files: "parts-data.txt" and "positions-data.txt". The "parts-data.txt" will populate the listbox of the form and be used to create the bin numbers for the parts (more on that later). For now, look at the format of this file, and the real "parts.txt" file. The format is very simple "Value | footprint | Name", the "parts.txt" file does have groupings that start with "-". Make sure all lines have those three fields, it is very possible that the Value field can be empty!

Anyway, remove any blank lines from "parts-data.txt" and "positions-data.txt". Also, remove any components you don't want to show up in the menu (e.g. through hole parts, etc). Next, organize the "parts-data.txt" file into the sequence that you will use to put those parts on the board. I like to add them from the shortest to the tallest parts: ICs first, then resistors and caps, then sockets, etc.. You can add any menu seperators by putting a dash "-" as the first character on the line. When done, copy "parts-data.txt" to "parts.txt" and "positions-data.txt" to "positions.txt".

One more step and then we are done: error checking! Run the "checkparts.pl" script to make sure both files cross-reference each other. Correct any problems reported.

Try it out and see how your board guide works. Try all the parts to ensure they are properly shown, nothing like being in the middle of an assembly to find an oops!


TopWhat to do when it goes wrong

And it usually does at first, there is always some tweaking needed.

Most problems with colorizing is the color is locked inside a tiny area. This happens a lot with diodes, that little triangle area isn't big enough to see well when it is filled with color. To correct this, edit your "image.png" using gimp and erase a litte of one triangle side to "let the color spill out".

You can see this exact problem, of color being trapped, in the demo that I set up. For example, select any of the oscillators.

While we are on the subject of spilling color, sometimes you will have it where the whole board will fill with color. In such a case, look for a component with an incomplete silk outline. Repair this using Gimp.


TopMaking a bin list

Another script, "make-binlist.pl" will read the "parts.txt" and create a list of the parts to place into trays. For this, I found some plastic parts trays at Home Depot that work well. Prior to starting the paste operation, I will unpackage all the parts I will need an lay them out into these trays. When the paste has been applied, it is now a simple matter to sequentially empty the trays. No more packages to unwrap!