A tour of the GPIO pins

One of the things that makes the Raspberry Pi more than just a small, cheap computer is the fact that it gives us easy access to its general purpose input and output (GPIO) pins. Locate the GPIO pins on your Raspberry Pi and make sure that the SD card is on your left and the GPIO pins are away from you. This will help make sure that the pins in the picture are the same as the pins on your Pi.

RaspberryPi

3.3 volt and ground pins

With the Raspberry Pi connected to power we should have 3.3 volts on the pin closest to the SD card. My multimeter shows 3.28 volts with the positive probe touching the 3.3 volt pin and the negative probe touching the ground pin.

Multimeter showing 3.28 volts

Directly across from the 3.3 volt pin is the 5 volt pin. When the Raspberry Pi is connected to power we should always have 5 volts on this pin.

5 volt pin

When I put the positive probe of my multimeter on the five volt pin and the negative probe on the ground pin I get a reading of 4.61 volts. This is less than the 5 volts we expected but still within operating range.

Multimeter showing 4.61 volts

Another way to see that these pins, the 3.3v pin and the 5v pin always have power is to wire an LED in a circuit. Here I have a yellow jumper wire that goes from the 3.3v pin to node 10 on a small bread board. The positive (long) lead on the LED is pushed into node 10 and the negative (short) lead of the LED is push into node 11. I have a 330 ohm resitor from node 11 to the negative bus of the bread board and then a black jumper from the negative bus to the ground pin on the Raspberry Pi.

LED wired to the 3.3 volt pin of the Raspberry Pi

I use the resistor to limit the current flow through the LED. Without the resistor I expect the LED would quickly burn out. Ohms law tells us that Voltage is equal to Amps times Ohms.

3.3v = 0.01 amp X 330 ohms

or 10 mAmps

Now we will take a look at the pins that are really interesting.

GPIO pins with labels

The version of Linux for the Raspberry Pi is ready to help us use these pins. One thing to note is that there is plenty of software available to help us control the pins and we will want to learn how to use these programs but it is good to know that we can work with the GPIO pins with just the operating system.

First we switch our user to be the super user.

pi@raspberrypi ~ $ sudo su

Now we tell the operating system that we want to use pin 17 by running export.

root@raspberrypi:/home/pi# echo 17 > /sys/class/gpio/export

Export creates a new folder named gpio17 inside /sys/class/gpio

root@raspberrypi:/home/pi# cd /sys/class/gpio
root@raspberrypi:/sys/class/gpio# ls
export gpio17 gpiochip0 unexport

Inside the gpio17 folder are several new files.

root@raspberrypi:/sys/class/gpio# cd gpio17
root@raspberrypi:/sys/class/gpio/gpio17# ls
active_low direction edge power subsystem uevent value

Take a look at the direction file. It contains one line that tells the operating system if the pin is used for input or output.

By using the cat (concatenate) command we see that the pin is set for output and has a value of 1.

root@raspberrypi:/sys/class/gpio/gpio17# cat direction
out
root@raspberrypi:/sys/class/gpio/gpio17# cat value
1

It looks like pin 17 is set for output and has a high value, however, if we check the voltage between pin 17 and ground we see 1.36 volts which is neither zero volts for low or 3.3 volts for high. After exporting a pin we need to initialize it. We can do this by setting its direction and value.

echo "out" > direction
echo 1 > value
cat direction
out
cat value
1

Now we can read 3.3 volts between pin 17 and ground.

Next we will set up a pin for input. (Add input pin instructions here..)