In this tutorial we will walk through setting up the GPIO ports and the I2C interface for the Raspberry Pi.
The tools required for this tutorial are a configured Raspberry Pi and a computer to communicate with it. To configure the Raspberry Pi see this tutorial for setting up the pi for the first time.
Step 1: Setup Raspberry Pi GPIO
In order to setup the Raspberry Pi to use the GPIO connectors the correct python packages need to be installed. Log into the Raspberry Pi and type the following command:
sudo apt-get install python-dev
This command will install the python development tools required to use the GPIO ports. A prompt may come up asking if you would like to install the package. Enter Yes or Y to continue. After the installation of the package is complete type:
sudo apt-get install python-rpi.gpio
This will install the RPI GPIO package. Again enter Yes or Y to continue if prompted.
Step 2: Setup Raspberry Pi I2C Interface
In order to use the I2C interface for the Raspberry Pi it will first need to be enabled under the Raspberry Pi configuration interface. In the command prompt type:
to bring up the configuration control panel. Choose Advanced Options
Under Advanced Options choose I2C to enable the I2C interface
A prompt will come up asking if you would like to enable the interface. Choose Yes to continue. Another prompt will come up saying that the I2C interface is enabled. Press Enter to continue. A third prompt will display asking if you would like the I2C kernal to be loaded by default. Choose Yes.
Another screen will display saying that the I2C kernal will be loaded by default. Choose Finish at the main screen. Reboot the Raspberry Pi by typing:
Wait about a minute for the Raspberry Pi to reboot and log back into the Raspberry Pi using your SSH client. We will now make sure all of the kernal modules are configured properly to load at boot time. In the command prompt type
sudo nano /etc/modules
This will start Nano, a built in text editor, in Raspian. Add i2c-bcm2708 and i2c-dev to the bottom of the file if not already there.
Press CTRL-X, you will be prompted to save. Type Y and press Enter and then Enter again to return command prompt. In the command type:
sudo nano /boot/config.txt
In this file enter dtparam=i2c=on1=on and dtparam=i2c_arm=on at the end of the file if not already there.
Press CTRL-X, you will be prompted to save. Type Y and press Enter and then Enter again to return command prompt. Reboot the Raspberry Pi by typing:
The Raspberry Pi is now configured to use the I2C and GPIO interfaces. In the next tutorial we will walk through creating a test circuit and testing the two interfaces.