WarningThis is no "HOWTO build an expansion board for the Raspberry Pi"!. I just would like to give you an impression of how things work on my board and what has to be considered when starting your own projects. If you have already experience in soldering work and if you know about the basics of transistors, you might be interested in the stuff of this chapter. My board is not foolproof nor is it optimized in any way. I have built the whole stuff "on the fly ", using materials I had in stock. I recommend using the Gertboard, developed by Gert van Loo to make your first steps in physical programming!
You might destroy your Pi, burn your fingers, smoke power supplies and much more while trying to build an own board. You know what I am talking about? If not, you can read the following, but stop acting without base knowledge!
GeneralI/O board is the acronym for Input / Output board. Those boards are used to send signals to a computer (Input) or to actuate peripherals by signals coming from a computer (Output). The voltage output of sensors might be different from those a computer uses and the power consumption of a peripheral device is mostly higher than those a computer can provide. So voltages are transformed and signals are amplified by the board. Another function is to protect computer or peripherals from handling errors (connecting peripherals to wrong clamps, attaching too high voltages and so on). Remember: What ever might go wrong, will go wrong (if not today than tomorrow)!
This chapter is a preview of what I intend to treat much more detailed in some chapters about semiconductors during the next days/weeks/month/years. It's published now, because the Raspberry Community asked for it several times...
Expansion board of the Raspberry PiThe 17 GPIOs of the Raspberry Pi are connected through a flat cable to the expansion board. Each of the pins is connected via a 16kΩ resistor to the gate pin of a small signal Transistor. LEDs indicate the switching status of each transistor. A LED is turned on, if a sufficient voltage is applied to the gate of the small signal transistor. Normally this is done when the GPIO pin of the Raspberry Pi is set to output mode and it is turned on by software, hence 3.3V are attached to the pin and so to the base of the transistor.
To be able to switch devices consuming more than 2mA (that's what the pins of the GPIOs can drive) respectively more than 200mA (thats what the small transistors can drive), 7 H-bridges are soldered at the board. Using H-bridges (each consists of 4 power transistors) instead of single power transistors gives you a much greater range of using the output pins. By using H-bridges you can alter the polarity attached to the output pins, enabling you e. g. to alter the rotational direction of electric motors.
Three pins can be used in input mode.
By using 16 GPIOs the board can operate as a 2 channel 8 bit frequency generator.
Let's have a closer look at the single components of the board:
Power supplyThe input voltage of the board is 12V. I am using a power supply of an old computer. The black cables are ground and the yellow ones provide 12V. The green cable must be connected to ground to turn the power supply on. To connect both devices, use plugs being protected against reverse polarity! I haven't (accidentally) tried wrong polarity (yet), but I guess you will start crying.
There is a 5V regulator at the board to be able to drive servos, which will burn down while connected to 12V (I know what I am talking about - the board is not foolproof...).
By a voltage divider (2.2kΩ and 1.5kΩ), the 12V output of 2 clamps of the power transistors has to be transformed to 5V, to be able to control 2 servos by a 5V square wave signal (or more if required).
Limiting the currentThe current running through a single pin of the Raspberry's GPIOs must be limited. Referring to the documentation I have found, it should not exceed 2mA. The most simple way to limit those current is using a resistor. The output voltage of the pins is 3.3V so the minimum value of those resistor is
The only connection between Raspberry Pi and the board without a series resistor is the grond pin, which is connected directly to the ground of the board.
Driving the small signal transistorsThe small signal transistors I am using are N-channel MOSFETs type 2N7000. MOSFET means they can be driven (almost) without a current running through the gate pin (see chapter JFET, the MOSFET section is not online yet). To avoid an undefined state of the transistor while it is not connected to the Raspberry Pi or if the computer is turned off, a 220kΩ resistor is soldered between the gate pin and ground. This resistor is called pulldown resistor, because it pulls the voltage to ground level, if the gate pin is not connected to an input circuit, hence the transistor is turned "off". Those resistor is very important, because without it, your peripheral would behave in an unpredictable way whenever the board is connected to an input voltage, while it is not connected to the Raspberry Pi!
The series resistor and the pulldown resistor are forming a voltage divider, hence the voltage at the gate pin is lower than the 3.3V output of the GPIO pin:
A high value of the series resistor and the pulldown resistor lead to a low current running through the input circuit, hence through the GPIO pin. Low current means low power consumption means energy efficiency. So far so good, but there is a reason not to use too high resistors: The switching frequency! No current is running through the gate pin of a MOSFET - that's true as long as the state of the transistor is not altered. To change the state from "on" to "off" or vice versa, the charge, cumulated inside of the transistor's gate area has to be altered. The higher the series resistor, the more time passes by until the gate area gets charged (transistor is turned "on"), respectively discharged (transistor is turned "off"). I haven't checked the output curve of the small signal transistors with my oscilloscope yet, so I can't grant the correct function at high frequencies. The projects I started for the video use relatively low switching frequencies, so the combination of the two resistors causes no problems.
The output circuit of the small signal transistors consist of a series resistor limiting the current running through the LED. If you have a closer look at the photo you might have noticed another resistor soldered in parallel to the transistor, but this one is not necessary (was for the frequency generator, see below). The maximum current of the output circuit should not exceed 200mA.
H-bridgesThe H-bridges are the output circuit of the board. They are driven by the small signal transistors. The main reason why they can't be driven directly by the GPIOs is the Voltage they are connected to. To turn the upper P-channel MOSFET "off", the base pin has to be attached to a voltage of 12V, while the GPIOs provide just 3.3V!
The base pins of one half bridge are both connected to the drain pin of one small signal transistor. Two small signal transistors, hence two GPIOs are necessary to drive one H-bridge. You can use a half bridge to simply switch a load "on" or "off" (to positive or negative voltage). When turning the GPIO "on", a voltage of 12V is attached between the clamp of the half bridge and ground, respectively 0V between clamp and the 12V line. Vice versa, 0V are between the clamp and ground respectively 12V between clamp and 12V line while the GPIO is turned "off". 17 GPIOs can drive up to 17 loads in that way. By using the whole bridge, the state of two GPIOs switches the voltage between the two clamps of the H-bridge. There is no voltage attached to the clamps, if the switching states of the two GPIO is identical (both "on" or both "off"). The voltage drop is +12V if GPIO number one is turned "off" while number two is turned "on". The voltage drop is -12V if GPIO number one is turned "on" while number two is turned "off". That enables you e. g. to alter the rotational direction of an electric motor. Up to 8 H-bridges can be controlled by 16 GPIOs.
How to simply smoke an H-bridge:
One H-bridge consists of two N-channel MOSFETs type IRLZ24N and two P-channel MOSFETS type IRF9Z34N. According to the datasheet, both should be able to drive a continuous current of up to 13A. Like explained at the chapter about bipolar transistors, a heat sink is required to be able to operate at those limit. Without those heat sink, this might be the first mode of destroying an H-bridge.
While altering the switching status of a half bridge, a high current is running through both transistors, because for a short span of time none of them is turned completely "off". This causes trouble while operating the bridges with a high switching frequency! I did not have problems to drive the stepper motors, the servos or to dim the LEDs by pulse width modulation, but you remember the frequency generator in the video? This frequency generator is built with the same GPIOs which also drive the H-bridges (too much functionality on one board). After operating the frequency generator with it's limit frequency, I had to replace some transistors. To avoid this, I had placed a jumper on the board to be able to disconnect the H-bridges from the power supply while using the frequency generator, but forgot to remove it while recording the video sequence (whatever might get wrong...).
Input pinsWhile using the GPIOs in input mode there is no danger of shortcuts, but of too high voltages applied to the pins. If you are sure not to use other voltages than +12V at the output of the sensors, a simple voltage divider is sufficient to avoid damage. At my board, the series resistor of 16kΩ is also applied to the input pins, because the GPIOs can alternatively also be used as output pins. Furthermore they could accidentally be switched to output mode (defect free software doesn't exist). The higher the total resistance of the voltage divider, the lower the current your sensor must provide. The ratio between the two resistors can be calculated as follows:
If you intend to use a pin either in input or output mode, you have to consider the pulldown resistor at the base pin of the small signal transistor, which is in parallel to R1!
Replacing R1 by a 3.3V zener diode and another diode gives you some benefits:
Even higher or lower positive voltages than 12V at the input clamps lead to a voltage drop of not more than 3.3V at the GPIOs. When operating a sensor accidentally in reverse polarity, the negative voltage drop is limited to just 0.7V. While using a zener diode, the exact resistance value of R2 is not important, simply use a high one. I suggest 16kΩ and you should not use a much higher value. The current-voltage characteristic of a real zener diode is not as steep like assumed in an ideal world, hence there is just a voltage of 1.5V across the Zener diode when operating with a 12V sensor and a 100kΩ resistor, additionally 0.7V are subtracted by the second diode, while the Raspberry needs at least 1.4V to detect "true" or "1". With the pulldown resistor in mind, use a lower value if the voltage output of your sensor is below 12V! 3kΩ are suitable when operating 5V sensors.
There is no input logic on the board (like Schmitt trigger or comparators). Some more chapters about sensors will follow somewhen.
TotalIn total you get the following, which can be soldered on a board up to 8 times (click to enlarge):
The simple 8 bit 2 channel frequency generator I have demonstrated at the video is in fact a fastly switched Digital to Analog Converter (DAC), which is also soldered at the board. Like mentioned above, this was no wise decision. Use another board if you intend to build your own one. The quality of the generator is poor (low frequency stability, no symmetric voltage output, just 1kHz maximum frequency). On the other hand it is simple to build. The only thing you need is some constant resistors with two different values (the value of R1 must be twice as much as those of R2 - exactly, not nearly). For the reasons mentioned above they should be greater than 16kΩ. I used 100kΩ and 200kΩ resistors. The circuit can be used to demonstrate the functionality of Digital to Analog Converters or to paint Lissajous figures on an oscilloscope.
Mechanical stuffThe connection between Raspberry Pi and board is done by half of an old SCSI cable. Unfortunately there is no mechanical protection against faulty plugging of the cable at the Raspberry. What can go wrong... but my Raspberry survived, because of the 16kΩ series resistors!
The board is mounted on an acrylic plate to avoid shortcuts while storing the board on a conductive surface (e. g. computer case). The ribbon cable to the Raspberry is also fixed at the plate. Before that, one lead of the cable burst at the soldering point, which cost some time to discover... . Same are the lustrus clamps and the cable of the power supply (remember the plugs against reverse polarity).
Lustre terminals are used for the output clamps of the board. Wrong polarity or voltages might damage peripherals attached to the board rather than the board itself (resulting in a smoked servo). Curious behavior of peripherals may also be caused by using the wrong output clamps (It took some time to notice that, while I was operating stepper motors).
As you read above, I had to replace some of the power transistors of the H-bridges. I have soldered them with the pins bent into different directions at the back of the board (e. g. base pin of the upper transistor to base pin of the lower one). That made it hard to remove them. May be you can find a better solution. I am sure you will have to replace one sooner or later.
Glass fuses protect the output circuits from shortcuts. Another advantage is that you can open the output circuit by removing the fuses to find errors or to measure the current running through the bridges.
DiscussionQuestions, remarks and suggests are best posted at the forum of the Raspberry foundation. Many of the principles (and even more) were already posted somewhere at the forum. I am not the inventor of digital signal amplifying or creating expansion boards.
Jump to the post.