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>
enableMotors(100,0)
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?