Monday, December 19, 2011

Building your own Arduino board with the "Sparkfun Arduino Compatible PTH Kit"

Some of you, like our students, are going to want to really "get under the hood" with microcontrollers and learn how to "build your own".  We've noticed that when you use microcontrollers "out of the box" it is hard to appreciate their components. We tend to use them as discrete objects and never really gain an appreciation for what makes one microcontroller different from another. We will say things like, "The Arduino Romeo is better for running a Sea Perch because it has 2 built-in motor controllers" but we don't really come to appreciate which components vary and which don't and what makes one Arduino board more suitable for a task than another.

By building your own basic Arduino board using the Sparkfun kit, you get to touch and mount and solder each component individually and this gives a real appreciation for what the components are and do and ultimately will enable you to build new custom boards and expand the capabilities of what these boards can do (to do all those cool robotic things that only your imagination can conceive of!).

If you are highly ambitious, you can make your own Printed Circuit Board (a.k.a. "PCB" or PC Board) from scratch, doing the design, etching and drilling yourself.  But for starters we will work with boards that are pre-wired and drilled and simply needs its components soldered on.  The Arduino Compatible PTH Kit is one such introductory kit.  It "gives you all the components you need to build your very own development platform. When you're done with this kit, " they say, "you'll not only have a fully-functioning microcontroller that can be used with Arduino code and software, but you'll also have a greater understanding of how your development platform works. This kit is built with the beginner in mind and features only through-hole soldering."

The kit includes:

  • 1x ATmega328
  • 1x28-pin socket
  • 2x6-pin female headers
  • 2x8-pin female headers
  • 1x6-pin right-angle male header
  • 1x momentary push button
  • 1x 5mm green LED
  • 2x 330 Ohm resistors
  • 1x 10k Ohm resistor
  • 1x 16MHz crystal
  • 2x 22pF ceramic capacitors
  • 5x 0.1uF ceramic capacitors
  • 2x 100uF electrolytic capacitors
  • 1x 1N4001 diode
  • 1x MCP1700 3.3V regulator
  • 1x PTC
  • 1x barrel jack connector
  • 1x Arduino Compatible PTH Kit PCB
(Note that here PTH stands for "Pin Through Hole")

To solder a PC Board that is a pre-drilled "PTH", like the one that Sparkfun supplies, we want to be careful not to overheat the back of the board.  If you are using an inexpensive soldering iron, the recommendation is to stay within 10 Watts to 30 Watts so as not to damage the board or components.  For a more expensive soldering iron with adjustable temperature, like the Weller WES51 that we are using, we dial the Fx10 (degrees Fahrenheit x 10) control to between 60 and 65.  This is because "The melting point of most solder is in the region of 188°C (370°F) and the iron tip temperature is typically 330°C to 350°C (626°F to 662°F)."

The site tells us,
"...ensure that the temperature of all the parts is raised to roughly the same level before applying solder. Imagine, for instance, trying to solder a resistor into place on a printed circuit board: it's far better to heat both the copper PCB and the resistor lead at the same time before applying solder, so that the solder will flow much more readily over the joint. Heating one part but not the other is far less satisfactory joint, so strive to ensure that the iron is in contact with all the components first, before touching the solder to it...  the joint should be heated with the bit for just the right amount of time -- during which a short length of solder is applied to the joint. Do not use the iron to carry molten solder over to the joint! Excessive time will damage the component and perhaps the circuit board copper foil too! Heat the joint with the tip of the iron, then continue heating whilst applying solder, then remove the iron and allow the joint to cool. This should take only a few seconds, with experience. The heating period depends on the temperature of your iron and size of the joint -- and larger parts need more heat than smaller ones -- but some parts (semiconductor diodes, transistors and integrated circuits), are sensitive to heat and should not be heated for more than a few seconds. Novices sometimes buy a small clip-on heat-shunt, which resembles a pair of aluminium tweezers. In the case of, say, a transistor, the shunt is attached to one of the leads near to the transistor's body. Any excess heat then diverts up the heat shunt instead of into the transistor junction, thereby saving the device from over-heating. Beginners find them reassuring until they've gained more experience."

 Our electronics wizard at Motion Picture Marine, Mark Volivar, keeps his Weller WES51 at 75 (750 degrees F) because "if you keep it at a lower temperature you will be tempted to keep the iron on the component lead longer and then you risk damaging the component or board.  If you keep it hotter you heat the component to the desired temperature quicker and can get in and out fast".

A good illustrated tutorial for soldering PCB boards is found here:
This site has a nice short video showing the proper technique.
They say,
"If you see the area under the pad starting to bubble, stop heating and remove the soldering iron because you are overheating the pad and it is in danger of lifting. Let it cool, then carefully heat it again for much less time. "

As I solder the components on the board I lay my blue Arduino Uno, purchased from Sparkfun, next to the characteristic red  Sparkfun "Adunio Uno Compatible PTH Kit" board, to see what the differences are.  The most obvious, of course, is the color, but beyond that there are big differences. What is similar about them is what strikes the eye:  the size and shape of the board and the number and location of input and output pins along hte sides of the boards.  It is these that allow one to use shields made for the one on the other.

Let's see, as I solder each component on the Arduino clone (the PTH kit board), how it compares with the original.

The first thing I solder on are the Right Angle to 6 pin male Header pins.  These seem to go where the USB jack is located on the Arduino Uno. The pin assignments on the clone board are "DTR, TX-0, RX-I, 5V, GND and GND".  We will work on understanding the relation of these pins to the USB mounted jack later on; what is nice is that this project of building an arduino may help demystify the function and pin assignments of USB jacks.

The second and third part of the assembly are the two 330 ohm resistors and the single 10 kilo-ohm resistor.  These are hard to distinguish in the Arduino Uno board, but there seem to be tiny microresistors in the correct locations near the micro-LED lights for L and ON.

Step 4 is the 22pF Capacitor, which are not to be confused by the 0.1 microFaraday capacitors (they look alike, so read the printed label on the mustard colored body).  There are two to be installed.  If your eyes are as bad as mine you will need a magnifying glass to see the labels (I use one for all my soldering too, one on a stand with clips sold in many electronics stores).  Note that the capacitors (sometimes called simply "caps") are labeled on both sides, so don't get confused. The one's we want here say "220" on one side and "K2J" on the other.

 On the Arduino Uno I can't seem to find an easy visual equivalent for these two caps, which surround a spot meant for a 16MHz Crystal component located above the primary IC. There is a tiny soldered component above what looks like a silver metal slug (and to the left of the reset push button) so maybe that is the equivalent.

In Step 5 you install the five 0.1 microFarad caps.  They have "104" on one side and "K5M" on the other.
If what I think are the micro-capacitors on the Uno are indeed that, then one can sort of see the correspondence between the two boards...

In Step 6 you install a 1N4001 Diode and this you have to pay careful attention to because it is polarized, meaning the plus side and minus sides have to be installed facing the right direction.  The silver band on the diode can fortunately be lined up with the white line on the PCB.  I'm believing that the black rectangle with the letters M7 etched on it is the Uno equivalent.

Step 7 is the installation of the LM7805 5V Regulator.  The tutorial that comes with the kit tells us to "bend all three legs at a 90 degree angle so they point toward the back of the chip. Insert the regulator matching it up with the white outline on the PCB; the metal side of the regulator should be touching the board."  I couldn't get the hole in the regulator to line up exactly with the hole in the board, but it seems okay.
The equivalent on the Uno board is fairly obvious because of the three legs.

Step 8 is the MCP1700 3.3V Regulator.  Hard to tell what on the Uno board is the equivalent. It might be the yellowish larger rectangle at the edge of the baord next to the 5V regulator that says 2005 on it, or it could be the tiny rectangular black box under it.

Step 9 involves inserting the 16MHz Crystal in the center of the board. This looks identical to the silver metal cased oval on the Uno board, only it is in a different location.

It is nice that the instruction manual makes clear which components have polarity (indicated in yellow on the schematic) and which don't (indicated in green on the schematic) so that we don't have to worry when installing something like the 16MHz crystal (which can be installed in either direction). This attention to detail and fool-proof assembly through color and clear descriptions will be critical to any kit we develop too so that students are not only free from intimidation but so that a project doesn't get derailed because of a simple error in assembly destroying a board which would be expensive in time and money for an at risk school to replace.

Step 10 is the Reset Button.  It doesn't seem to matter which way you insert it as long as you do it gently (it is indicated in green!).  The reset button has a direct visual equivalent on the same location of the Uno board (the only difference is that the Uno reset seems to have 5 pins and the one on the clone only 4).

Step 11 is a resettable fuse (called a PTC which stands for "positive temperature coefficient").
Sparkfun says these components can protect your board from disaster:

"This is a handy little device that can save your system from smoking. A resettable fuse (also known as a PTC) is a resistor that has very unique properties ... For this model, if your circuit tries to draw more than 250mA of current (if you have a bad short for instance) the PTC would 'trip' (by heating up). The increased resistance (trip state) would break the circuit and allow only a small leakage current."

The general class of components of this type is a "thermistor" (a combination of "thermal" and "resistor"). Wikipedia tells us, "Thermistors can be classified into two types, depending on the sign of k. If k is positive, the resistance increases with increasing temperature, and the device is called a positive temperature coefficient (PTC) thermistor, or posistor. If k is negative, the resistance decreases with increasing temperature, and the device is called a negative temperature coefficient (NTC) thermistor."

The instruction manual says to "push it down as far as it will go" but the PTC has kinky looking spider legs with bends in them and these seem to inhibit pushing down very far unless you are willing to straighten the kink out.  My thought is that the bends in the legs must be there for a reason, so for now I am only pushing the thermistor down to the kink in the leg.

There doesn't seem to be an obvious equivalent on the Uno unless it is the black rectangle that I took to be the diode. 

In step 12 we mount the 8-pin and 6-pin female headers on the top and bottom sides of the board. These are identical to what we find on the Uno, being the input and output headers for both digital and analog pins and power pins; this is what you also mount arduino shields onto.

In step 13 we insert the red and green LED's.  These are polarized so we must carefully observe where we place the positive lead (the long lead) and the negative lead (the short one which is on the flat side of the plastic bulb casing -- you can find it by rolling the LED until it stands still on the flat side).  Because the PTH kit board doesn't indicate positive or negative, you use the white markings on the PCB to align the flat side (so that the shorter negative lead is facing the reset button and the 6-pin female headers side of the board.)

On the Uno board the LEDs for ON and STATUS (L) are in identical places on the board; they are just much much smaller, appearing as tiny rectangles.  The Uno also has two more LED indicators underneath the L LED; these are labelled TX, for transmit, and RX, for receive, respectively. They tell us when the board is communicating with the computer when uploading information or downloading sketches.

Step 14 involves putting the barrel jack on the board. The pins go through three fairly large holes and the instructions say "you may have to use a little extra solder on this part.  From looking at the comparable part on the Uno it seems you should fill in the entire hole. That really does take a lot of solder!

Step 15, soldering the 28 pin socket, involved putting a ballpoint pen under the socket to keep it in place while soldering and being careful while doing all 28 pins not to let the solder bleed from one pin to another.  It is good that they have you attempt this part at the end so that you have built up a lot of experience soldering PC boards before attempting this.  The temptation of somebody not involved in education would be to have people solder the socket on at the beginning because it would be easier to hold it in place without the female pin headers and other components sticking out.  By the way, this component is polarized -- make sure the notch on the socket lines up with the white line notch marked on the board.
The Uno board has an IC in the same place but it is a tiny square rather than the large 28 pin arthropod looking thing supplied for the clone.

Step 16 involves putting the polarized 100 uF capacitors in place; they must be placed with the gold stripe (the shorter lead) facing the barrel jack -- this is easily done because the board is marked with a minus sign on the left side of the markings (left if the barrel jack is to the left).  On the Uno the caps are much shorter but are in the same location.

The last step is aligning and pushing in the ATmega328 chip.  You want the notch marked  at the end with the A6/A5 marked on it (it says "UNO" under it) to line up with the notch at the end of the board (the side farthest from the barrel jack).  Conveniently the chip has a white label strip on it with indicators for what each pin is (A6, D0, D1, D2, D3, D4, VCC, GND, X1, X2, D5, D6, D7, D8 on the top side (the side facing the reset button and LED's) and A5, A4, A3, A2, A1, A0, GND, AREF, AVCC, D13, D12, D11, D10 and D9 on the bottom side (facing the 6 pin female headers).

You have to be careful as you "bend the legs slightly inward" to plug it in. As they say, "be gentle, don't force it" and rock it in place.

Voila. Done.

Interestingly, the board does have 6 holes labeled ISP on the side with the reset button, but nothing to populate them with (and the schematic in the instructions doesn't show them at all).  Meanwhile, the Arduino Uno itself has these holes populated by six male pin headers and labels them ICSP.  Also, on the Uno board the same six pin male headers can be found on the side where the USB connector is, next the the 8 pin female header labeled AREF.  So the Uno has extra functionality that our clone does not have (including what look like to microchips the clone lacks, one a square one above the crystal and next to the Tx and Rx LEDs and aother below the crystal.  As we say in Egypt, "Ma'alaysh".  No problem. We've built our first Arduino clone board and learned to compare it with the Uno.   Fun times. Now all we have to do is test it out to make sure there are no short circuits before trying to run some sketches on it.

Thanks for joining us!


Testing the Arduino clone:  I used a voltmeter with continuity alarm to see if any of the solder joints I made are touching by mistake.  Everything looks good. Two of the barrel jack leads (the ones at the edges of the board) are connected but this is true of the pro-Uno board too so it seems I'm okay.  Now I just have to figure out how to connect the board to the computer since it doesn't have USB. 

The instructions say that "to power the Arduino a DC power source between 6V and 15V should be plugged into the barrel jack. A standard 9V Wall Adapter power supply would be perfect".  I'm used to getting power from the USB on the Uno so I'll have to look around for an adaptor. But this still won't solve the computer connection.

The instructions have the answer, telling me "To load a new program onto the Arduino, you'll need one more piece of hardware -- a 5V FTDI Basic Breakout board.  One side of the FTDI Breakout connects via USB to your computer, while the other side connects to the right angle 6-pn male header on your kit (which was the first component we soldered on).  When you connect the FTDI Breakout to your arduino, make sure to line up the 'blk' and 'grn' labels. The FTDI Breakout can also be used to power your Arduino. If you haven't already, you'll need to install drivers for the FTDI Basic Breakout board." Then it tells us that we need to select the correct port under "Tools>Serial Port" and under "Tools>Board" (we select 'Arduino Uno' since this is a clone). Then we can load new sketches.

Fortunately the ATmega328 apparently comes preloaded with the classic "Blink" sketch so to see if my board is correctly assembled, all I need to do is power it up via the barrel jack.

To program your Arduino visually, look at (based on the Scratch environment).
See this article

(To enable your Android phone to talk to Arduino:
On Android, go to google search, type in Amarino, when the google search comes up click on download. 
Download the apk file to your android phone.  It will appear in the downloads folder. Click on it to install it to your phone (you may have to enable your device to install applications that aren't from the Android market). )

Project Lead the Way STEM program: