Skip to content
FR
  1. LuzineDebug
  2. Electronics & Arduino
  3. OSError: [Errno 121] Remote I/O error
Electronics & Arduino Intermediate ≈ 15 min to fix

Fix "OSError: [Errno 121] Remote I/O error" with I2C on Raspberry Pi

Error message
OSError: [Errno 121] Remote I/O error
  • IOError: [Errno 121] Remote I/O error
  • OSError: [Errno 5] Input/output error
  • ValueError: No I2C device at address: 0x3c
  • Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
  • FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'
In short

The I2C bus is open, but no device answered at the requested address. Run i2cdetect -y 1 to see the module's real address, then check the SDA/SCL wiring, the common ground and the 3.3 V supply. If /dev/i2c-1 does not exist, enable I2C in raspi-config first.

Be the first to confirm this fix

What this error means

Errno 121 (EREMOTEIO) is returned by the Linux kernel I2C driver when the master sends the device address and gets no acknowledgement (ACK). So Python could open /dev/i2c-1, but nothing answered at that address: wrong address, module badly wired or unpowered, degraded signal. The error can also be intermittent if the sensor is busy or the bus is too long. Do not confuse it with [Errno 2] No such file or directory: '/dev/i2c-1', which means the I2C interface is not enabled.

Common causes

  1. Wrong address: a PCF8574 LCD answers at 0x27 or 0x3F depending on the chip, a BME280 at 0x76 or 0x77, an OLED at 0x3C or 0x3D. Writing 27 instead of 0x27 (decimal instead of hex) gives the same error.
  2. Wiring: SDA and SCL swapped, ground (GND) not connected, loose Dupont wire. On the 40-pin header, SDA is pin 3 (GPIO2) and SCL is pin 5 (GPIO3).
  3. Power and logic levels: 5 V module powered at 3.3 V, or a module powered at 5 V whose pull-up resistors pull SDA/SCL to 5 V, which the Raspberry Pi GPIOs (3.3 V) do not tolerate.
  4. Pull-ups and bus length: the Raspberry Pi has built-in 1.8 kΩ pull-ups on GPIO2/3, but long wires, too many modules or a bare chip on another bus degrade the signal.
  5. Intermittent errors: sensor busy during a measurement, read too soon after power-up, or using clock stretching, which the I2C controller of some Raspberry Pi models handles poorly.

Step-by-step fix

  1. Enable I2C

    If /dev/i2c-1 does not exist, enable the interface: sudo raspi-config > Interface Options > I2C > Yes, or in one command. This adds dtparam=i2c_arm=on to /boot/firmware/config.txt (/boot/config.txt before Bookworm). Then reboot.

    bash
    sudo raspi-config nonint do_i2c 0   # 0 = enable
    sudo reboot
    ls /dev/i2c-*
  2. Scan the bus with i2cdetect

    Install i2c-tools and scan bus 1. Each number shown is the address of a responding device; -- means nothing at that address, and UU that a kernel driver is already using the device. If the grid is empty, the problem is hardware (wiring or power).

    bash
    sudo apt install -y i2c-tools
    i2cdetect -y 1
    #      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    # 20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
  3. Use the exact address, in hex

    Use the address shown by i2cdetect in your code, written in hex (0x27). Install smbus2 in a virtual environment, then test a simple read with error handling.

    python
    # python3 -m venv .venv && . .venv/bin/activate && pip install smbus2
    from smbus2 import SMBus
    
    ADDRESS = 0x27  # from i2cdetect -y 1
    
    with SMBus(1) as bus:
        try:
            value = bus.read_byte(ADDRESS)
            print(f"0x{ADDRESS:02x} answered: {value}")
        except OSError as e:
            print(f"no answer at 0x{ADDRESS:02x}: {e}")
  4. Check the wiring, board powered off

    Shut down the Raspberry Pi before touching the wires. Connect VCC to pin 1 (3.3 V), GND to pin 6, SDA to pin 3 (GPIO2) and SCL to pin 5 (GPIO3). This pinout is the same on Pi 3, 4 and 5. Test one wire at a time with a multimeter if in doubt.

  5. Respect 3.3 V and 5 V levels

    Power the module at 3.3 V if it supports it. If the module needs 5 V (many PCF8574 LCDs), use a bidirectional level shifter (BSS138 type) between the Pi and the module, or remove the module's 5 V pull-ups. Never connect lines pulled up to 5 V directly to the Pi's GPIOs.

  6. Intermittent errors: slow the bus down and retry

    Keep wires short, let the sensor start up before the first read and add a few retries. If the error persists, lower the bus frequency (100 kHz by default) in config.txt, then reboot.

    ini
    # /boot/firmware/config.txt
    dtparam=i2c_arm=on
    dtparam=i2c_arm_baudrate=50000

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • Run i2cdetect -y 1 after every wiring change, before writing any code.
  • Store each module's address in a constant at the top of the script, and avoid two modules with the same address on one bus.
  • Always use a level shifter with 5 V modules, and keep I2C wires short.

Frequently asked questions

i2cdetect shows no address, what now?

The module does not answer at all: check the power (is the module LED on?), the common ground and the SDA/SCL order. Try another module or other wires to isolate the problem.

What does UU mean in i2cdetect?

A kernel driver (loaded by a dtoverlay) has claimed that device. Use that driver's interface, or remove the overlay from config.txt to access it directly from Python.

Errno 121 or Errno 5, what is the difference?

Errno 121 means no device acknowledged its address. Errno 5 (Input/output error) rather signals a transfer interrupted midway: degraded signal, timeout or clock stretching. The wiring and bus speed checks are the same.

Permission denied on /dev/i2c-1?

Add your user to the i2c group with sudo usermod -aG i2c $USER, then log in again. Avoid running the whole script with sudo.

Useful tools for this error

More Electronics & Arduino errors

All Electronics & Arduino errors →