The Raspberry Pi Punnet


Well having finally got my Pi actually working it was time to do what any true hardware guy would do and blink some LEDs. This involved delving into the signals brought out on the extension pin header. It is not quite as easy as you might think for a number of reasons. First of all this is a 3v3 processor and the output pins have very little current capability. Sure there is enough to light a small LED but I wanted to make something that would handle a bit more and also be capable of driving 'normal' TTL 5V logic for another project.

Getting at the GPIO

At the top left hand corner of the Pi is a 26 pin header labelled P1. It is here you can get access to logic signals that provide inputs and outputs to the computer.

A Buffer Board

The next thing that makes it a bit tricky is that only 17 GPIO (General Purpose Input Output) lines are made available on this header and they are not in any particular order. The main criteria was they were pins that could be tracked out of the BGA chip on only a six layer board. This is a bigger restriction than you might at first think. By the way is it only me, but every time I here the term GPIO I almost burst into an old song:- GPIO, GPIA Ghost riders in the sky...

This tracking difficulty means the output pins are a somewhat random selection of the first 32 bit GPIO register. Not that it is difficult to cope with but it is just another thing to learn. However, what makes matters worst, is that on the official information site people have labelled these in various ways. Even, to the extent of inventing new ways of labelling them, and calling them virtual pin numbers. I will have no truck with such unnecessary complications. Then, as many pins have alternative specialised functions these functions took precedent over the GPIO numbers when it came to labelling them. This is an error and is putting things very much back to front.

A Buffer Board

Therefore the first thing to establish what what the connections on this header actually are, this is shown in the diagram.

Next I cut out a small pice of strip board 1.9” by 1.6”. The idea is that this board should plug into the Pi, the signals should be buffered, and then brought out to a socket so that you can plug in other circuits, like in this case a small board of LEDs. The space on this board is a bit limited and all I could do is to fit two ULC2003 darling driver arrays. These have seven darlington transistors per chip, I used them in preference to the ULC2803 with 8 per chip mainly because I had two large tubes of them and non of the others. This allows a total of 14 signals to be buffered, leaving 3 signals unbuffered. I thought that those could be used as inputs in my experiments.

Each of the darling buffered outputs is capable of switching 500mA but heat dissipation issues mean that the total current switched on at any one time is about 650mA per package, more than adequate for most applications.

Mechanically I needed two different types of pin header sockets. One pointing up and the other down. The point is that there is only one side with copper on the strip board I had so the soldering had to be on the same side. For the connector into the header I used a surface mount strip. Where as for the other header I used a trough hole type, with the plug capable of being pushed all the way through the connector.

When dealing with strip board you have to be able to cut the tracks, normally you would use a spot face cutter or drill bit. This is fine if you have the space to sacrifice a hole to make the cut but this is not always the case, especially with the through hole connector. Therefore you have to get a bit more creative with a sharp scalpel to cut away at the copper between the holes. You can also leave a lot more copper on the board by just removing a small nick of copper either side of the hole. This is important when you want to bridge the gap with a surface mount resistor, capacitor or LED.

The circuit is shown in the schematic and is about as straight forward as you can get. I used Kynar coated solid core wire of 30 AWG to make the connections. These are nice and thin and allow you to push two wires down a single hole. The three unbuffered signals were brought out to another through hole connector and the 5V, 3V3 and ground was also brought out to this connector. The three pins I chose to be unbuffered were the I2C data line, this already has a pull up resistor built into the circuit of the Pi, and the transmit and receive signal lines of the UART. These would need extra buffering before being used to connect to an RS232 line anyway so I though this was a good choice. You might disagree but the modification is simple. Once it was wired up I felt that there could do with a bit of support on the opposite end to the connector to the Pi. Therefore I cut a plastic pillar to size and glued it with epoxy to the strip board only. In hindsight I should have made the strip board one hole longer in that direction to make it fit fully. However, it does it's job and there is not a lot of pressure going to be applied.

So next I lashed up a small board with some surface mounting LEDs. These were chosen for size, so that they were as wide as the copper strip. I used a 820R resistor in series with each LED connected to the terminal header. The other end of the LEDs were connected to the +5V line, and the small board was plugged into the header.

Now for the software. For those familiar with other processors the software to drive the GPIO register might seem complex, and so it is. There are a number of options to set, such as drive strength, pull up or down, edge detection or interrupt generation. Fortunately there is a piece of example code on the Wiki for driving the pins. I took this as my starting point and added the extra bits to drive the LEDs into an interesting chase pattern. I made an array which defines the pin numbers in the order I want to turn them on and off, and I wrote a delay function that just looped a number of times and gave the results roughly as you would get them on an arduino. That is a function called delay to which you pass a number giving the delay in  milliseconds. This was simply tuned by hand as it were, by putting in numbers until the appropriate delay was achieved. The initialisation code set all the pins on the header to outputs, even the unbuffered ones and then a simple endless loop churned out the same pattern. You can see the results on the video. If you are making this then you need to be running with root privileges to get at some of the included files. You can down load the code and all the PDFs of the drawings for this project here

So in conclusion a satisfactory first attempt at driving the outputs of the Pi, once you can light an LED you can control all manner of things in a very similar way.

I put a small dab of correcting fluid on the connectors next to pin 1 to ensure I always connect it the right way round. The common line on the buffers, is the reverse biased EMC diodes for all the buffers. If driving a motor then connect this pin to the motor supply. Otherwise leave it unconnected.

Back to the Punnet