Solved TLC5940 library dependent on Serial?

I am very confused. Just playing around with some simple code and some TLC5940s on a demo shield.

/* For the RGB 4x4 board, with 3 TLC5940 */

#include <Tlc5940.h>

const byte WP[] = // winding path
  { 0, 1, 2, 3, 7, 11, 15, 14, 10, 6, 5, 9, 13, 12, 8, 4 } ;

void setup() {
  Tlc.init() ;
  Serial.begin(9600);
  setchn() ;  // set up channles
  Tlc.update(); Serial.println("X"); // now send it out
}

void loop() {
}

void setchn() {
// load the current array
  for (byte C=0; C<=32; C +=16)   // for each colur
    for ( byte n=0; n<16; n++) {  // for each element
      Tlc.set(WP[n]+C,32-n*2) ;   // load a value
      Serial.print(".");     // comment out for code to fail??
    }
}

This works.

If the last line with Serial.print("."); is commented out, the LEDs remain dark. It is af the Tlc.set() is only called if the Serial is there.

I have discovered that if I change it from SPI mode to BitBang mode (#define DATA_TRANSFER_MODE) in the library I get even weirder results. I have a tiny "hello world"-like program which works without the Serial.

W-T-F ?? I just can't see my error.

Shouldn't you have a Tlc.update(); in your loop?

I tried that, ie I had only the init() in the setup and the rest in the loop(), but only executed once. I posted the simpler version above. The documentation says one update() call pushes the array out to the TLCs.

But it made a difference. :slight_smile:

So it seems one needs to call update() several times for the change to come through. Hmmm... while that solves my problem it does not explain why Serial should "rescue" it. (I'm using 1.0.3.)

This code fails, too, unless one activates the bottom Serial. I also fooled around with the number of times the update() is called and it needs 8 times. If I remove the Serial-"!" print it needs more than 20. Removing all Serial it requires more than 100.

void setup() {
  Tlc.init() ;
  Serial.begin(9600);
}

void loop() {
  static int R = 0 ;
  if ( R == 0 )  setchn() ;  // set up channles
  if ( R < 5 ) {Tlc.update() ; Serial.print("!") ; }
  if ( R < 10 ) R++ ;
  if ( R < 9 ) Serial.print(R);
}

void setchn() {
// load the current array
  for (byte C=0; C<=32; C +=16)   // for each colur
    for (byte n=0; n<16; n++) {  // for each element
      Tlc.set(WP[n]+C,32-n*2) ;   // load a value
      //Serial.print(".");
    }
}

The range of intensity values is 0 to 4095. You seem to be using 2 to 32. I would expect a very dim output.

They are bright enough. I can not see any intensity difference after a few hundred. But the difference between 0 and 1 is very noticable.

I'll change the current limit resistor to something else - later.

Now I've got another problem. The "3rd" LEDs RED seems to be following pin 13. Apparently a short somewhere (I've swapped tlcs around, so it isnt a chip). Oh, BTW, this is the board.

Anyhow, the OP is still open, even though the "workaround" (calling update() often) solves the immediate problem.

I'm off for a few days travel, so I wont followup until back.

After much head banging and sarcastic but nevertheless encouraging/helpfull advice from friends, I finally used an Ohm meter and checked around the board. There are some shorts (and it isn't my soldering). One of them was shorting one of the LED outputs to the SIN - that explains a lot of the erratic behaviour.

In short - a hardware fault