It turns out the arduino is starting but it stops in the setup routine.
I pulled the arduino out of my project and removed the shield, loaded up blink and it worked every time. I put it all back together and started adding Serial.println commands at various placed until I located the place where it stops. i am using an MPU6050 And when its MPU6050_setup is called, it calls the MPU6050_read routine. In that routine there is a Wire.beginTransmission , a Wire.write, and a Wire.endTransmission.
When things lockup, I see the message, “Before Wire.endTransmission” but not the message, “After Wire.endTransmission”. It always locks at this point and always the first time through. So I believe I have located where the trouble is, now I have to isolate the cause. There are no other I2C devices on this project so no possible conflicts.
Since it always locks up the first time through, I will try using a short delay before setting up the MPU6050 in case it needs to stabilize. If that doesn’t help, there is about 2’ of unshielded 4-wire cable between the arduino and the mPU6050. I can make up a short cable to see if that helps. I might also try putting a bypass cap at the MPU6050 between 5V and Gnd to see if that helps. I am using the default Wire library so i’m guessing/hoping that is fairly stable.
// MPU6050_read n bytes
int MPU6050_read(int start, uint8_t *buffer, int size)
int i, n, error;
// Serial.println("Before Wire.beginTransmission ");
// Serial.println("After Wire.beginTransmission ");
n = Wire.write(start);
// Serial.println("After Wire.write ");
if (n != 1)
n = Wire.endTransmission(false); // hold the I2C-bus
if (n != 0)
// Third parameter is true: relase I2C-bus after data is read.
Wire.requestFrom(MPU6050_I2C_ADDRESS, size, true);
i = 0;
while (Wire.available() && i < size)
buffer[i++] = Wire.read();
if ( i != size)
return (0); // return : no error