A little update on the hanging issue: I've tracked it down to the first call of a I2C function, in most cases this occurs during the initialize() function which calls some sort of writeBits()
To get around this, I've put a bit of the standard I2C bus scanner into the code, right after the Wire.begin():
// test the connection to the I2C bus, sometimes it doesn't connect
// keep trying to connect to I2C bus if we get an error
boolean error = true;
while (error) {
Wire.beginTransmission(mpu.getAddr());
error = Wire.endTransmission(); // if error = 0, we are properly connected
if (error) { // if we aren't properly connected, try connecting again and loop
Serial.println(" ");
Serial.println("Not properly connected to I2C, trying again");
Serial.println(" ");
Wire.begin();
TWBR = 24; // 400kHz I2C clock
}
}
Serial.println("Properly connected to I2C");
I also ended up writing my own library function getAddr() - if you want to try this code yourself, just replace that function with 104 (if you've got the AD0 pin low or 105 if it's high).
I'm hoping this will fix things; I haven't been able to confirm since I can't reproduce the hang on my own (it seems intermittent).