How to Enable i2c on the Raspberry Pi

i2c is a communication protocol that runs over a two wire bus. The two wires are called SDA (Serial Data) and SCL (Serial Clock). The i2c bus has one or more masters (the Raspberry Pi) and one or more slave devices, like the LSM6DSL on the BerryIMU . As the same data and clock lines are shared between multiple slaves, we need some way to choose which device to communicate with. With i2c, every device has an address that each communication must be prefaced with.

How to enable i2c on the Raspberry Pi

pi@raspberrypi ~ $ sudo raspi-config
select #3 Interface Options

Raspberry Pi i2c

Select I4 I2C

Raspberry Pi i2c

Hit Yes

Raspberry Pi i2c

If you have an I2C device connect, you can check for any components connected to the i2c bus by using i2cdetect;

pi@raspberrypi ~ $ sudo i2cdetect -y 1

Or port 0 on the older Raspberry Pi

pi@raspberrypi ~ $ sudo i2cdetect -y 0

A table like the table below will be shown and if any divices are connected, thier address will be shown. Below you can see that a device is connected to the i2c bus which is using the address of 0x6b.

pi@raspberrypi ~ $ sudo /usr/sbin/i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — —
10: — — — — — — — — — — — — 1c — — —
20: — — — — — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — 6a — — — — —
70: — — — — — — — 77

Blip, blop, bloop…