In this tutorial we are going to test the I2C and GPIO interfaces of the Raspberry Pi.
- Quad Alphanumeric Display with I2C Backpack
- 2 - Mini Breadboards
- Pi T-Cobbler GPIO Breakout
- 1k Ohm Resistor
- Jumper Wires
Step 1: Assemble the I2C Alphanumeric Display
First, solder together the alphanumeric display. Adafruit has a great tutorial for assembling the display here. After the display is assembled, place it onto the mini breadboard like this:
Make sure each of the displays pins are in their own separate rows. If the pins are in the same row on the bread board they will be shorted together.
Step 2: Assemble The GPIO Test Circuit
Next, connect the LED to the bread board. The LED has one leg that is longer than the other. The longer lead is the positive lead.
Connect the negative lead to the negative (-) rail of the bread board. Connect the positive lead to one of the rows of the bread board. Connect one leg of the 1k Ohm resistor to the same row that the positive lead of the LED is connected to. Connect the other leg of the resistor to an empty row on the bread board. The LED and resistor connections should look like this:
Step 3: Connect Breakout Board to Raspberry Pi
Take your second bread board and connect the Pi T-Cobbler so that each pin is in a separate row on the bread board. Connect the Pi T-Cobbler to the Raspberry Pi using the included ribbon cable. Pay close attention to the alignment of the white wire on the ribbon cable. The white wire should be farthest from the USB connectors on the Raspberry Pi. The connector on the Pi T-Cobbler is keyed so that the cable can only be connected one way. Once connected, the setup should look like this:
Step 4: Connect Test Circuits to Raspberry Pi
Connect the wires from the Raspberry Pi breakout to the display. Here is a link to a graphic of the pin out of the Raspberry Pi. Connect the display to the following pins. These pin names correspond to the names listed on the breakout board.
Both "+" pins on display -> positive (+) rail of bread board
"-" pin on display -> negative (-) rail of bread board
"D" pin on display -> "SDA" (Pin 3 on Raspberry Pi) on breakout board
"C" pin on display -> "SCL" (Pin 5 on Raspberry Pi) on breakout board
The connections from the display to the breakout board should now look like this:
Connect the "3.3V" pin on the breakout to the positive (+) rail on the bread board that is also connected to the "+" pins of the display. Connect the negative (-) rail of the bread board that is connected to the LED and "-" pin of the display to a "GND" pin on the breakout board. Lastly, connect the lead of the resistor that is not connected to the LED to pin "#26" on the breakout board (Pin 32 on Raspberry Pi). The connections to the breakout board should now look like this:
Step 5: Test I2C Display
Double check all of your circuit connections especially the power connections to the breakout board. Connect your Raspberry Pi to your router via an Ethernet cable and power up the Raspberry Pi. Wait a minute for the Raspberry Pi to boot up and log into the Raspberry Pi with your SSH client. Type this command to see if the I2C interface is connected correctly:
sudo i2cdetect -y 1
A table will be displayed in the command window listing all of the I2C addresses that are in use. If everything is working correctly you should one address in the table like this:
If you see no entries in the table, double check that the I2C interface has been configured properly (see this tutorial) and double check all of the connections to the display are correct. To download an alphanumeric display test program, type the following command into the console:
sudo apt-get update sudo apt-get install build-essential python-dev python-smbus python-imaging git
These commands will download the necessary packages to install the display package library. If prompted type Y or Yes to confirm any downloads. After the installation of those packages are complete, type the following commands to download the display package library from Adafruit and install it:
git clone https://github.com/adafruit/Adafruit_Python_LED_Backpack.git cd Adafruit_Python_LED_Backpack sudo python setup.py install
Once the installation is complete, type the following commands to run the test program.
cd examples python alphanum4_test.py
Letters will begin to scroll across the the alphanumeric display. Press CRTL-C to quit the program.
Step 6: Test GPIO Circuit
Type the following command to return to the home directory, create a new directory to hold your GPIO test program and open a new file in nano:
cd ~ mkdir GPIO_Test sudo nano ~/GPIO_Test/gpioTest.py
Once nano opens, type or copy the following program into nano. Make sure that the program is properly indented:
import RPi.GPIO as GPIO import time LED = 26 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(LED, GPIO.OUT) def loop(): GPIO.output(LED, True) time.sleep(1) GPIO.output(LED, False) time.sleep(1) if __name__ == '__main__': try: print 'Press Ctrl-C to quit' while True: loop() finally: GPIO.cleanup()
Type CTRL-X and enter Y and hit enter again to confirm the name of the file. At the console type the following commands to run the GPIO test program:
cd GPIO_Test python gpioTest.py
The LED should then begin to blink on and off every second. If the LED is not blinking, check the connections of the GPIO circuit. If a software error message displays in the console double check that the program was typed in properly especially the indentation of the program. The indentation is extremely important and will cause the program to fail if not done properly.
If everything works properly, congratulations! You have completed testing of the GPIO and I2C interfaces.