I2C and the TLC5940 LED driver

So, I'm having a very weird problem. My current project needs 1200 individually controlled LEDs. To get this to work, I hooked 5 Arduinos up to a Raspberry Pi (via I2C) and 15 TLC5940 (using the library at Arduino Playground - HomePage) chips to each of those. The problem is that when I try to send a signal to the Arduino for it to turn on a channel, the python on the Raspberry Pi crashes, giving me an IOError number 5. I've used trial and error to determine that the Tlc.update(); function is what is causing the I2C error. The RPi and the LED driver aren't connected, so I can't figure out why this is happening. I think it may have something to do with timing, but I tried moving the Tlc.update(); function to void loop() from inside of the function run by i2c when it receives data, and that didn't work either. Is there something with the wire library that might be messed up by using the TLC chips?

Here is the arduino code:

#include "Tlc5940.h"
#include <Wire.h>

int address = 4;
int input = 0;
int pin = 12;

void setup(){
  pinMode(pin, OUTPUT);
  Wire.begin(address);
  Wire.onReceive(recData);
}
void loop(){
  delay(1);
}
void recData(int numBytes){
  while(Wire.available()>0){
    input = Wire.read();
Tlc.set(0, 4095);
Tlc.set(1, 4095);
Tlc.set(2, 4095);
Tlc.set(3, 4095);
Tlc.set(4, 4095);
Tlc.set(5, 4095);
Tlc.set(6, 4095);
Tlc.set(7, 4095);
Tlc.set(8, 4095);
Tlc.set(9, 4095);
Tlc.set(10, 4095);
Tlc.set(11, 4095);
Tlc.set(12, 4095);
Tlc.set(13, 4095);
Tlc.set(14, 4095);
Tlc.set(15, 4095);
Tlc.set(16, 4095);
Tlc.set(17, 4095);
Tlc.set(18, 4095);
Tlc.set(19, 4095);
Tlc.set(20, 4095);
Tlc.set(21, 4095);
Tlc.set(22, 4095);
Tlc.set(23, 4095);
Tlc.set(24, 4095);
Tlc.set(25, 4095);
Tlc.set(26, 4095);
Tlc.set(27, 4095);
Tlc.set(28, 4095);
Tlc.set(29, 4095);
Tlc.set(30, 4095);
Tlc.set(31, 4095);
Tlc.set(32, 4095);
Tlc.set(33, 4095);
Tlc.set(34, 4095);
Tlc.set(35, 4095);
Tlc.set(36, 4095);
Tlc.set(37, 4095);
Tlc.set(38, 4095);
Tlc.set(39, 4095);
Tlc.set(40, 4095);
Tlc.set(41, 4095);
Tlc.set(42, 4095);
Tlc.set(43, 4095);
Tlc.set(44, 4095);
Tlc.set(45, 4095);
Tlc.set(46, 4095);
Tlc.set(47, 4095);
Tlc.set(48, 4095);
Tlc.set(49, 4095);
Tlc.set(50, 4095);
Tlc.set(51, 4095);
Tlc.set(52, 4095);
Tlc.set(53, 4095);
Tlc.set(54, 4095);
Tlc.set(55, 4095);
Tlc.set(56, 4095);
Tlc.set(57, 4095);
Tlc.set(58, 4095);
Tlc.set(59, 4095);
Tlc.set(60, 4095);
Tlc.set(61, 4095);
Tlc.set(62, 4095);
Tlc.set(63, 4095);
Tlc.set(64, 4095);
Tlc.set(65, 4095);
Tlc.set(66, 4095);
Tlc.set(67, 4095);
Tlc.set(68, 4095);
Tlc.set(69, 4095);
Tlc.set(70, 4095);
Tlc.set(71, 4095);
Tlc.set(72, 4095);
Tlc.set(73, 4095);
Tlc.set(74, 4095);
Tlc.set(75, 4095);
Tlc.set(76, 4095);
Tlc.set(77, 4095);
Tlc.set(78, 4095);
Tlc.set(79, 4095);
Tlc.update();
  }
}

What are you reading? You seem to be discarding it.

Anyway, I would rework to put the update out of the ISR. eg.

volatile bool doUpdate;

void recData(int numBytes)
  {
  for (int i = 0; i < numBytes; i++)
    Wire.read ();
  doUpdate = true;
  }

void loop ()
  {
  if (doUpdate)
     {
     doUpdate = false;

     Tlc.set(0, 4095);
     Tlc.set(1, 4095);
     Tlc.set(2, 4095);
     Tlc.set(3, 4095);
     Tlc.set(4, 4095);
     Tlc.set(5, 4095);
     Tlc.set(6, 4095);

     // etc.

    }
  }

Ah, yes. The update seems to be discarded because I was testing what caused the error. There is more code that I forgot to put in where it only writes to the LED that the RPi specifies. As to taking the update func out of the i2c loop, I just tried that and it does seem to keep the thing from crashing, although the LEDs aren't turning on. I think this may be a different issue, but I'm not sure...

Ok, so what I've found out so far is that the Arduino is definitely receiving the i2c signal, and the Wire library does let code in the main loop execute. The if statement in the main loop also runs, but doesn't get past the Tlc.update function. I just put some LEDs on spare pins and set them to turn on right after certain code blocks ran to test this. Is it possible to freeze an arduino?

Maybe you are drawing too much current and the processor is resetting.

Sounds like a power supply and/or decoupling problem to me.

Yeah, what someone told me is that you have to put a cap between power and ground to smooth out all the bumps from the PSU... I'm going to try that tomorrow

farTooManyWires:
Yeah, what someone told me is that you have to put a cap between power and ground to smooth out all the bumps from the PSU... I'm going to try that tomorrow

No, you have to put many caps, one for each chip, as close to the chip Vcc pin as possible. And they have to be ceramic.

Well, I have 10 104M ceramic 0.1uF caps, so I'll solder them up and see what happens

I soldered up the caps across the vcc and gnd lines of the TLC5940 chips. I can't test it right now, because the Arduinos have decided to not register on the bus. So I'll test it and post more once I get that figured out