Skip to content

i2c-tools

14 commands

Utilities to detect, read and write devices on an I²C bus: i2cdetect, i2cget, i2cset and i2cdump.

  • I2C
  • hardware
  • embedded

Install i2c-tools

sudo apt install i2c-tools

Discovering4

i2cdetect -l

Lists the I²C buses on the system.

i2cdetect -y 1

Scans bus 1 and shows a grid of responding 7-bit addresses. -y skips the confirmation prompt.

Link
i2cdetect -y -r 1

Scans with read-byte commands instead of quick-write — safer for some write-sensitive chips.

Link
i2cdetect -F 1

Shows what the bus adapter supports.

Link

Reading4

i2cget -y <bus> <addr> <reg>

Reads one register. 0xD0 on a BME280 at 0x76 returns its chip ID (0x60).

Link
i2cget -y <bus> <addr> <reg> w

Reads a 16-bit word. Note the byte order may be swapped relative to the datasheet.

Link
i2cdump -y <bus> <addr>

Dumps all 256 registers — on an EEPROM at 0x50 this reads stored data.

Link
i2cdump -y -r <start>-<end> <bus> <addr>

Dumps only a range of registers.

Link

Writing3

i2cset -y <bus> <addr> <reg> <value>

Writes a byte to a register — here, setting all pins of an MCP23017 as outputs.

Link
i2cset -y <bus> <addr> <reg> <value> w

Writes a 16-bit word.

Link
i2ctransfer -y <bus> w<n>@<addr> <bytes> r<m>

Combined write-then-read in one transaction — here, setting an EEPROM pointer to 0 and reading 16 bytes.

Link

Setup3

sudo raspi-config nonint do_i2c 0

Enables I²C on a Raspberry Pi.

Link
ls /dev/i2c-*

Confirms the bus device nodes exist.

Link
sudo usermod -aG i2c $USER

Lets your user access I²C without sudo (log out and back in).

Link