Arnaud
Posts: 3
Joined: Mon Jun 15, 2015 12:03 pm
Location: Luxembourg

Usage of L293D and MPU6050

Sat Sep 19, 2015 5:38 pm

Hello Everybody,

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

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.

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK

Re: Usage of L293D and MPU6050

Sat Sep 19, 2015 6:31 pm

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!

Arnaud
Posts: 3
Joined: Mon Jun 15, 2015 12:03 pm
Location: Luxembourg

Re: Usage of L293D and MPU6050

Sat Sep 19, 2015 7:00 pm

Thanks for your reply ! I will test it.

The weird thing us that it never happens when using the mpu6050 alone. But it is quite systematic when using mpu6050 with l293d ... I do not understand :-(

Return to “Troubleshooting”