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.
3 posts • Page 1 of 1
I get the I2C errors occasionally to when using python SMBus. I _think_ it happens when the MPU6050 is updating the data registers while you are trying to read them. The MPU6050 has a hardware interrupt which you can attach to a GPIO pin, and use GPIO.wait_for_edge(). This will block until the MPU6050 has fresh data to be read. That way, I've been able to mostly avoid those errors. I have the data register sampling set to 500Hz and I do get occasional errors still, but by wrapping the I2C read with a try except loop, you can have another go - something like this:
Code: Select all
while True: try: GPIO.wait_for_edge() result = self.bus.read_byte_data(self.address, reg) break except IOError, err: continue print result
www.pistuffing.co.uk - Raspberry Pi and other stuffing!