i2cget
Read I2C device register value
TLDR
Read from a register of an I2C device
Read from a register of an I2C device without asking for confirmation
Read from a register of an I2C device using a specific mode
SYNOPSIS
i2cget [-y|-f] [-V] [-q] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
PARAMETERS
I2CBUS
The number of the I2C bus to communicate with (e.g., 0, 1). This typically corresponds to /dev/i2c-N.
CHIP-ADDRESS
The 7-bit hexadecimal address of the I2C device on the specified bus (e.g., 0x50). This is a required argument.
DATA-ADDRESS
Optional. The hexadecimal address of the register or memory location within the chip to read from (e.g., 0x00). If omitted, a direct byte read (c mode) is performed.
MODE
Optional. Specifies the read mode. Common modes include:
b: Read a single byte from DATA-ADDRESS. (Default if DATA-ADDRESS is provided)
w: Read a 16-bit word (two bytes) from DATA-ADDRESS.
c: Read a single byte directly from the device (no DATA-ADDRESS is sent). (Default if DATA-ADDRESS is omitted)
B: Perform an SMBus block read, returning up to 32 bytes.
-y
Disable interactive mode. Assumes 'yes' to all prompts, useful for scripting.
-f
Force access to the I2C bus, even if it is busy. Use with extreme caution as it can cause bus conflicts or data corruption.
-V
Display the version number of i2cget and exit.
-q
Quiet mode. Suppress standard output, useful when only the exit status matters.
DESCRIPTION
i2cget is a utility from the i2c-tools package designed to read data from I2C or SMBus client devices connected to an I2C bus. It provides a simple command-line interface for low-level interaction with these devices. Users specify the I2C bus number, the 7-bit chip address of the target device, and optionally a data address (register) within the device to read from. The command supports various read modes including a single byte read, a word read (two bytes), or a block read, depending on the device's capabilities and the desired interaction.
This tool is invaluable for debugging I2C device drivers, verifying hardware connectivity, and directly manipulating device registers during development or system bring-up. It acts as a direct interface to the I2C kernel driver, translating command-line arguments into I2C bus transactions. It's commonly used to read sensor data, EEPROM contents, or status registers.
CAVEATS
Using i2cget typically requires root privileges (e.g., sudo) to access the I2C device files. Improper use of CHIP-ADDRESS, DATA-ADDRESS, or MODE can lead to incorrect readings, bus hangs, or even damage to I2C devices. The i2c-dev kernel module must be loaded for i2cget to function correctly. The -f (force) option should be used with extreme caution, as it bypasses safety checks and can interfere with other processes or hardware on the bus.
PERMISSIONS
Due to direct hardware access to /dev/i2c-* devices, i2cget usually requires superuser (root) privileges. It's common to prefix the command with sudo.
BUS CONFLICTS AND SAFETY
If other processes or kernel drivers are actively using the I2C bus, i2cget might fail or cause conflicts. The -f option can bypass some safety checks, but it increases the risk of system instability or corrupting ongoing I2C transactions.
ADDRESS FORMAT
Both CHIP-ADDRESS and DATA-ADDRESS are typically specified in hexadecimal format. You can use the 0x prefix (e.g., 0x50) or simply provide the hexadecimal value (e.g., 50).
OUTPUT FORMAT
The command typically outputs the read value in hexadecimal format.
HISTORY
i2cget is part of the i2c-tools project, an open-source collection of utilities developed to provide command-line interaction with I2C and SMBus devices on Linux. Its development has closely tracked the evolution of the Linux kernel's I2C subsystem, making it an essential tool for developers and engineers working with embedded systems and hardware interfacing. It has been a staple in the i2c-tools suite for many years.