Arduino with TLC5926 Library

Hi, I was looking to drive 15 LEDs with an TLC5926. I have found this library: https://github.com/2splat/arduino-TLC5926 but I do not understand the example.

I want to switch on for example 2 LEDs connected to OUT2 and OUT6 and 1 second later 2 LEDs connected to OUT5 and OUT8.

How can this be done? I really dont understand the example.

I will get the parts next week to to the testing. I hope I will understand how to connect everything because at he moment I am not really sure.

Maybe you can help me. I want to write the code now to safe time when I get the parts.

Thanks in advance for your help :-)

You have an int variable that holds all 16 bits of the shift register. Every time you want to change any bit and leave the others the same you do a bit write operation on the variable and send the whole variable out again to the shift register.

OK I have put this in a INO and Verified it with no errors.

From what I understand. Now power is on and all LEDs are off.

But how do I switch on now the LEDs/Outputs?

#include <TLC5926.h>
// Arrange for /OE to be on a PWM

TLC5926 shift_register1;

// avoid pins 0 and 1, that's typically used for USB and serial.
// avoid pin 13, the bootloader does stuff to it
const int SDI_pin = 2;
const int CLK_pin = 3;
const int LE_pin = 4;
const int iOE_pin = 5; // put this on a PWM pin

void setup() {
   Serial.begin(9600); // for warnings

   // turn on warnings. probably turn it off when in production
   shift_register1.debug(1); // requires Serial.begin(...);

   // LE_pin and iOE_pin would be -1 if not hooked up
   shift_register1.attach(1, SDI_pin, CLK_pin, LE_pin, iOE_pin ); // attach 1 shift-register, "1" is optional
   
   // A second shift_register obviously would be on different pins

   // nice to set everything off/clear at first
   // otherwise, leaves the tlc5926 with whatever data it had, and powering outputs
   shift_register1.off();
   shift_register1.reset();
   shift_register1.all(LOW); // shifts LOW into all shift-registers
   shift_register1.on(); // power is on but all outputs are off (from previous)
   }

void loop() {
  // put your main code here, to run repeatedly:

}

What does this do?

shift_register1.send( 0b00111100 )

@G_M Wouldn’t an unsigned int be more safe, awoiding any sign bit confusement?
@OP
That statement would turn LEDs on outputs on line 2,3,4,5, leaving the LEDs on line 0,1,6,7 off.

@OP That statement would turn LEDs on outputs on line 2,3,4,5, leaving the LEDs on line 0,1,6,7 off.

Can you explain this a bit more detailed? For example. How can I turn on OUT15 for example?

haschu87: Can you explain this a bit more detailed? For example. How can I turn on OUT15 for example?

Grumpy_Mike: Every time you want to change any bit and leave the others the same you do a bit write operation on the variable and send the whole variable out again to the shift register.

Now if you don't understand something ask just don't ignore what you are told. https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitset/ So you make bit 15 into a 1 ( or zero depending on how you have wired the LEDs on the shift register )

@G_M Wouldn't an unsigned int be more safe, awoiding any sign bit confusement?

Makes no odds. You only set and clear the bits using the bit set or bit clear calls if you are a baby, or by using logic operators if you are grown up.

What does this do? Code: shift_register1.send( 0b00111100 )

It turns on and off individual bits. Start after the "b" and then each 0 is a LOW sent to the shift register and each 1 is a HIGH sent to the shift register.

Study bitSet and bitClear in the link provided by Grumpy_M, in Arduino Reference. That is a superb source for learning more.

So this should turn on OUT15 from what I understand

shift_register1.send(0b0000000000000001);

So to get the LED connected to OUT15 on and one second later the LED connected to OUT0 I think this is the code that would do it

#include <TLC5926.h>
// Arrange for /OE to be on a PWM

TLC5926 shift_register1;

// avoid pins 0 and 1, that's typically used for USB and serial.
// avoid pin 13, the bootloader does stuff to it
const int SDI_pin = 2;
const int CLK_pin = 3;
const int LE_pin = 4;
const int iOE_pin = 5; // put this on a PWM pin

void setup() {
   Serial.begin(9600); // for warnings

   // turn on warnings. probably turn it off when in production
   shift_register1.debug(1); // requires Serial.begin(...);

   // LE_pin and iOE_pin would be -1 if not hooked up
   shift_register1.attach(1, SDI_pin, CLK_pin, LE_pin, iOE_pin ); // attach 1 shift-register, "1" is optional
   
   // A second shift_register obviously would be on different pins

   // nice to set everything off/clear at first
   // otherwise, leaves the tlc5926 with whatever data it had, and powering outputs
   shift_register1.off();
   shift_register1.reset();
   shift_register1.all(LOW); // shifts LOW into all shift-registers
   shift_register1.on(); // power is on but all outputs are off (from previous)
   }

void loop() {
  // put your main code here, to run repeatedly:
  shift_register1.send(0b0000000000000001);
  delay(1000);
  shift_register1.send(0b1000000000000001);
  delay(1000);
  shift_register1.all(LOW);
  delay(1000);
}

Now does this work?

So this should turn on OUT15 from what I understand

Or OUT0 depending on if that library shifts out the least significant bit first or the most significant bit first. I don’t know because I would never use a library for anything that trivial.

Now does this work?

Looks as if it might but you have the hardware so try it.

Note you are still not using a variable and setting and clearing the bits.

Hi, I think you are having difficulty understanding binary and how registers work.

shift_register1.send(0b1000000000000001);

The 5926 has a memory register that is connected basically to the 16 output/input pins of the chip. The register called shift_register1 is 16 bits long, bit zero to bit 15.

0b1000000000000001 is a binary word of 16bits, representing the 16 bits in the register and hence the output of the IC.

In this case 1000000000000001 loads bit 15 and bit zero with logic 1. A logic 1 turns the respective output pin HIGH A logic 0 turns the respective output pin LOW.

I hope this explains the process.

Can I suggest you have a good long experiment with your hardware when it arrives. Half the enjoyment is debugging and getting you code to work. To much pre-thinking is not good, experimenting is GOOD.

Tom.. :)