mpu6050 icon indicating copy to clipboard operation
mpu6050 copied to clipboard

OSError: [Errno 121] Remote I/O error

Open kodecreer opened this issue 4 years ago • 8 comments

  File "/home/pi/.local/lib/python3.7/site-packages/mpu6050/mpu6050.py", line 60, in __init__
    self.bus.write_byte_data(self.address, self.PWR_MGMT_1, 0x00)
OSError: [Errno 121] Remote I/O error

I2C is enabled

kodecreer avatar Sep 19 '19 05:09 kodecreer

For me, this error was because I had connected the mpu up to the wrong pins

mdsimmo avatar Nov 26 '19 01:11 mdsimmo

The raspberry has two I²C busses.

bus 0: pins 27, 28 bus 1: pins 3,5 (default)

If you connected the mpu6050 to 27 and 28 you will have to specify bus=0:

from mpu6050 import mpu6050
sensor = mpu6050(0x68, bus=0)
accelerometer_data = sensor.get_accel_data()

If you're using the wrong bus you'll also get the OP's error.

For more info about the pins see: https://pinout.xyz/pinout/i2c

toonijn avatar Apr 05 '20 10:04 toonijn

Hey I didn't know this. Thanks @toonijn!

m-rtijn avatar Apr 05 '20 10:04 m-rtijn

I am seeing the same error, but on the second time I run my code; works fine on start up and first run. The first time, the sensors works, and I can read data. If I stop the code to make a change (been tweaking how it writes to file), when I restart it, the second time I get the error. Works fine on start up and first run.

danchendrickson avatar Nov 10 '21 20:11 danchendrickson

@danchendrickson I2C gets picky if you don't close everything neatly, I think that could cause your issue.

m-rtijn avatar Nov 19 '21 17:11 m-rtijn

I am getting the same error as Errno 121 Remote I/O error even after I have the correct addresses shown with the i2cdetect command.

maryam0707 avatar Jan 22 '22 14:01 maryam0707

I have trouble using your lib and respective sensort with other i2c devices. I think the problem is the smbus not being closed properly after each interaction on the bus. I am a newbie as well. I looked in another lib where the bus.close() function is called. I wonder if you could have an example explaining this, because I get an I/O error every time. Thanks for the lib, it helped me already a lot!

spaceKelan avatar Jun 26 '22 18:06 spaceKelan

@spaceKelan Interesting. It indeed seems that I never implemented a mpu6050.close() method or something similar. It should be easy to implement though, just add the following code to mpu6050/mpu6050.py, after line 75:

def close(self):
    """Close the i2c bus. Make sure you don't use the object afterwards"""
    self.bus.close()

The problems might also be caused by unsafe exiting of a python program, I think.

m-rtijn avatar Jun 27 '22 20:06 m-rtijn

The raspberry has two I²C busses.

bus 0: pins 27, 28 bus 1: pins 3,5 (default)

If you connected the mpu6050 to 27 and 28 you will have to specify bus=0:

from mpu6050 import mpu6050
sensor = mpu6050(0x68, bus=0)
accelerometer_data = sensor.get_accel_data()

If you're using the wrong bus you'll also get the OP's error.

For more info about the pins see: https://pinout.xyz/pinout/i2c

Sorry for such a late reply, I was using pins 3 and 5, and it works with i2cdetect -y 1 pulling up address 0x68 as expected.

 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --

Just right when I try to load it in the library is when it has issues (even still after over 3 years) it still has the same problem). Also I verified that the pins I was using is 3 and 5.

kodecreer avatar Aug 18 '22 01:08 kodecreer

Alright so the answer was super simple. It was cheap and faulty due to my soldering. Since it's pretty cheap I just bought a new set and soldered it worked perfectly fine.

Lesson of the story is, there might be a slight chance you just have a fault accelerometer. It's cheap for a reason.

kodecreer avatar Aug 20 '22 02:08 kodecreer