Arduino hangs at Wire.requestFrom() when reading MPR121 capacitive touch sensors

I'm having problems with my MPR121 capacitive touch sensors. I am using four of them in my prototype. My Arduino Mega 1280 just hangs after some time of touching the sensors. Sometimes within five seconds, sometimes after a few minutes. They also do it randomly, so it is not one particular MPR121 breakout that causes the program to freeze. The Arduino doesn't crash when the sensors are not touched.

The reason I know it is the touch sensors is because I have been doing some debugging. I played around with digitalWrite (13, HIGH); and digitalWrite (13, LOW); commands. Now I have it configured to turn on the LED, do an I2C command, and turn off the LED. See the code below:

digitalWrite(13, HIGH);
Wire.requestFrom(sensoraddr[i], (byte)2);
digitalWrite(13, LOW);

Whenever the Arduino crashes, the LED blinks continuously. This tells me the error must be in this particular line. In the rest of my code there is nothing turning this LED on or off.

I've also tried a different I2C library:

So I tried using this:

digitalWrite(13, HIGH);
I2c.read(sensoraddr[i], (uint8_t)2);
digitalWrite(13, LOW);

But it leaves me with the same result; a freeze with the LED turned on...

This topic describes quite the same problem, but returns no actual solution:

http://forum.arduino.cc/index.php?topic=92923.0

What could be the problem? Thanks for helping me out!

Whenever the Arduino crashes, the LED blinks continuously.

If it would crash inside Wire.requestFrom() I would expect the LED to stay on and not blinking continously.

Please post your complete code (might be that the error is located somewhere else) and provide a wiring diagram or schematics. Such stuff usually isn't a software but a hardware problem but that's hard to tell without having seen the complete code that is able to reproduce the misbehavior.

Did you remove the internal pullups of the Mega1280? Otherwise the I2C signals are pulled to 5V which is not a good idea with a 3V3 sensor!

Sorry I didn't mean blinking, I meant it stays on continuously... (I'm a Dutch guy, so I got my translation wrong!)

I could post my complete code, but it's really a lot. Today I tried making a completely stripped version of the code that only reads the touch sensors, but up till now I can't make it to crash! That looks promising... I will update this topic when I know more about it.

I did not do anything with the internal pullups of the Arduino. They probably get pulled to 5V internally as you said, but I just wired it like they do in the examples:

From: http://bildr.org/2011/05/mpr121_arduino/

From: MPR121 Hookup Guide - SparkFun Learn

With that wiring it won't work on the Mega1280 because on A4/A5 there is no I2C. I asked for your wiring and not of how Sparkfun thinks it should be wired to an UNO.

For the UNO the wiring is correct because the Sparkfun breakout (you didn't specify that you use that breakout) includes pull-ups to 3V3. That means they work as a voltage divider pulling the I2C lines to about 4.2V. It seems that the chip runs for some time with this voltage but it's outside of the specification.

pylon:
With that wiring it won't work on the Mega1280 because on A4/A5 there is no I2C.

Of course I used digital pins 20 and 21 for this. For the rest the wiring is the same.

Last time I wrote I was working on a stripped version of the code and that I could not get it to crash. At the moment I am still building upon this code to figure out what is causing the Arduino to crash. Because I think the Arduino is probably running out of memory because of the rest of the code. Thanks for keeping me sharp, but if I am correct this topic is pretty useless now...