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 v6 (version 5 works as well), 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 render the files that will be needed.

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, more recent, 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 (temp.png needs to re-written) 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.
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 (maybe TDOC as well). 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.

Alternatively, in Eagle v6, you could just export a monochrome image to the clipboard, then paste it into gimp. If you choose this method, specifiy a resolution of 250 dpi. A 250 dpi image seems to strike a good balance between image load time on the web server and image quality when rendering parts (the PHP script needs 250).



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 250dpi, 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... Rotate it to match the orientation that it had within the eagle board editor.

Now, use the rectangle select tool (TOOLS | SELECTION | RECTANGLE) and carefully mark out the area just inside the board dimension line. Copy this area of the image to a new image (FILE | NEW). This will give us an image of the board without the dimension outline.

We need to copy what is inside the dimension boundary as the X/Y co-ords of parts are relative to the base of board (lower left). Many times, parts will extend outside of the board dimension line(s) and this will upset the relationship between the board image and the actual board. Parts, in eagle, are given a location relative to the baseline, not relative to the leftmost+bottommost component / detail.

Switch to a 1 bit palette (IMAGE | MODE | INDEXED) and save as an XPM (FILE | SAVE AS).

Next we will colorize the image. Instead of using the painting tools of Gimp, let's take a shortcut for this. Use a text editor and edit the xpm file and 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.

In gimp, re-open the xpm file, 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).

Don't close the gimp image yet, you will probably have to make some minor changes to it to get the floodfill color to fill the image properly.


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. Edit this file to remove any parts that are not to be installed at this time, for example, any leaded parts that must be hand soldered.

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". Check to make sure any components you don't want to show up in the menu (e.g. through hole parts, etc) have been removed, if not, remove those from both of the two files. 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! Test by selecting each item to ensure it colorizes properly. Sometimes a diode symbol inside a part outline will be the only thing that colorizes and is hard to see. When that happens, return to the gimp and make a "notch" inside that diode symbol to "let the color out". Make sure that the "notch" is the same color as the base color of the board so that the floodfill will seek its way outside the inner symbol edges.


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".

If you don't know where the colorizing is starting from, edit the index.php file and turn on the $debugSpot. This will put a small yellow rectangle at the position where the color flood fill will begin. There are a few more debug vars, some of those you may find helpful?

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.

You will have to adjust the X/Y co-ordinates (postions.txt) of the flood fill location to get either a proper fill, or not spill color across the whole board image. The debugColorizePart variable can help give you some info as to where inside the image that the flood is starting from for each of the selected parts. Sometimes all it takes is adjusting the positional value of either X or Y by 10 units.



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 layout all the parts for the board into the bins, sorted according to height. It becomes simpler to just empty the trays, in sequence, after the paste has been applied. The placement operation goes so much faster when I don't have to search for plastic bags to unwrap and count out the parts!