RETIRED - Pi Wedge B+ Hookup Guide
This Tutorial is Retired!
The SparkFun Pi Wedge B+ kit has been retired. If you are still looking for a way to connect to the Raspberry Pi's 40-pin header, there is a preassembled 40-pin Pi Wedge version available.
View the updated tutorial: Preassembled 40-pin Pi Wedge Hookup Guide
Software
With the many programming languages available on the Pi, it's hard to know where to start writing software that interfaces with the I/O connector.
For a quick and easy way to check out the connections on the IO connector, check out the WiringPi package. Wiring Pi is a hardware interface library that includes a utility to help you configure and check the status of the GPIO connector pins.
Follow these instructions to install Wiring Pi.
Once you've got it installed, you can use the gpio
command line utility to quickly check and test hardware connections.
gpio
takes a number of arguments. The readall
option prints a handy table that deciphers the configuration and assignment of the pins. It also detects the revision of the Pi, and translates the pin numbers to match.
pi@raspberrypi:~$ gpio readall
+-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5V | | |
| 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 1 | ALT0 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT0 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | ALT0 | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | ALT0 | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 0 | 27 || 28 | 0 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 0 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 0 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 1 | OUT | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+
Somewhat confusingly, you'll notice that there are three different ways to refer to the GPIO pins. Starting from the center of this table, we see:
- The "Physical" columns that correspond to the pin numbers of the J8 connector on the B+.
- Moving outward from there, the the "mode" and "name" columns indicate the presently configured pin function and direction.
- The next column out, "wPi," is a set of contiguous numbers (0 to 31) that WiringPi uses by default (though it can be configured to use other numbering schemes, too - see the GPIO man pages).
- Finally the "BCM" column refers to channels of the GPIO peripheral on the BCM2835 processor.
The Pi Wedge is labeled with the numbers seen in the Name column.
If you run gpio
without any parameters, it displays the available options. You can use it to configure, read and write pins right from the command line. Similarly, man gpio
displays more detailed information on using the utility, including a number of sample commands.
Programming
If you're coming from Arduino, and you've got a handle on how it manages I/O, you'll find that the WiringPi libraries present a familiar programming interface. We have a few WiringPi based examples for GPIO, SPI and I2C in the Pi Wedge GitHub Repository that should help you get started.
If Python is more your speed, then take a look at the RPi.GPIO module.
For more detailed information about using both WiringPi and RPi.GPIO, take a look at our Raspberry gPIo tutorial.