You have an I2C device attached to your Raspberry Pi, and you want to know how to check that it’s attached and to find its I2C address.
Install and use i2c-tools.
On newer distributions, you may find that i2c-tools is already installed.
From a Terminal window on your Pi, type the following commands to fetch and install the i2c-tools:
$ sudo apt-get install i2c-tools |
Attach your I2C device to the Pi and run the command:
$ sudo i2cdetect -y 1 |
Note that if you are using an older revision 1 board, you need to change 1 to 0 in the preceding code line.
If I2C is available, you will see some output like that shown in Figure 8-3. This shows that two I2C addresses are in use—0x40 and 0x70.
Discussion
i2cDetect is a useful diagnostic tool and one that is worth running the first time you use a new I2C device.
See Also
See some of the I2C recipes in this book: Recipes 10.2, 13.1, 13.2, and 13.4.
For more information on installing with apt-get, see Recipe 3.16.