[ Prev ] [ Index ] [ Next ]

1. i2cdetect

Created Wednesday 11 January 2017

If you haven't already interracted with I2C peripherals using your Linux device, begin by looking to see if support is currently available.
Using the ls command, look for i2c
$ ls -l /dev/i2c*
crw------- 1 root root 89, 1 Dec 31 1969 /dev/i2c-1
crw------- 1 root root 89, 2 Dec 31 1969 /dev/i2c-2
crw------- 1 root root 89, 3 Dec 31 1969 /dev/i2c-3

From the above output, we can see there are three I2C busses, each of which may have a number of devices on them.

If you don't see an I2C bus....
On the raspberry Pi, run the raspconfig program. From there, enable the I2C bus.


Assuming your Linux device has i2c-tools installed...
Use i2cdetect to display the different I2C busses:
$ i2cdetect -l
crw------- 1 root root 89, 1 Dec 31 2016 /dev/i2c-1
crw------- 1 root root 89, 2 Dec 31 2016 /dev/i2c-2
crw------- 1 root root 89, 3 Dec 31 2016 /dev/i2c-3

From the above output, we can see there are three busses (again), and their names.

A Raspberry Pi will typically have /dev/i2c-1 I2C bus available
Using i2cdetect, display the different devices on /dev/i2c-1 bus:
$ i2cdetect 1
Error: Can't use SMBus Quick Write command on this bus

$ i2cdetect -y 1
Error: Can't use SMBus Quick Write command on this bus

$ i2cdetect -y -r 1
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- 12 -- UU -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- UU -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- --
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- UU -- UU -- -- —

The above example shows 7 I2C devices were found on I2C bus 1.
The "UU" indicates devices owned by the kernel, being managed by a device driver. The remaining devices are available for users to interract with (no owner). This example is from a control system (not a Raspberry Pi). If you don't see any devices, that may just mean you haven't attached anything to the I2C bus yet. The "i2cdetect" tool is where you always want to start. If the tool can't see it, there's a problem. Check your wiring. Some modules have multiple I2C peripherals on them, such as many of the DS3231 boards. They usually contain a DS3231 RTC at I2C address 0x68, and a AT24C32 EEPROM at I2C address 0x56.

$ i2cdetect -y -r 1
 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- 56 -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- —-

Home Page