I built a small Arduino "robot" on a tracked chassis. The device uses MPU-5060 for direction finding (on a prototype shield) and Adafruit MotorShield v2 to control two 320-type motors. The goal at the moment is to simply be able to turn in 90 degree increments.
All communications between the devices happen on I2C bus. The motors have their own power supply, and the logic boards have their own. The I2C uses 4.7K pull-up resistors for 5v voltage. I tried 400K and 100K frequency on I2C
I wrote a bunch of code using the I2Cdev library and AdaFruit's own library for controlling the motors.
The problem is, as long as motors' power supply is off or at least the the motors are not connected to it (using LEds instead of motors) all the code works correctly.
When I turn on the motors, in a few seconds the I2C bus freezes. Even if I reset the Arduino, the motors stay running and the initialization of the MPU fails (it involves pumpung ~2K across the I2C bus and verifying the data reading it back. The read-back does not match, which tells me that I2C is still unstable).
I tried putting 0.1 uF capacitors across the motors, it does not help. I tried running motors on their own w/o connecting them to the controller - that does not reproduce the issue, so I think this rules out the RF interference. I don't have an osciloscope, and I am no tsure how I would use it to diagnise this issue anyway.
Could someone suggest what would be a good next step? I donot know what else I can do...
Update: The puctures of the setup.
The connections on th elogical boards are plain to see, an I will try to add some schematics later.
Thanks everyvbody for the responses and comments.
I decided to try these steps in the following order:
- Change the layout by flipping the Arduino around. This will get my motor wires to be maybe 1.5cm long and vertical, so the opportunity for the interference is minmized.
- Use shielded cable for the motor battery wires.
- Change the pull-up resistors to below 2K.
Will see if any of it helps.
Also, as promised, the schematics. The most important part is the motor shield:
It does have its own 10K pull-up resistors.
Items 1 and 2 done, very little improvement.
Here is what the system looks like now:
Note that the wires fromthe motors are vertical and as short as I can make them.
The shielded cable for motor power is grounded at the battery end to the "-" terminal of the battery.
As an "extra", I added 2 more capacitors to each motor as described here in the "Three-capacitor filter" section.
Will try item 3 later.
Update! I've given this puzzle to a more experienced friend. He went ahead and added a huge capacitor to the battery that feeds the motors (2500 microfarads). The problem stopped.
My question now is: why??? The current from that battery should never be anywhere near the control board...