[Errno 5] Input/output error when trying to use motors

I am running BrickPi_Python/Sensor_Examples/LEGO-Motor_Test.py. Motors may run a few times, then they stop and I get an error:

} sudo python3 LEGO-Motor_Test.py
Running Forward
Traceback (most recent call last):
  File "LEGO-Motor_Test.py", line 39, in <module>
    BrickPiUpdateValues()       # Ask BrickPi to update values for sensors/motors
  File "/usr/local/lib/python3.4/dist-packages/BrickPi-0.0.0-py3.4.egg/BrickPi.py", line 569, in BrickPiUpdateValues
  File "/usr/local/lib/python3.4/dist-packages/BrickPi-0.0.0-py3.4.egg/BrickPi.py", line 684, in BrickPiFlush
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 435, in inWaiting
    s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
OSError: [Errno 5] Input/output error

Less frequently I get a different error:

} sudo python3  LEGO-Motor_Test.py
Running Forward
Running Backward
Running Forward
Running Backward
Running Forward
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 308, in _reconfigurePort
    orig_attr = termios.tcgetattr(self.fd)
termios.error: (5, 'Input/output error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "LEGO-Motor_Test.py", line 39, in <module>
    BrickPiUpdateValues()       # Ask BrickPi to update values for sensors/motors
  File "/usr/local/lib/python3.4/dist-packages/BrickPi-0.0.0-py3.4.egg/BrickPi.py", line 572, in BrickPiUpdateValues
  File "/usr/local/lib/python3.4/dist-packages/BrickPi-0.0.0-py3.4.egg/BrickPi.py", line 716, in BrickPiRx
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 378, in setTimeout
    if self._isOpen: self._reconfigurePort()
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 311, in _reconfigurePort
    raise SerialException("Could not configure port: %s" % msg)
serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')

Issue happens both with a USB charger and the 8 batteries pack. I have installed the latest Raspbian, and then modified my own image following the provided instructions.

} uname -a
Linux raspberrypi 4.4.26-v7+ #915 SMP Thu Oct 20 17:08:44 BST 2016 armv7l GNU/Linux

Sample program LED.py works fine.

Based on what I read in the forum, I have tried disabling getty with

sudo systemctl disable serial-getty@ttyAMA0.service

and uncommented two lines in /root/config.txt

dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

but no improvement.

Anything I can do to collect additional information for troubleshooting?

I have found this post that gives the solution. My cmdline.txt now is:

} cat cmdline.txt
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

Hi @Francesco_F,

Glad that it works for you and thanks for sharing the solution in this topic. We have our custom OS named Raspbian For Robots which is best suited for our robots. This image works well with our examples and you can learn more about this here.

Also check if everything is working well for you and get back to us if any help needed.

-Shoban