Fix "OSError: [Errno 121] Remote I/O error" with I2C on Raspberry Pi
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'
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.
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
- Wrong address: a PCF8574 LCD answers at
0x27or0x3Fdepending on the chip, a BME280 at0x76or0x77, an OLED at0x3Cor0x3D. Writing27instead of0x27(decimal instead of hex) gives the same error. - 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).
- 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.
- 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.
- 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
-
Enable I2C
If
/dev/i2c-1does not exist, enable the interface:sudo raspi-config> Interface Options > I2C > Yes, or in one command. This addsdtparam=i2c_arm=onto/boot/firmware/config.txt(/boot/config.txtbefore Bookworm). Then reboot.sudo raspi-config nonint do_i2c 0 # 0 = enable sudo reboot ls /dev/i2c-* -
Scan the bus with i2cdetect
Install
i2c-toolsand scan bus 1. Each number shown is the address of a responding device;--means nothing at that address, andUUthat a kernel driver is already using the device. If the grid is empty, the problem is hardware (wiring or power).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 -- -- -- -- -- -- -- -- -
Use the exact address, in hex
Use the address shown by
i2cdetectin your code, written in hex (0x27). Installsmbus2in a virtual environment, then test a simple read with error handling.# 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}") -
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.
-
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.
-
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.# /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 1after 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
- Fix "avrdude: stk500_getsync(): not in sync" on Arduino
- Fix "Failed to connect to ESP32" (Wrong boot mode, No serial data received)
- Fix "Brownout detector was triggered" on ESP32
- Fix "can't open device /dev/ttyUSB0: Permission denied" (Arduino, ESP32)
- Fix "Guru Meditation Error: Core 1 panic'ed (LoadProhibited)" on ESP32
- Fix "error: 'x' was not declared in this scope" (Arduino, C++)
- Fix "Sketch too big" on Arduino and ESP32 (flash memory full)