Creating a PCB name plate using Python and Diptrace

After moving into my new office at Contact Amsterdam, I wanted to make a nice name plate showing passers-by my name and how to contact me if I’m not in the office at the moment. Of course, it would be nice if the plate also gives a hint of what I actually do. So, I decided to design a PCB with my name on it, an use that as a name plate.

Making a blank PCB and adding some text is super easy in DipTrace. But I thought it would be cool to add some traces. However, adding a lot of traces sounds like work. So instead of spending hours drawing a lot of traces that look nice, I decided to spend many more hours writing a Python script that generates random PCB traces for me.

I made a first draft of what it should look like in DipTrace and exported the file to the DipTrace ASCII format.

Looking at the exported ASCII file it looked pretty accessible, it’s basically an XML file with the straight brackets replaced by normal braces. So I needed to do two things:

1. Generate a bunch of nice looking PCB traces in Python
2. Translate the data structure in Python into the DipTrace ASCII format

Generating traces, first attempt

Starting with the first task, I fired up a Jupyter notebook and started trying some things out. I started out with a function that simply generates a random number of randomly positioned points within the PCB area and draws a line between them.

It worked, but it looked pretty terrible. So I tried to make the lines so they only run at multiples of 45 degrees to more resemble actual PCB traces. This turned out to be a bit harder than I expected, as you cannot simply take two points anymore. You have to make sure they lie on the same line.

After I figured out how to generate these lines, the output started to look kind of interesting. On a real PCB the lines should of course never cross, but I thought I’d give it a try anyway and just create a first PCB file to see how it looks.

Translating into DipTrace ASCII

I set out to create a function that translates these lines into the DipTrace ASCII format. After some messing around, I got it to work. Turns out you have to multiply all the x-coordinates by 3, and all the y-coordinates by -3 to go from mm to whatever unit DipTrace uses internally.

So I managed to translate the lines into DipTrace, but it still wasn’t very pretty. The traces still didn’t look like normal PCB traces at all. It was time for a new approach.

Using the DipTrace autorouter

Instead of generating the actual traces in Python, I thought I’d leverage some of the power that DipTrace already has in it. I generated a PCB that just contains a bunch of pads connected to different nets. That way, I would be able to let the DipTrace autorouter do the work for me and I wouldn’t need to worry about how to generate traces that look like actual traces. This turned out to be a bit harder than expected, as the DipTrace format was a bit confusing and there is no documentation available. After almost a full day of reverse engineering the XML format, I managed to generate some PCBs and I was able to let DipTrace route the board. I then simply deleted all the pads and traces where I wanted to place text and added some text and drill holes.

This was starting to look kinda cool! So I sent the gerbers out to PCBWay for manufacturing and about a week later, I got 5 PCBs in the mail.

The resulting PCBs look pretty good and I’m very happy with the result. All code is available on Github. Feel free to contact me with any questions or remarks.

How does mp3 compression sound?

I wrote a small script in Jupyter notebook that compresses a audio file over and over again to make the effect of MP3 compression (more easily) audible. The compression is done using the LAME encoder, a compiled binary of which can be found here. The compression level is set to v5 which is a variable bitrate level with an average of 130 $$kbit/s$$.

I ran the script on a track that I made myself (to avoid any copyright issues). After a few rounds, the effect is already clearly audible. After a few more, the audio starts to sound really bad. After a hundred rounds, the audio sounds terrible with loud hisses of white noise. After a thousand rounds, almost only white noise remains.

You can listen to the audio below (1998 distant keys is the name of the original track). The full track can be found on Soundcloud.

Interestingly, the size of the compressed files goes up at first and only then starts to go down and keeps going down. The first file is, however, still way smaller than the original file, which is about 5 MB.

The code for compressing the files can be found below. To run it you’ll need Jupyter notebook or if you have Python but not Jupyter, you can simply copy the code from the blocks into a single *.py file and run that. You’ll also need the LAME encoder.