DIRTY TUESDAY: Measure PCBs and create images from gerber files

in DirtyPCBs.com, site by Ian | 0 comments


A few months ago we started a private PCB website so our team can get cheap PCBs from a fab in China. Someone spilled the beans, and it hit Hack a Day, Hacker News, etc. We almost shut it down, but it was too much fun to hack and refine the process. Dirty Tuesday is a weekly post about our misadventures accidentally starting a PCB service. As a design shop with Seeed Studio doing fulfillment, we’ve never been on this side of the fence and want to share the terrifying experience.

Gerber files are simple text files that describe how to draw a PCB. Most CAD programs export to this common format, and any manufacturer can load them and make exactly the same board. They’re a publishing format though, it’s tough (and usually inappropriate) to make changes to a gerber directly.

Detecting missing files

Boards are submitted to DirtyPCBs as a ZIP archive of gerber files (or a Eagle .brd file, more on that another week). The system, written in PHP, opens the temporary file upload without actually extracting anything. It scans through the file names and catalogs the extensions. Missing drill files (.txt) and board outline files (.gml) are common. We used to reject these orders, but it’s a hassle for people to enter all their info again. Now we accept payment and then give a notice about the problem, new files can be uploaded directly on the order status page. That’s a much friendlier process, while also ensuring we make the sale as quickly as possible.

Measuring the board

Next, we get the board size to see if it fits the ordered size. We pass a file handle pointing to the board outline file (.gml) inside the .zip to a PCB measurement function. Our original function used this very simple code from Wayne and Layne, it just looks for the longest line on the board by comparing all the X/Y coordinates in the outline file. This works on about 60% of boards, but fails if the board doesn’t use a fixed 2.4 leading zero suppression decimal notation. Eventually Jonathan Georgino contributed a more advanced function that reads the gerber opcodes for decimal notation and type of zero suppression, accurate on 98% of boards. The measurement class is available on Github here.

Boards too big for the ordered size are flagged and held for review before we send them to the board house. The board house also checks the size against the ordered size. We don’t reject boards based on the measured size because text outside the outline can mess it up pretty bad. So far every mis-sized order emailed to make full payment before we even noticed the hold.

Creating a PCB image from gerbers

DirtyPCBs started as a convenient way to get cheap boards to our team. We knew every PCB going through and who it belonged to. When it blew up we asked the board house to put stickers on the outside of each package with the PCB ID number. Aaron at Oomlout quipped sarcastically that the sticker innovation would certainly solve the problem in a new and refreshing way. He was right. The board house packing department randomly put stickers on anything of the same color. We had to replace dozens of orders. Later we acquiesced and let the PCB manufacturer put a small ID number on the silk screen, just like every other cheap PCB supplier.


We still occasionally have boards without a number, or with the wrong number. We also need a way to instantly check if a board is the right color before we send it out. We set out to imitate the online gerber viewer Gerblook. Export each layer of the PCB as an image using gerbv, apply color, and create a composite image. Easier said than done.

Anything outside the PCB, such as notes or overhanging headers, throws that layer out of alignment. Gerbv has command line options to specify the origin of the export area, DPI and window size, but most boards don’t have clean lower left corners that start at X=0 Y=0. Many PCBs even have negative coordinates for the placement of the lower left corner. Even the top right corner can be a negative coordinate!

This is a problem already solved by Gerblook, so we wrote to Hadley for help. His solution is as brilliant as it is simple. When exporting a layer, include every other layer with the color set to transparent. Each layer is exported with perfect alignment to every other layer because they’re all included every time. Sorted.


With all the individual layers in hand, it’s time to color them and create the composite image. Our PHP script uses GD for this:

  1. Get board background color from image pixel 0,0. Despite our best efforts this is not always what we tell gerbv to output
  2. Change the background color to transparent
  3. Replace all the red (or whatever is closest to red, grrrbv!) with our desired color. This could be silver (HASL) or gold (ENIG) for pads, white for drill holes, etc
  4. Soldermask takes a bit of extra work as we need to color the outline first and then subtract all the holes in the mask where the HASL or ENIG pads will be
  5. Composite the layers together: outline, copper, solder mask, copper again faded a bit, silkscreen, drill holes


Using the copper under and over the mask makes it pop, like seeing the traces under the solder mask on a real PCB. The only major limitation of this method, shared by Gerblook, is that holes inside the outline layer (panelized boards, etc) will be colored and not transparent. We toyed with a method of walking from the top center of the board until we find the outline, then apply a fill to the interior of the board. This has promise, but wasn’t worth perfecting at the time.

When you order a board at DirtyPCBs you get an email with the composite board image attached. The status page also shows the top and bottom views. Images are nice for the buyer’s reference, but crucial to our backend packing crew. They double check every board, and find mislabeled/wrong color boards before they’re mailed. It’s not perfect, but it helps us catch problems before they become a bigger hassle.

DirtyPCBs’ gerber file check, measurement, and image output PHP script is here. It won’t work on cheap shared hosting as you’ll need root access to install gerbv.

Gerblook mentions eventually going open source on their website – turns out it already is. We will definitely swap to Gerblook’s Python scripts if we update DirtyPCBs in the future.


Video: Hack All The Things – 20 Devices in 45 Minutes

in hacks, reversed, Videos by the machinegeek | 0 comments

The GTVHacker group gave this presentation at DEFCON 22. The group is famous for Hacking the Google TV a few years back, and in this talk they add plenty of devices to their credit. “We’ve taken all of our previous experience exploiting embedded devices and used it to bring you a presentation filled with more exploits than ever before. This presentation will feature exploits for over 20 devices including but not limited to TVs, baby monitors, media streamers, network cameras, home automation devices, and VoIP gateways. Gain root on your devices, run unsigned kernels; it’s your hardware, it’s internet connected, and it’s horribly insecure.”

The presentation slides in PDF can be downloaded from GTVHackers.

Free fun flexible watch

in clock, open source by DP | 1 comment


F*watch team writes:

F*watch is a fully open electronic watch project featuring an integrated GPS receiver. The development started at CERN as an after-work project to make a special present for a retiring colleague who likes hiking and timing. The full design (electronics, mechanics and software) is available under free licenses and the design is exclusively made with free tools.

  • Sensors

-Pressure sensor
-Ambient light sensor

  • I/O

-128×128 pixels LCD with backlight
-Micro-USB connector, 4 Buttons
-Buzzer, vibrating motor
-MicroSD memory slot

  • Various

-500 mAh Lithium-ion battery, fuel gauge
-4-layer PCB

Via Hacked Gadgets.

Posted in clock, open source | Tagged , | 1 Comment

Digitally controlled bench PSU project update

in DIY, power supply by DP | 0 comments


Yet another update on Bertho’s digitally controlled bench PSU project we covered previously:

Did some test-bed assembling today and did a dry-test of the power board.
The good news… the power board did not blow up ;-)

The aux PSU for +/-12V analog and the 5V logic supply switcher is working as it should. The power board is able to supply the control board as far as I can see. Haven’t done any in-depth testing, but it looks good. The main low voltage AC inlet is also functional and the default of the power switcher is correctly off. The DC voltage after the rectifier was tested to 42V DC and no sparks or smoke were detected.
With the preliminary tests complete, I have now a small test-bed to continue working. The setup has the control board with LCD, 2 encoders (+ push switch) and 3 LEDs. All is powered from the power board aux supply…

App note: Power-supply solutions for Xilinx FPGAs

in app notes by DP | 0 comments


MAXIM’s power solution for Xilinx’ FPGAs. App note here (PDF!)

Field-programmable gate arrays (FPGAs) are used in a wide variety of applications and end markets, including digital signal processing, medical imaging, and high-performance computing. This application note outlines the issues related to powering FPGAs.


Free PCB Sunday: Pick your PCB

in Free PCBs by DP | 86 comments

buspiratev383 We go through a lot of prototype PCBs, and end up with lots of extras that we’ll never use. Every Sunday we give away a few PCBs from one of our past or future projects, or a related prototype. Our PCBs are made through Seeed Studio’s Fusion board service. This week two random commenters will get a coupon code for the free PCB drawer tomorrow morning. Pick your own PCB. You get unlimited free PCBs now – finish one and we’ll send you another! Don’t forget there’s free PCBs three times every week:

Continue reading →

Posted in Free PCBs | Tagged | 86 Comments

App note: Power supplies begin the circuit foundation, taming switching power-supply layout

in app notes by DP | 0 comments


A power supply design app note from MAXIM.

This article outlines power, ground PCB, and system layout hints and kinks. It includes an overview of using power, ground star points, and multifrequency power decoupling. It also shows how to control the component placement to minimize the size of the high-current switching loop.

App note: High speed amplifier techniques

in app notes by DP | 1 comment


An old but interesting app note (PDF!) from Linear on high speed amplifier techniques:

Most monolithic amplifiers have been relatively slow
devices. Wideband operation has been the province o
discrete and hybrid technologies. Some fast monolithic
amplifiers have been available, but the exotic and expensive
processing required has inflated costs, precluding
widespread acceptance. Additionally, many of the previous
monolithic designs were incapable of high precision and
prone to oscillation or untoward dynamics, making them
Recent processing and design advances have made inex-
pensive, precision wideband amplifiers practical. Figure 1
lists some amplifiers, along with a summary of their
characteristics. Reviewing this information reveals ex-
traordinarily wideband devices, with surprisingly good DC
characteristics. All of these amplifiers utilize standard op
amp architecture, except the LT1223 and LT1228, which
are so-called current mode feedback types (see Appendix
H, “About Current Mode Feedback”). It is clear that the raw
speed capabilities of these devices, combined with their
inherent flexibility as op amps, permit a wide range o
applications. What is required of the user is a familiarity
with the devices and respect for the requirements of high
speed circuitry.

Bus Pirate smart card shield

in Bus Pirate by DP | 0 comments


Bus Pirate smart card shield by Yaehob:

Tired of playing with wires, breadboard and so on to interface synchronous smart cards with bus pirate, I made a kind of shield. Thank you Arduino for teaching me this way of thinking :-)
Bill of materials

  • 1x breadboard solder
  • 1x smart card socket (e.g. this one, this one, or ebay : here and here)
  • 1x female header [2X5]
  • 3x pull-up resistors [2kΩ-10kΩ] (I added a piece of wire to connect them, or not)
  • Wire

Get your own handy Bus Pirate for $30, including world-wide shipping. Also available from our friendly distributors.

Free PCB coupon via Facebook to 2 random commenters

in Free PCBs by DP | 3 comments


Every Friday we give away some extra PCBs via Facebook. This post was announced on Facebook, and on Monday we’ll send coupon codes to two random commenters. More PCBs via Twitter on Tuesday and the blog every Sunday.

Don’t forget there’s free PCBs three times every week:

Continue reading →

Posted in Free PCBs | Tagged | 3 Comments

Week in (p)review October 17, 2014

in week in review by DP | 0 comments


Here’s a summary of major developments over the last week. Free PCB Friday is coming up soon.

Coming up:

  • Free PCBs via Facebook on Friday
  • App notes on the weekend
  • Free PCB Sunday
  • Free PCBs via Twitter on Tuesday
  • Weekly roundup and preview every Friday

DirtyPCB Yellow-Panel microgameboy

in DirtyPCBs.com by DP | 2 comments

In this video Stijn Kuipers demonstrates his Yellow-Panel microgameboy:

The recent DirtyPCBs.com paneling experiment resulted in a nice new addition to our prototyping toolbox.
The yellow panel contains:

  • Wolfsom SMT microphone breakout with small amplifier
  • QFN24-to-dip adapter
  • Freescale K20 TFT backpack (enhanced Teensy3.1 without the bootloaderchip)
  • Freescale KL02Z DIP breakout with microphone
  • USB-testpoint board in USBstick form
  • 0.49″ I2C OLED breakout board
  • 3.3v MIDI IO board
  • KL02Z micro-gameboy with 0.49″ OLED, microphone, switches and battery.
  • A this-is-not-rocketscience.nl keychain
Posted in DirtyPCBs.com | Tagged , | 2 Comments

DIY USB-Oscilloscope in a matchbox

in DIY, oscilloscope by DP | 0 comments


ajoyraman posted a tutorial on how to make a DIY USB-matchbox oscilloscope,  an instructable here:

In order to economize on the cost of an enclosure while still providing an aesthetic unit the Aj_Scope2 is enclosed in a large size cardboard matchbox enclosure.
The USB connection to the PC is on one end while the Audio-Jack for the signals to be monitored is on the other.
A ‘Busy’ LED is provided on one corner at the top and a ‘Reset’ switch is provided diagonally opposite.
The ‘Reset’ switch provides a restart of the micro-controller is the worst-case of hang-up. This typically occurs when the operator selects a trigger threshold which is out of limits with respect to the waveform being observed. If the Aj_Scope2 is operated correctly this switch is seldom used.

DIY LM1876 dual 20W audio power amplifier

in DIY by DP | 1 comment


An audio power amplifier based on LM1876 from Electro Labs:

We are building another enjoyable weekend DIY project. This is an audio power amplifier based on LM1876 which can deliver up to 20W per channel into 4 or 8 ohm load and guarantees less than 0.1% THD + N (Total Harmonic Distortion + Noise).
The amplifier is powered by -15 0 15 VAC symmetrical supply. The full bridge diode rectifier and the smoothing capacitors convert the AC input to ±21 VDC which is used to power LM1876. The inductors on the AC input line reduces the noise arising from the mains line.

Via Electronics Lab.

Posted in DIY | Tagged , , | 1 Comment

Measure audio level using root mean square on Spark Core

in library, measurement by DP | 0 comments


Davide Gironi writes:

A Spark.io library to retrive RMS and Spl value from an audio input.
This library reads data from an ADC pin and returns the RMS value of the input simply using RMS avarage.
The root mean square (abbreviated RMS or rms), also known as the quadratic mean, is a statistical measure of the magnitude of a varying quantity.
Here is simply implemented by getting samples, for each of them making the root, then the mean for all the collected samples, and finally square the result.

Code is available on GitHub.

Nokia 5110 screen module with PIC microcontroller and Oshonsoft

in library, PIC by DP | 0 comments


Chris Holden made a font library for a Nokia 5110 display using a PIC microcontroller and Oshonsoft. He writes:

Having left the 1980′s behind, we decided to write our own “libraries” to write text onto the Nokia 5100 display, using a PIC microcontroller. The code below was written for a 16F877a (because it was the first chip we found already on a breadboard, with a programming header connected) but would work equally well on any PIC microcontroller with enough RAM for the font table.