I2C Motor Driver and MPU 6050 gyro not working together

Hello, me and my friends are trying to build a self-balancing robot. To get the angle of the robot, we're using a MPU 6050 gyro. It's working in I2C, we have managed to plug it to the grove shield and it's working well. The Motor Driver is wired too in I2C, and is working well alone. Our 2 DC motors are powered with an external battery.

But when we connect the two I2C devices together, it stops working correctly for some reason. For instance, at the moment i plug the I2C Motor Driver into the Grove, the MPU 6050 debug values stop working.

I heard of pull-up resistors but idk if we need to add one.

Do you have any idea of what may cause the issue ?

Thank you :)

You forgot to post all necessary data:

  • no code (post the complete sketch and don’t forget the code tags, the “</>”-button in the editor)
  • no link to the libraries used
  • no wiring diagram
  • no link to the used hardware
  • no mention of the type of Arduino used

I heard of pull-up resistors but idk if we need to add one.

Pull-ups are needed exactly once per bus and if you need it or not depends on the above data.

Thank you for your quick answer ^^.
The card is an Arduino Uno card. If it can help, i’m running Windows 10 x64.
I don’t think the code is involved but anyway:

MPU 6050

Code is in attachment, it’s the “MPU6050_DMP6.ino” example from i2cdev lib.
Link to the library’s github: GitHub - jrowberg/i2cdevlib: I2C device library collection for AVR/Arduino or other C++-based MCUs.

I2C Motor Driver
http://wiki.seeed.cc/Grove-I2C_Motor_Driver_V1.3/
library: GitHub - Seeed-Studio/Grove_I2C_Motor_Driver_v1_3: Grove - I2C Motor Driver v1.3 - L298P&ATmega8L

#include "Grove_I2C_Motor_Driver.h"

// default I2C address is 0x0f
#define I2C_ADDRESS 0x0a

void setup() {
  Motor.begin(I2C_ADDRESS);
}

void loop() {
  // Set speed of MOTOR1, Clockwise, speed: -100~100 
  Motor.speed(MOTOR1, 50);
  // Set speed of MOTOR2, Anticlockwise
  Motor.speed(MOTOR2, -70);
  delay(2000);
  // Change speed and direction of MOTOR1
  Motor.speed(MOTOR1, -100);
  // Change speed and direction of MOTOR2
  Motor.speed(MOTOR2, 100);
  delay(2000);
  // Stop MOTOR1 and MOTOR2
  Motor.stop(MOTOR1);
  Motor.stop(MOTOR2);
  delay(2000);
}

As you can see, i edited the I2C Motor driver address, because i changed it by dial switch (http://wiki.seeed.cc/Grove-I2C_Motor_Driver_V1.3/#2-set-the-address-of-the-i2c-motor-driver)

Grove shield
https://www.seeedstudio.com/Base-Shield-V2-p-1378.html#

I added in attachment the mpu 6050 wiring diagram. We couldn’t find the Grove shield on fritzing so we used instead A4/A5 arduino pins for I2C communication.

The I2C motor driver is directly plugged to an I2C port of the Grove.

MPU6050_DMP6.ino (15.7 KB)

For instance, at the moment i plug the I2C Motor Driver into the Grove, the MPU 6050 debug values stop working.

An I2C bus is not hot pluggable! Never connect or disconnect devices while the system is powered! You may damage your chips.

My guess for your problem is the different voltage of the two devices. You connect the MPU directly to your Arduino which is running on 5V but the input pins should not get more than 3.6V according to the datasheet. As the Sparkfun board has onboard pull-ups to 3V3 you probably have around 3.8V on the bus lines without any data transmission. This is theoretically over the limit for the MPU but may just not damage the chip. I guess you didn't remove jumper J4 on the motor shield. So when you connect the motor shield the 5V from the shield go through the cable to the Arduino. Depending on how you power your Arduino this may lead to a reset of the board and maybe other issues.

Try powering the system up after connecting all components and removing J4 on the motor shield. You should use a (bi-directional) level converter to connect the MPU to the Arduino.

I will try as soon as possible, thank you for your help.

You connect the MPU directly to your Arduino which is running on 5V but the input pins should not get more than 3.6V according to the datasheet

the MPU is connected to the 3.3V output of the arduino.

the MPU is connected to the 3.3V output of the arduino.

Yes, Vcc but the Wire library activates the internal pull-ups to 5V on the Arduino. Together with the pull-ups on the MPU board you get the 3.8V I wrote in the last reply.

Removing the Jumper 4 doesn't seem to be enough :/ We still can't get the i2c motor driver and the mpu to work together ... However, the motor shield is now powered only by the battery. Again, the code is working well for each module ... We didn't try to add a bi-directionnal level converter to the MPU but we're running out of time :(

EDIT: the gyro is working now while the motor driver is plugged, but the motors aren’t spinning …
It might be something wrong with the code, but i can’t understand what …

gyro_motors.ino (6.65 KB)

My guess is that line:

        Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties

I couldn't find any hint in the documentation that the motor driver supports 400kHz I2C, so maybe it just do not.

BTW: It might be interesting for other users trying the same to know what you changed to make the hardware work.

How we managed to make the hardware work:

We followed Pylon's advice and finally after removing the Jumper 4 on the I2C Motor Driver, unplugging everything, resetting the Arduino Uno and the I2C Motor driver to empty capacitors, and plugging back, the MPU 6050 and the I2C Motor Driver were no longer interfering each other. (Although resetting electronic cards may be useless)

I will try to remove that line :)

OK, so now we have another problem ! (I don't know if the nightmare is going to end one day !) We removed the Wire.setClock(400000); and the motors are triggered as it should be, but the only "little" problem we have is that is seems the program crashes at the first time motors are trigerred ... If I comment Motor.speed() or Motor.stop() it doesn't happen ... Every time the program crashes we have to unplug the I2C Motor Driver and plug it back to restart the program.

That sounds like a power supply problem. Motors are rather big inductors so they pull quite some current at start and return it when they're switched off. What kind of motors do you use? Please provide a link to the product.

DC motors
http://www.makeblock.com/25mm-dc-motor-pack-blue

I doubt it is a power supply problem because motors keeps spinning after the “crash”.
A video is worth many words: Vidme (make sure to watch in 480p). In this video you can see that the MPU debug values stop in the serial monitor a few seconds after the program launch.

EDIT: Someone said built-in resistors stack up, could it be the case ?

EDIT: Someone said built-in resistors stack up, could it be the case ?

What do you mean by this sentence? There should be no more than one built-in resistor for each pin.

I doubt it is a power supply problem because motors keeps spinning after the "crash".

That does only mean that the motor shield still has power but there still could be a negative spike in the power supply of the Arduino that let it crash. Please provide a diagram of how you wired the different batteries to the Arduino and the motor driver board as well as the motors. Could you also post a picture of the setup where all connections are visible (if that's possible)?

First i want to apologize for the long time without answer, we weren’t able to advance our project or even manipulate it.

EDIT: Someone said built-in resistors stack up, could it be the case ?

What do you mean by this sentence? There should be no more than one built-in resistor for each pin.

An engineer told us that. I will try to quote him in English as good as I can, sorry for the misunderstanding.

It is probably a pull-up resistors problem. Generally, each equipment incorporates his own resistors. So it works well alone. But as soon as multiple elements are on the bus, resistors become in parallel. So it is recommanded to remove pull-up resistors on the modules, except one.

I put the power supply wiring diagram in attachment, as well as two pictures of our project. The I2C Motor Driver and the DC motors are currently powered by an external power supply (and the Arduino is powered by a computer). We tried too with batteries and it works the same, but for testing purposes the external power supply is more convenient. If you want, i can take a picture of how the external power supply is wired but I think it is ok. The power supply is set to 8V.

I would try to stabilize the I2C bus. Insert a level converter between the main I2C bus and the MPU6050. That way you can drive the motor driver with the standard 5V it expects and still match the voltage range of the MPU6050. If you have a 12V power supply, try that to power the motor board.