I2C on Raspberry Pi -
OS and Library Install
If you’re starting from scratch, with a blank microSD card, you’ll want to install Raspbian. If you’ve
already got a working Raspbian system, skip ahead to step 3.
1.
Download the
NOOBS
image. As of this writing, it’s at version 2.4.4.
2.
Follow the official
installation instructions
.
3.
Follow the
Wiring Pi Instructions
to get
git
, update and upgrade your Rasbpian packages,
then install WiringPi.
Be patient
– each of these steps takes a while.
Once you’ve got wiringPi installed, run the
gpio
commands shown below.
COPY CODE>gpio -v
>gpio readall
It should respond with some information about the wiringPi version and the Pi that its running on,
then draw a table illustrating the configuration for the pins in the 40-pin connector.
Configuration
Like the SPI peripheral, I2C is not turned on by default. Again, we can use
raspi-config
to enable it.
1.
Run
sudo raspi-config
.
2.
Use the down arrow to select
5 Interfacing Options
3.
Arrow down to
P5 I2C
.
4.
Select
yes
when it asks you to enable I2C
5.
Select
OK
and then
Finish
Once you return to terminal, enter this command
COPY CODE>ls /dev/*i2c*
The Pi should respond with
COPY CODE/dev/i2c-1
Which represents the user-mode I2C interface.