Chapter 15

Understanding Circuits

IN THIS CHAPTER

check Discovering what a circuit is

check Getting familiar with GPIO

check Coming to grips with a soldering iron

check Looking at ready-made add-on boards

Part 5 of this book deals with what is known as physical computing, or making your program reach out beyond the confines of keyboard and screen and into the physical world. You discover how you can use your Scratch and Python programming skills to sense what is happening in the outside world and to control lights, motors, and, in fact, anything else that uses electricity. However, before you can do this safely, without risking damage to you or your Pi, you need to look at a little bit of background electrical theory so that you have a foundation to build on.

In this chapter, we show you the relevant concepts that allow you to understand why the projects look like they do and what you should avoid doing. Next, we introduce you to the concept of GPIO connections, explain what they are, and look at why they are included in the Raspberry Pi computer. We also discuss in general how you can use them.

Although you can make the projects in Chapter 16 without soldering, in order to make most things in electronics, you have to be able to use a soldering iron. We show you how to go about this and discuss safety concerns. Finally, we introduce you to the concept of ready-made add-on boards because they can make building stuff a lot simpler (albeit at the cost of a bit more money).

Discovering What a Circuit Is

The first thing you have to understand is that a circuit is something where electricity can flow; it is a path, or a conduit. It is continuous; that is, it's a loop with no dead ends. If you have a dead end, you don’t have a circuit. Electricity has to be able to flow. So let's be more specific in what we mean by electricity. It can be complex stuff and because it's invisible, you have to do a bit of imagining to appreciate what is going on.

There are two aspects of electricity: current and voltage:

  • Current is what actually flows.
  • Voltage is what forces the current round a circuit.

Voltage can't flow and current doesn't exist in the absence of a voltage. However, voltage can exist in the absence of current. You've no doubt felt the effects of static electricity, which is the build-up of voltage that occurs when insulators (materials that don’t normally conduct electricity) are rubbed together.

It's kind of like how rubbing a balloon on wool can make the hairs on the back of your hand stand up. You can feel it, but only because you feel your hairs being lifted. You aren't feeling the electricity itself. You only feel static electricity when it stops being static and a current flows. At a very high voltage, a little current can hurt a lot. You've probably felt the static-discharge shock of touching a metal object after walking on a nylon carpet.

Understanding the nature of electricity

So, what is electric current? It is a flow of electrons past a point, just like a flow of cars past a motorway sign. With electric circuits, you measure current in amps. One amp of current is about 6.24 × 1018 electrons per second passing a point, or 624 followed by 16 zeros. That’s a big number, and, fortunately, we don’t have to count all those zeroes. The bigger the voltage, the more current is forced through a circuit, but circuits have a property that resists the flow of current. We call this the resistance of a circuit. This resistance depends on the materials the circuit is made from and is measured in a unit called ohms. So, because we know how to define an amp in terms of electron flow, we can define these other two properties in terms of an amp:

One volt is the voltage you need to drive one amp through a circuit with a resistance of one ohm.

You can advance a long way in electronics by knowing just that single fact. In fact, that definition is contained in what is known as Ohm's law:

Volts = Amps × Ohms

However, it would be too easy to just use that as a formula. People would understand it straight off, and that would never do! You have to build up a mystique. Imagine how you would feel about a doctor if he actually told you in plain English what was wrong with you. No, it needs to be dressed up so that not everyone can understand it. Ohm's law becomes

E = I × R

where E is the electromotive force measured in volts, I is the current measured in amps, and R is the resistance measured in ohms.

This is the formula you see in books and all over the Internet, but remember — it's just

voltage = current × resistance

Connecting things to the Raspberry Pi involves juggling voltage and current, and often you need to use a resistor to limit the current a voltage pushes through a device in a circuit. Using Ohm’s law is the simple way to work out what you need. Later on in this chapter, we show you how to use this to make sure you drive light-emitting diodes (LEDs) correctly.

Resistance is not the only thing we can calculate. If we know two of the quantities in a circuit, we can calculate the other one. We do this by rearranging this simple formula to find any one of the quantities if we know the other two. We like the Ohm’s law triangle, which gives the three formulas in one go:

image

When scientists were first discovering electricity, they knew that it flowed from one terminal to the other. They said the flow was from the positive to the negative, but which was which? Experiments with making a current flow through a solution of water and copper sulphate showed that copper was dissolved from one wire and deposited on the other. So they quite reasonably assumed that the metal was flowing with the flow of electricity and named the dissolving wire an anode or positive and the wire receiving the metal the cathode or negative. They were wrong: The electrons that constitute the current actually flow the other way. However, this notion became so entrenched that today we still use it. We call it conventional current, and it flows from the positive to the negative.

In a way, it doesn't matter which direction we think of it as flowing. It's the fact that it is flowing that is important, and we use the terms positive and negative so we know what way round it is flowing. A common mistake beginners make in thinking about electricity is to think that the direction of flow matters because “it first flows through one component and then through another.” This leads to the erroneous thought that the first component it meets will “use up” some or all of the electricity and then pass on what is left to the next one. This is simply wrong, because current flows through all components equally in any one path. You might also hear the phrase “electricity finds the path of least resistance and flows through that.” Again this is nonsense. Electricity always flows through all available paths at the same time — it is just that the resistance of a path determines how much current flows through that path.

Power sources, like batteries and power supplies, are all marked with positive and negative symbols so that you can connect it the correct way. This is known as direct current (DC) because the current flows in only one direction.

The other sort of power supply you can get drives the current round in one direction for a short length of time and then reverses the direction for a short time. This is known as alternating current (AC). A favorite trick that electricians play on their apprentices is to send them to the store to fetch the nonexistent AC battery.

tip Switches are used to make or break circuits, so an early name for a switch was a breaker.

Putting theory into practice

To see how this works, consider a simple circuit. To make things a bit clearer and easy to draw, we use symbols to represent components and use lines to represent wires that connect the components together, as shown in Figure 15-1.

image

FIGURE 15-1: Two circuit symbols representing a switch.

Take a switch. Its symbol (refer to Figure 15-1) is simple. There are two types of switches: single throw and double throw. In the single throw, a connection is made or not made through the switch, depending on the switch position. In the double-throw switch, a common connector is connected to one or the other switch contact, depending on the switches' position. That is, when the switch is one way, there is a connection through the switch from one connection to the common connection. When the switch is the other way, the connection is between the other connection and the common connection.

It’s called a double-throw switch, or sometimes a changeover switch, because the switch changes over which terminal is connected to the common one. The figures in this section help explain this concept. However, the important thing to note is that we use the same symbol for a switch, no matter what the physical switch looks like. Figure 15-2 shows just some of the many physical forms a switch can take.

image

FIGURE 15-2: Just a few of the many different physical forms a switch can take.

Figure 15-3 shows the symbols for a battery, a small flashlight or torch bulb, and a resistor. Note that there are two symbols for a resistor: one for the U.S. and one for Europe. In the U.K., we used to use the U.S. symbol until the late 1960s. Today, both are understood.

image

FIGURE 15-3: Schematic symbols for some components.

The world’s simplest circuit is shown in Figure 15-4. While the switch is open, there is no complete circuit, so there is no current flow and no lighting of the bulb.

image

FIGURE 15-4: A schematic of a simple circuit.

However, when the switch is closed as shown in Figure 15-5, a path for the current to flow along is created and the bulb lights up. Note that this diagram has a different symbol for a closed switch than the one used in Figure 15-4. This is so that you can more easily see what is going on. Normally, you have to imagine the switch in the open and closed positions and visualize the resulting circuit or break in the circuit. We call this a series circuit because all the circuit elements are in a line, one after the other, and the same current flows through all elements of the circuit.

image

FIGURE 15-5: A schematic of a circuit with switch closed.

So, for a circuit like this, there is only one value of current. When the switch is closed, current flows from the positive end of the battery through the switch, through the bulb lighting it up, and, finally, back into the batteries’ negative terminal. Note here that the actual electrons are returned to the battery. The battery loses energy because it has to push them round the circuit. The positive and negative terminals of a battery show the direction it will push the current, from the positive to the negative. In this circuit with an incandescent light bulb, the direction of the current doesn't matter; however, this is rare in electronics. In most circuits, the current must be sent round the circuit in the right direction.

Communicating a circuit to others

You should use circuit symbols in schematics because they constitute a universal language and make it easy to see what is going on. Many people waste their time using diagrams that show the physical appearance of components and wires and their interconnection. Although this might appear at first to be attractive, especially to a beginner, physical layout diagrams like this are almost impossible to follow in all but the most trivial circuits. Despite the initial small hurdle of learning to read the symbols, a schematic is a much simpler way of defining a circuit. Physical layout diagrams are a dead-end for anything more than a trivial circuit and should be avoided.

Some time ago, Mike was visiting Russia and bought his son an electronic construction set. Even though the words were in Russian and incomprehensible to them both, the diagrams were in the language of schematic and perfectly understandable.

technicalstuff To show the units of resistance, we can use various symbols. We can say 18 ohms, 18 Ω, or, as we shall use in this book, 18 R.

tip Although the units for calculation are volts, amps, and ohms, 1 amp (A) is in practice a lot of current, and it's more common to talk of milliamps, or mA. There are 1,000 mA in 1A. Similarly, 1000 R is one kilohm, or 1 K.

Calculating circuit values

Although the circuit shown in Figure 15-5 is all very well because it describes what's actually wired up, it's not useful for calculating anything using Ohm’s law because it shows no resistances. However, each real component has associated with it a resistance. We say it has an equivalent circuit. These are shown in Figure 15-6. All components, even the wires, have some series resistance. In other words, they behave like they have a resistor in line with the component. Sometimes this is important, and sometimes it is not. The trick is in knowing when to ignore them.

image

FIGURE 15-6: A circuit with the effective series resistance values shown.

When resistors are placed in series, or in line with each other, you can find the resistance by simply adding up all the individual resistance values. Figure 15-6 shows our circuit with the series resistance values shown. If we add up all the values around the circuit, we get 18R105. (That's 18.105 ohms.) Note that virtually all of the resistance in the circuit comes from the bulb. The series resistance of the switch is negligible, as is the series resistance of the battery. This is not always the case. So, with 18R resistance and 6V, we can calculate that the current through the circuit should be

I = E/R -->
Current = 6/18 = 0.333 Amps or 333mA

Determining how a component needs to be treated

How do we know the series resistance of a component? Well, it is normally in that component’s data sheet, the document that the manufacturers of all components produce to exactly define the component and its properties. However, it's not always given as a straightforward value. Take a bulb, for instance. This is normally “rated” as a voltage and a current; that is, we would say that the bulb is 6V at 0.33 amps. If we need to know the equivalent resistance, we use Ohm’s law. Other bulbs, especially big ones, are given a power rating in watts. Current multiplied by voltage is equal to the power in watts.

The other point is that a bulb doesn't have a constant resistance. We say it's a nonlinear device; that is, the resistance changes depending on what current is going through it. This is because a bulb is just a coil of wire. As current passes through it, the wire heats up. This causes the resistance to increase, thus limiting the current. An equilibrium point is reached where the temperature reaches a point where the resistance is such that the current is limited to the design value at the design voltage. We use this concept of a nonlinear resistance later in this chapter when we come to calculate what resistor we need to use with an LED.

technicalstuff When dealing with units like volts and ohms that include a decimal point, often the point is missed out and the letter of the unit is substituted, so 3.3 volts becomes 3V3, or 4.7K becomes 4K7. This is done to make it clear that there is a decimal point that otherwise might be lost in small print. While this is not an officially approved standard, it is widely used in the electronics industry.

The series resistance of a battery — or any power supply, for that matter — is an important concept in that it limits the current the battery can deliver. This is all wrapped up in the chemistry of the battery, but its effects can be summed up by a theoretical series resistance. A battery that can deliver a lot of current has a low series resistance. This is sometimes known as the output impedance of the battery.

remember These concepts may seem like they have nothing to do with the Raspberry Pi, but as you shall see in later chapters, these concepts are the ones you need in order to get the Pi to interact with the world outside the keyboard and screen.

Getting Familiar with the GPIO

The original Raspberry Pi Model 1, and the Pi Zero are made from a BCM2835, a single-core system on a chip. The Pi Model 2 uses the BCM2836, and the Model 3 uses the BCM2837 — both are quad core. Basically, a core is a processor, so the later models have four processors that, in theory, can work on four different processes at the same time, although this capability is not presently fully exploited by the operating system. The cores in the Pi Model 3 are more powerful than the cores in the Pi 2, but again the full power of this processor has yet to be exploited by the operating system. This is because it will mean having a version of the operating system for each type of core, and at the moment there is just the one version of each operating system for all three processor chips.

Unlike traditional microprocessors, these chips are designed to be used in an embedded system. An embedded system is a device that has a computer inside it, but you don’t use it as a computer — things like mobile phones, GPS displays, digital cameras, and TV set-top boxes. These chips have a number of connections to them in order for the software in them to control things like push buttons and displays and getting sound in and out. All the processors used for the Pi have54 such signals. They are called General Purpose Input/Output pins (GPIO), and they can be controlled by software. Some of these signals are used to build and control the peripheral devices that turn the chip into a computer, like the SD card reader, the USB, and the Ethernet. The rest are free — that is, not needed to make the Pi — so they are surplus to requirements.

Rather than just ignore these surplus GPIO lines, the designers of the Raspberry Pi have routed some of them out of the chip and to the connector called P1 on the board for you to play with. It’s a bonus. This sets the Pi apart from mainstream computers and laptops in this respect. However, they have not routed all the spare pins out to this connector. Some go to other connectors — the camera socket, for example, or the display socket — and some are not even connected to anything. This is because the family of chips used to make the Raspberry Pi are housed in a package called a BGA, or Ball Grid Array, with connections less than a millimeter apart. So close are they that you can only have enough room for one trace (PCB wire) between the connectors.

This means that, to get some of the inner connections out to other components, you need to use a printed circuit board (PCB) that has a number of extra layers of wiring inside the board. You might think the Pi’s board has just a top side and an underside, but in fact it is made from several boards sandwiched together to give six layers of wiring.

Even with this many layers, there is not enough room to route out all 54 GPIO signals. Adding more layers would significantly increase the price of the PCB and make the bonus cost something instead of being free. (You are no doubt aware that the price point of the Pi is one of its major features.) However, over successive hardware revisions, an increasing number of these pins have been brought out to use. There were 17 on the original board, but Revision 2 saw some rearrangement and another socket bring the total to 21; and, finally, the Model B+, and Revision 3, saw this increase to 28, all on one 40-pin header. This still leaves 8 GPIO pins not routed out or used internally on the board. This has remained the same for both the Model 2 and Model 3 of the Raspberry Pi as well as for the Zero models. While 28 GPIO pins on a 40-pin header might sound a little odd, the extra pins carry ground connections ( 8 pins), 5V ( 2 pins), and 3V3 ( 2 pins), which are very useful when it comes to connecting external circuits.

Putting the general purpose in GPIO

GPIO pins are called general purpose because you can use them for anything you want under the control of a program. They're called input/output pins because the software can configure them to be either an input or an output. When a pin is an input, the program can read whether a high voltage or a low voltage is being put on the pin. When the pin is an output, the program can control whether a high voltage or low voltage appears on that pin. In addition, many pins have one or more superpowers — alternative functions as a secret identity, like so many comic book heroes. These powers are not shared by all pins, but are specialist functions able to do things without software intervention. They act as ways to tap directly, deep into the computer’s inner workings. When you switch to these functions, they stop being general-purpose pins and do a specific job. For example, one pin can be used to output a continuous stream of high and low voltage levels in alternation, that, after they get going, continue without any further intervention from the program. So, if you connect that pin to a speaker or an amplifier, you can generate a tone that keeps on sounding until you command it to stop.

Understanding what GPIOs do

GPIOs are the gateway to interaction with the outside world and are, in essence, quite simple.

Figure 15-7 shows the equivalent circuit of a Raspberry Pi GPIO pin when it is configured as an output. You can see it is simply a double-throw switch that can be connected between the computer’s power supply of 3V3 or ground (that’s 0V). This is sometimes called the common ground or reference, and it is the basis of all measurements in a circuit. Basically, it's the other end of the battery — the negative terminal, if you will. Between this switch and the output is in effect a series resistor, one that is in line with the voltage coming from the Pi. It limits the current you can get through the output pin.

image

FIGURE 15-7: A GPIO when used as an output.

On the Pi, the value of this resistor can be changed over a limited range. The default value is 31R, but note that this resistor, by itself, is insufficient to protect the Pi from giving too much current if you connect it to too low a resistance load. If you did this, then your Pi would be permanently damaged. So an output pin can switch between only two voltages — 0V and 3V3. These are known as logic levels, and they have a number of names: high and low, true and false, zero and one, and even up and down.

Although the logic voltage levels on the Pi are simple, the current that these outputs can supply is more complex, with a current limit of about 16mA. This limit is how much current the Pi should supply into a load, not how much it can supply or will supply. That depends on the resistance of the load connected to the pin. We say that the limit is about 16mA, but this is a bit of a gray area. This value is considered safe for the Pi to supply, but that is not to say a value of 17mA would be considered dangerous or excessive.

Putting an output pin to practical use

What can you do with a switched output? Well, you can drive a small current through a load, or you can control another device that can control a bigger current through a load. Put like that, it doesn't sound exciting, but it's what physical computing is all about — it is the gateway to all control. The load can be a light, a motor, a solenoid (an electromagnetic plunger used to prod or strike things), or anything that uses electricity. Because that includes most everything in the modern world, it is safe to say that if it uses electricity, it can be controlled and, more importantly for our purposes, controlled by a Pi.

Take a look at controlling a light — not the current-heavy flashlight bulb we looked at earlier, but rather a component known as a light-emitting diode (LED). These can light up from just a tiny bit of current, and the 16mA we have available is more than enough for that task. In fact, you're going to limit the current to less than 10mA by adding a 330R-series resistor.

For the moment, just look at the circuit in Figure 15-8. This shows two ways to wire up an LED — or any other load — directly to a GPIO pin. Here we just show the GPIO pin and not the equivalent series resistance of the power source as discussed earlier — in the context of a 330R resistor, 31R is negligible.

image

FIGURE 15-8: Two ways of driving an LED.

The first way to wire it, called current sourcing, is perhaps the way a beginner might think of as natural. When the GPIO pin is set by the program to produce a high voltage (that is, when the switch is set to connect the 3V3 line to the output pin), current flows from the pin through the LED, through the resistor and to ground, thus completing the circuit, causing current to flow and so lighting up the LED. When the GPIO pin is set by the program to produce a low voltage (that is, when the switch is set to connect the 0V or ground line to the output pin), no current flows and the LED is not lit. This method is known as current sourcing because the source of the current — the positive connection of the power — is the GPIO pin.

The second way of wiring (refer to Figure 15-8) is known as current sinking. When the GPIO pin is set by the program to produce a low voltage, the current flows through the LED, through the resistor, and to ground, through the GPIO pin. To turn off the LED, set the output to a high voltage. There's no way current can flow round the circuit, because both ends of the load (LED and resistor) are connected to 3V3 — so there is no voltage difference to push the current through the components.

Note in both circuits that the position of the resistor and LED can be interchanged — it makes no difference. You might like to think of these two approaches as switching the plus and switching the ground.

Now an LED is a non-liner device in a similar way to the filament of a flashlight bulb, but in the case of an LED we need a resistor to limit the current to a safe value; it will not self-limit, like the bulb. The important thing to know is the LED’s voltage drop — the voltage that will appear across it when the LED is on. This drop changes with different colours of LED, so to get the same current down two LEDs of different colours, you need different resistors.

remember Getting the same brightness is not the same thing as getting the same current, because different LEDs have different current-to-light efficiencies. Modern LEDs are a lot more efficient that they used to be, so you need less current.

With a red LED, there is about a 2V2 voltage drop across it. This leaves the remaining voltage from the GPIO pin (3.3–2.2 = 1.1V) to be dropped across the resistor. With a 330R resistor, Ohm’s law tells you the current will be –1.1 / 330 = 3.3mA, which is plenty bright to see.

warning Don't try to run the LEDs at too much current. Although most will be able to take 20mA, if you did this then your GPIO pin would be supplying too much current and your Pi could be damaged. There should be no need to run an LED any harder than 10mA.

Using GPIOs as inputs

The other basic mode of operation for a GPIO pin is as an input. In this case, you don’t have to worry about the current, because when the pin is an input, it has a very high input impedance, or a high value of series resistance, and therefore little or no current can flow with normal logic level voltages. A resistance is a special form of impedance, which, as its name implies, impedes the flow of electricity. There is a bit more to impedance than simple resistance, but at this stage, you can think of them as the same sort of thing. They are both measured in ohms.

Resistance is the property of a material, whereas impedance is the property of a circuit and includes how it behaves with AC as well as DC. So an input pin has a very high impedance. It allows hardly any current to flow through it, so much so that we can connect it directly to either 0V or 3V3 directly with no extra resistors. In fact, an input is so high-impedance that if you leave it unconnected, it picks up very tiny radio waves and other forms of interference and gives random values when you try to read it.

In fact, the human body can act as an antenna when close to or touching a high-impedance input, causing any readings to go wild. This often amazes beginners, who think that they have discovered something mysterious. They haven't. In fact, the tiny amounts of energy in the radio waves that are all around us are not absorbed by the high-impedance circuits as they would be by low-impedance circuits. A low impedance would cause current to flow, but it would easily absorb all the power, leaving minuscule amounts of voltage. Just the fact that you have a wire carrying AC power (mains) close by is enough for that wire to radiate radio wave interference.

To explain why this is so, consider that interference of, say, 2V is enough to override the signal from a chip and cause it to malfunction. With a low resistance — say, 1K — in order to develop 2V across, it needs to have a current of 2mA (Ohm's law) flowing through it. This represents a power (volts × current) of I×V=4mW of interference. However, with a resistance of 1M, you can get 2V across it by only having 2uA flowing through it. This represents a power of 4uW. So, a high resistance is much more sensitive to interference because it requires less power from the interfering source to develop the same voltage. Therefore, weaker fields produce enough interfering voltage to disrupt a circuit.

This underlines an important fact about inputs: They can’t simply be left alone. They must be driven to one voltage state or the other; that is, either 3V3 (known as high) or 0V (known as low). If you connect an input to the output from some other chip, that's fine, but if you want to detect whether a switch is made or broken, you have to give the input pin some help. This is normally done with a resistor connected from the input to either the 3V3 or the ground.

When a resistor is used in this way, it's called a pull-up or pull-down resistor, as shown in Figure 15-9. Of the two arrangements, a pull-up is preferable, mainly because switches are normally on the end of long runs of wire and it is safer to have a ground than a 3V3 voltage on a wire. This is because it tends to cause less damage if you accidentally connected a ground wire to the wrong place than a power wire. This arrangement of pull-up or pull-down resistors is so common that the computer processor in the Pi has them built-in, and there is a software method for connecting or enabling internal pull-up or pull-down resistors. We show you in Chapter 16 how to control this from software.

image

FIGURE 15-9: Two ways of using a GPIO as in input.

Learning which end is hot: Getting to grips with a soldering iron

Although you can do some interfacing without resorting to the soldering iron to join components together, to get serious, you'll have to do some soldering at some stage or the other. This often induces fear and panic in the newcomer, but even a child can solder successfully. In fact, Mike had his first soldering iron at the age of nine and by and large taught himself. Soldering involves two parts, the solder, which is an alloy of two or more metals, and the flux, a chemical cleaning agent. If you are soldering something like a gas pipe, you would apply the flux round the joint, heat the joint up with a blow torch, and apply the rod of solder to the hot joint. The job of the flux when it is heated is to clean the surface and make the solder flow. It does this by breaking down the surface tension on the molten solder. Without it, the solder would clump together in round globs held by the tight surface tension.

Water has surface tension as well, and to reduce that we use soap, which allows the water to wet things. You can’t use soap with solder because it wouldn't stand the heat, so you need something else. Most fluxes for heavy jobs are made from nasty chemicals like hydrochloric acid, or phosphoric acid. These are too corrosive to be used with electronics, so what is normally used is some sort of rosin flux. Although you can get this in a pot, by far the best thing is to use Multicore solder, where the flux is built into the solder wire as five very thin strands. That way, the right amount of flux is always delivered with whatever amount of solder you use.

We recommend using a good quality 60/40 tin/lead solder alloy, with a diameter of 0.7mm and a built-in rosin-based flux core. Anything else is making life difficult for yourself. We've found that solder with self-cleaning fluxes or non-fuming fluxes are harder to work with, as well as being more expensive. Couple the right kind of solder with a good soldering iron, preferably a temperature-controlled one with a fine tip.

tip It is often said that you can use any old tool to learn on, and then get a good tool when you get good at using it. This is rubbish. As a beginner, you are fighting how to do the job, so you don’t want to be fighting your tools as well. A good iron includes a stand and a place for a sponge, for removing flux that has accumulated during the soldering process. If it were not removed, then it would form a glassy layer that would prevent the iron from making good thermal contact with the solder of joint. Use a proper soldering iron sponge — a natural one that won't melt on contact with the iron. Do not use a plastic foam sponge because your iron will go straight through it.

Making a soldered joint

The first thing you should do when making a soldered joint is to make a mechanical joint. For example, if you're joining two wires, bend each end into a hook and squeeze together lightly with pliers.

Wipe the tip of the iron on a damp sponge, and melt just a spot of solder on the tip. This “wets” the tip and allows good thermal contact to take place between the tip and the work. Then apply the iron, solder, and wires all together. The secret is then to look at the joint and the solder closely, to see how it sits. Remove the solder, but keep the iron on the joint until you see the solder flow around the joint and see it seep into the cracks. Only then is the joint hot enough for you to withdraw your iron. It is a quick process and needs a bit of practice.

Many beginners make the mistake of putting too much solder on a joint. Try to use as little solder as possible. A joint is rarely bad because of too little solder, but it's often bad because of too much. When you are done, you see a small amount of black flux residue around the iron tip. Wipe that away on a damp sponge before returning the iron to its stand. Do not move the joint as the solder sets.

remember A good-quality iron is ready immediately for the next joint. A poor iron needs a few seconds to come up to temperature again after making a joint.

tip Use some sort of fume extractor when soldering. A simple fan works to guide the curl of smoke from the iron away from your face. Air currents from the warmth of your body tend to attract the flux. Try not to breathe it in. This is more important as you spend a long time (hours at a time) with a soldering iron in your hand. The fumes are from the flux in the solder; they are not lead fumes.

Although Chapter 16 contains projects that can be made without the use of a soldering iron by using solder-less bread boards, we recommend that you never take that approach for a permanent project. When a project is meant to last more than a day or two, you should always solder it up.

Looking at Ready-Made Add-On Boards

There are basically two types of ready-made boards: those designed for making it easy to get access to the GPIO pins and those with components that have already been soldered up. We will look at some of the latter type here and leave the former types to Chapter 16.

Since the introduction of the Raspberry Pi in 2012, many companies have produced ready-made boards with all sorts of components already built on. They normally come with sample code to show you how to use them, and many users just stick to that. However, this can be a wasted opportunity because you can always do more with a board than is shown in these examples. (Chapter 17 shows you some examples of this.) Many of these boards contain sensors that allow your Pi programs to measure things. New boards are constantly being developed and produced.

Boards come in three styles:

  • Separate boards that connect to the GPIO pins via a ribbon cable or your own wires.
  • Boards that plug into all the GPIO pins and cover most of the area of the Raspberry Pi board. These are sometimes called shields or plates.
  • Boards similar to the shield/plate variety just mentioned but contain in addition an identification and sometimes software so that the Pi can read what they are on start-up and install some software and prepare the GPIO pins automatically. These are called HATs — short for Hardware Attached on Top. Read more about HATs at http://www.raspberrypi.org/introducing-raspberry-pi-hats.

The Sense HAT

The Sense HAT was specifically designed for the Astro-Pi mission and two ruggedised versions were flown on the International Space Station from December 2015 running code written by school children. It has an 8×8 RGB LED matrix, a 5-button joystick, and sensors to measure acceleration, magnetism, temperature, pressure, and humidity — as well as a gyroscope. (See Figure 15-10.) The Sense HAT also has an extensive Python library associated with it, which allows for easy access to this board. You can find comprehensive coverage of how to use the Sense HAT on the Raspberry Pi Foundation's website at https://www.raspberrypi.org/learning/getting-started-with-the-sense-hat/.

image

FIGURE 15-10: The Sense HAT.

The Skywriter HAT

The Skywriter HAT (see Figure 15-11) is an electric near-field 3D proximity sensor. With it, you can make gestures with your hands waving above it, which can then be detected by the library software, causing your own functions to run. Gestures such as flicks right, left, up, and down can easily be detected along with a circular motion of the finger. It also detects taps made directly to the HAT surface. It has a range of about 5 centimeters and can be mounted behind any nonconducting surface, such as an acrylic sheet.

image

FIGURE 15-11: The Skywriter HAT.

The Xtrinsic Sense board

The Xtrinsic Sense board is a low-cost sensor board, in some ways similar to the Sensor HAT but without the LEDs. It is made in partnership with the component distributor and Raspberry Pi co-manufacturer Farnell. It contains a high-precision pressure sensor in the range 50 to 110kPa, a 3-axis, digital accelerometer, and a 3D magnetometer. As you can see in Figure 15-12, it sits over less than half the Raspberry Pi and can be used, among other things, with robots and high-altitude balloons.

image

FIGURE 15-12: The Xtrinsic Sense board.

Other boards

There are many other boards available from small start-up manufacturers as well as web-based projects for you to build. You can find a good starting point for information on many of these at http://elinux.org/RPi_Expansion_Boards.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.156.202