help! sensor failure due to motors - balancing robot almost working

I’m trying to build a balancing robot and I’m almost done, but having a serious problem with motor feedback causing the gyro to fail to read the input. After the gyro fails, the motors continue to turn, but are not responsive to the position of the robot.

I’ve tried to add capacitors at every terminal (which already has helped), but still is too much interference when the motors.

Components:
Arduino Mega 2560
Arduino Motor Shield (with Vin Connect is cut)
OSEPP gyroscope (MPU-3050) I2C connection –(connected to 3.3V and ground pins)
OSEPP accelerometer (ADXL345) I2C connection
Accelerometer connected to gyro auxiliary output
Tamiya dual gearbox (2 motors 1.5-3V)
4AA batteries connected to motor shield
9V battery (connected to Vin and ground ground pins)

Capacitors placed everywhere, lol.
• 10uF capacitors between motor terminals
• 10uF capacitors between arduino motor input terminals
• 10uF capacitor between I2C 3.3V and ground pins
• 221uF capacitors between 4AA battery terminal on arduino motor shield
• 221uF capacitors between 9V battery terminal on Arduino Mega

code included in attachment

BalanceBotCode_Deuce_Legend.txt (9.44 KB)

pics of balance bot included

Sample Serial output:

Format of data:
AccX, AccY, AccX (in G's); GyroX, GyroY, GyroZ (deg per sec); AccAngleX (atan2(x,z)), AccAngyleY(atan(y,z)); Angle: gyroAngle, complementary filter, kalman filter; PID Output, LastUsefulLoopTime, LastLoopTIme;

Acc: -0.00, -0.06, 0.78, Gyro: 28.08, -45.30, 4.85, Acc: -0.29, -4.29, angle: 2.94, -2.24, 1.01, PID: -34.68, 34, 4, 10
Acc: -0.34, -0.00, 0.94, Gyro: -14.65, -32.13, -12.36, Acc: -19.85, -0.24, angle: -1.65, -7.38, -5.08, PID: 50.38, 50, 3, 9
Acc: -0.16, 0.01, 0.86, Gyro: -32.86, 5.65, -1.84, Acc: -10.51, 0.52, angle: 1.83, -4.39, -1.98, PID: 193.91, 193, 3, 9
Acc: -0.03, 0.09, 0.98, Gyro: -27.07, 21.89, -6.39, Acc: -1.60, 5.48, angle: 6.71, 2.21, 0.48, PID: -146.88, 146, 3, 9
Acc: 0.18, -0.10, 0.81, Gyro: 15.84, -13.77, 1.69, Acc: 12.26, -6.89, angle: 13.77, 6.08, 2.53, PID: -250.00, 250, 4, 9
Acc: -0.11, -0.12, 0.86, Gyro: 11.25, -25.00, -0.27, Acc: -7.03, -8.31, angle: 10.37, -10.70, -6.79, PID: 179.74, 179, 3, 10
Acc: 0.38, 0.14, 0.89, Gyro: 6.80, 4.80, 22.65, Acc: 23.26, 8.97, angle: 21.55, 8.00, 6.63, PID: -102.31, 102, 4, 9
Failed to read gyroscope
Acc: 0.41, -0.11, 0.80, Gyro: 22.51, -46.38, -10.63, Acc: 26.79, -8.01, angle: 25.06, 5.71, 3.70, PID: -224.00, 223, 4, 9