Time is flying by! There’s less than one month left in the Pi Chef Challenge. If you’re not familiar with my Cooker Connector project, have a look at my project proposal. An essential part of my project is a Printed Circuit Board for my Sensor Hub, and it will take a few weeks to get it manufactured. This post describes my experience designing the board.
Sensor Hub
I will be designing a Printed Circuit Board (PCB) for my Sensor Hub. This is the piece that connects the thermometer probes to the Raspberry Pi. I plan to mount the board on top of the Raspberry Pi, similar to how the official Pi HATs mount. This provides a strong mechanical connection to the Pi and a direct electrical connection as well. The circuit board will hold all of my electrical components, including the Analog-to-Digital Converter, the jacks for the temperature probes, and all of the circuitry to transform the signals and get them where they need to go. I also plan to plug the servos that control the air intake vents into the board.
Why a PCB?
A PCB makes any project more professional. Prototypes that are built on breadboards are easy and fast to build and to modify, but they are fragile because nothing is fixed into place. There are wires sticking out all over the thing, and the components have to be spread out in a line, so the space is much less efficient. Besides the practical and aesthetic aspects, breadboards also introduce a lot of noise into circuits, since there are high-frequency digital signals running nearby and parallel to analog signals. The breadboard itself has a lot of metal in it, which acts like an antenna that picks up interference from the environment. When you design your own PCB, you can pack your components into a smaller space, arrange them in a convenient layout, and you can make sure that sensitive circuits are isolated from noisy ones. Because they are so useful, nearly every electronic product in existence has at least one PCB inside.
PCB Manufacturing Process
Whereas a prototype circuit board has individual, flexible metal wires, the “printed” word in Printed Circuit Board refers to how the wires are drawn on its surfaces. This flat pattern of “printed” metal provides the same electrical connections as wires, but it is firmly attached to the board. Both sides of the board can be utilized, and in very complex boards, there even can be several layers of printed wires laminated together into a single board.
To start, a board made of rigid, non-conductive material is covered with a solid sheet of copper foil, which is laminated to its surface. Eventually, portions of this copper will be etched away by an etching solution, and the copper that remains will form the electrical pathways of your circuit board. The etching solution dissolves any copper with which it comes into contact, so the copper that you wish to keep must be protected from the solution. This is typically done by printing the design onto the copper with a material that won’t be affected by the etching solution. In a factory, the copper is coated with a photoresist material, and then the pattern of your circuit board is projected onto it with light. Wherever the light hits, the photoresist will bond to the copper, and wherever it is dark, the copper will be left exposed. Then, the etching solution is applied, and the undesired copper is dissolved, leaving behind the desired pattern.
This whole process is messy and requires a lot of materials and precision. It’s possible to do this yourself at home by printing the design on slick paper using a laser printer and then pressing the toner onto the copper with a clothing iron. However, this process takes some practice and it’s easier and more reliable to send your PCB design off to a company that can produce a perfect board for a reasonable price, so that’s what I’m doing for this project. Another benefit of having your board made for you is that you can provide them with a design for silk-screen printing so that you can have guidelines, shapes, and text on the surface of your PCB to show you where all of the components should be mounted.
Mounting the Components
Once the board is manufactured, the components can be mounted. There are two ways of doing this. One way is to solder the components directly to the exposed copper. This method is called “surface mounting”. The other method is called “through-hole mounting”, where holes are drilled through the board, and the components have leads that stick through the holes and get soldered to the copper. You need to decide which method you are going to use before you choose the specific components for your board, since you can’t use them interchangeably.
Surface-mounted components can be very small and therefore densely packed onto a PCB. However, mounting tiny components on a tiny board is more difficult and prone to error. If you have an expensive, specialized machine that can be trusted to carefully place and solder your surface-mounted components, then this is the better method. I, however, am a hobbyist that doesn’t need the space efficiency, and I do everything by hand, so I use through-hole components whenever I can.
EAGLE CAD
Before you can print the circuit board pattern, you have to design it. You’ll need some CAD software to do this. I use EAGLE because it’s a powerful tool that has loads of part libraries available, and it’s free for small-scale use. The symbolic interface is a little quirky and takes a long time to learn. For that reason, I’m not going to go into any detail on how to use it, but I would highly recommend buying a guide book and working all the way through it. I originally tried to teach myself through trial and error, and then I tried going through some online tutorials, but nothing compares to the value of a thoughtful, published physical book. The book I used is called Make Your Own PCBs with EAGLE: From Schematic Designs to Finished Boards by Simon Monk, and I highly recommend it.
When you use EAGLE, you design your PCB in two stages. The first stage is creating the schematic, and the second stage is laying out the actual board. The schematic is an abstracted, high-level functional specification, and the board design specifies every dimension of every component of the physical board. In the first stage, you choose the parts, place the symbols on the schematic drawing, and connect them together. Then, you flip over to board design mode, where you arrange the shapes of the physical components and route the wires between them.
Designing the Schematic
I started the schematic with the voltage divider I had previously designed. I then designed a voltage follower using an operational amplifier and hooked them together. This output is then fed into the ADC, and I added power supplies and grounds where appropriate.
Figure 1. Schematic of voltage divider, op-amp, and ADC.
During my earlier prototyping phase, I noticed a lot of noise in this circuit and found that some of the noise could be reduced by averaging in software. I wanted to reduce this noise even further in hardware, so I did some research on RC filters and ADCs. I found a helpful article that explained how the internals of an ADC work and how to design a filter to smooth out the high-frequency signals that were affecting my data. I used an oscilloscope to observe the noise and to measure the frequencies that were present. It looked like the signal had some considerable noise in the range of 75kHz.
Figure 2. Screenshot of oscilloscope showing noisy input.
Using this information, I designed a passive RC filter using this helpful website. I found a combination of resistor and capacitor that should reduce the noise in the 75kHz range by about 25dB. Testing the prototype, I found that my filter had a great effect!
Figure 3. Screenshot of oscilloscope showing the noisy input (magenta) and filtered input (dark blue).
Here’s what my schematic looked like after adding the RC filter.
Figure 4. Schematic detailing the added RC filter.
The schematic didn’t yet account for the fact that the thermistor was not actually part of the PCB. I was using a standard thermistor component as a stand-in, but the real thermistors will connect to the PCB using the mini headphone jacks I bought. I couldn’t find an EAGLE library that had that specific part, so I had to create my own library and make the part myself.
Creating a New Part
Because EAGLE separates the board schematic from the board layout, it similarly separates parts into two related domains: the “symbol” and the “package”. The symbol is used on the schematic, and the package is what appears on the board layout. To create a new part, you need to design both. Fortunately, an EAGLE library already had a headphone jack that was similar to the part I had purchased, so I was able to copy its symbol into my new part. That left only the package to design. I used the data sheet from Digi-Key to design the mechanical specifications, such as the placement of drilled holes, solder pads, and the silkscreen-printed outline of the part.
Figure 5. Mechanical drawing from the datasheet of the headphone jack.
The mechanical drawing was not consistent about the orientation of the part, so I had to be careful to interpret the drills drawing (Figure 5 above, left) as a top-down view and the dimensions drawing (above, right) as a bottom-up view.
Figure 6. The headphone jack package I created.
After creating my part, I swapped it in for the thermistor in my schematic. At this point, I had one completed channel. My Sensor Hub PCB is going to host four channels, so I copied the single channel three more times and connected everything up. I then added the header pins that would connect to the Raspberry Pi and wired up the ADC and power. I added some more header pins to connect the servo to power, ground, and the Pi’s PWM pin, and I also added a few bypass capacitors.
Now that my schematic satisfied my functional requirements, I took some time to consider any other helpful features that I might want. I realized that the servo was using the Raspberry Pi’s 5-volt power supply, but that may not provide enough current if I find that I need additional servos or more powerful ones. In this case, I would want to have an external power supply to power the servos. I decided to add a 5V power supply jack to my board and a pair of jumper pins so that I can choose whether to connect the servo power supply to the Pi’s supply pins or isolate it with its own external one. I also decided that an LED would be a good addition so that I could have some kind of status indicator to tell me if the Pi lost its internet connection.
Figure 7. Final schematic for my Sensor Hub including bonus features.
Board layout
Now that the schematic was done, I switched over to board layout mode in EAGLE. I want my board to attach to the top of the Raspberry Pi, so I used the mechanical drawings to determine where to place the header pins and holes so that they would line up with those of the Pi. I decided to include only two of the mounting holes on my board, so that I could trim off some board area. Fabrication services usually charge by the square inch, so by trimming off about a quarter inch, I saved a few bucks. The header pins should provide more than enough strength on that side of the board, so I’m not worried about losing the additional contact points.
After defining the fixed locations and edges of the board, I started placing the input jacks. They obviously needed to be along one side of the board with enough clearance around them to accommodate the thermistor probe plugs. Next, I positioned the external power supply jack on another edge, and then put the rest of the components on the board.
Figure 8. Initial board layout with arbitrarily-placed parts and air wires.
The fun part was next: fine-tuning the placement of the components and routing all of the wires. EAGLE draws “air wires” between all of the connections that need to be made. These are a tangled “rat’s nest” of overlapping lines to begin with, and as you complete a connection from one end of a line to the other, it disappears. Once all the air wires are gone, you know that you are done. EAGLE also has an auto-router feature that will attempt to draw all of the wires for you. It usually does a good job and only takes a few seconds to run, but I get a huge amount of joy and satisfaction from drawing wires myself. You can also choose to route some portions manually and have the auto-router do the rest for you. This is particularly useful if you have some sensitive signals, such as analog inputs, that you want to keep far from noisy signals, such as PWM or serial lines.
PCB Fabrication Services
There are lots of services that will make a small batch of boards for you if you send them your board layout. They all differ slightly in price, minimum quantity, shipping time, and quality. Usually, you need to export your design from EAGLE to Gerber files, which are sets of instructions for the machines that actually make the board. Exporting Gerbers is kind of a clunky process, and you kind of have to cross your fingers and hope it all works. However, someone recommended to me a manufacturer named OSH Park, and their website actually accepts EAGLE files without having to perform the export step. They even render a preview of your board before you order it, so you can spot any errors early. This seemed like a great idea to me, and it definitely helped me catch a few oddities in my silk-screen layer. When I created my custom headphone jack part, I somehow put some of the lines on the wrong layer, so some bits of the outline were on the back of the board and some were on the top.
Custom Graphics
I noticed a feature in EAGLE that enables you to import a bitmap of a logo and put it somewhere on your board. I wanted to try out this feature, so I decided to pay a little homage to the Pi Chef challenge on my board. I fired up GIMP and traced a vector path of the logo and exported a bitmap. EAGLE essentially scans across each row of pixels in the image and draws a thin rectangle shape on your board for each group of adjacent pixels that are the same color, so the result is a collection of hundreds of tiny slivers of your bitmap.
The import script is very picky about the format of the bitmap file, and it accepts only files that have 256 colors or fewer. This means that a bitmap exported from GIMP with the default settings will be rejected, even if the image is made up of only black and white pixels. It turns out that GIMP supports only 16- and 24-bit colors by default. To get around this, I had to change the image mode in GIMP to an indexed color map with only two colors. Once I finally got it imported, it was enormous and was about 10 times the size of my board. There’s no way to scale this kind of shape in EAGLE, so I had to try again. I had arbitrarily chosen a size and pixel density of the bitmap, so I had to think more carefully about these values. OSH Park had some recommendations about pixel size, so I had somewhere to start. It took some trial and error, and I uploaded my board several times to look at the preview on the website. I finally found that when you import a bitmap, you need to make sure that the pixel size you choose is greater than 5 mil per pixel or else it won’t render at all.
After spending far too long on this, I finally got the image imported and sized properly. I initially thought it would look neat as part of the silk-screen layer, but I think it looks way cooler if I move it to the top copper layer, so that the logo is actually etched into the copper and covered by the solder mask. It’s nice and subtle, and it looks good on the preview render.
Figure 9. Final PCB layout (left) and OSH Park preview rendering (right).
I gave the PCB layout one final look-over before ordering. It would be really disappointing to buy and wait for a board that has a flaw of some kind. For extra peace of mind, I test-fit the size and placement of the components by printing out the layout on a piece of paper and punching holes in it where they would be drilled. I was especially concerned about the dimensions of the custom part I made, but it turned out to be just right.
Figure 10. Test-fitting some components using a paper printout.
Over all, it’s going to cost me about $25 for a shipment of three copies of my board. OSH Park claims the boards will be ready in about 14 days, and I’m really excited to see how they turn out!
Top Comments