I'm building an autonomous robot controlled by a Raspberry Pi 3 and I'm having a problem reading the sensor.

I'm using an H Bridge board to activate the motors and an I2C gyroscope sensor (MPU6050) both work perfectly in separate tests, but when I use both at the same time the following error occurs in the sensor reading:

Traceback (most recent call last):
File "/home/corcel/Documentos/trekking/src/control.py", line 44, in <module>
File "/home/corcel/Documentos/trekking/src/control.py", line 29, in enableMotors
    gyro = readAngularSpeed()
File "/home/corcel/Documentos/trekking/src/gyro.py", line 28, in readAngularSpeed
    rawZ = (i2c.read_byte_data(GYRO_ADDRESS, 0x47) << 8) | i2c.read_byte_data(GYRO_ADDRESS, 0x48)
File "/home/corcel/.local/lib/python3.9/site-packages/smbus2/smbus2.py", line 433, in read_byte_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error

I noticed that for some reason this error only happens when the motors are actually activated, even if I connect the H bridge in the circuit the error does not happen as long as the motors are not connected to it.

I've tried using optocouplers to isolate the Raspberry Pi circuit from the rest, but the error still persists. Has anyone gone through something similar or have any idea what could be going on?

  • 3
    You need to add circuit details and indicate which GPIO are being used and show the connections.
    – joan
    Nov 9, 2022 at 20:39

1 Answer 1


Do you power the raspberry pi and the motors from the same source? The motors will draw quite some current. So, when they get activated, there will by some spikes on the power source which might affect the raspberry pi if both are powered from the same source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.