I am new in the Raspberry community and I would like to start a project: to build a self balancing robot (

In order to achieve this goal, I am working step by step
1/ Using the L293D chip to control motors. I followed the tutorial https://learn.adafruit.com/adafruit-ras ... tor/lm293d. As it was well explained I succeeded, it works as expected. I am able to control 2 motors independently.
2/ Using the MPU050. I followed these tutorials and it also works.
http://blog.bitify.co.uk/2013/11/interf ... -6050.html
http://blog.bitify.co.uk/2013/11/readin ... berry.html
So ... good so far.
3/ Now I am trying to use both functionnalities together, and this is where troubles start.
In general, I can say that it works correctly: I am able to change to behaviour of both motors depending on values retrieved by the MPU6050.
But from time to time I am encountering random errors while reading value from the MPU6050 : IOerror=[errno5] input/output error
To be honest, I do not really understand what could lead to this non predictable behaviour.
Does anyone have an idea of a possible reason for this behaviour ?
(I am going to attach the code to my post).
Thanks in advance.