0

I am trying to use the TLC5940NT chip to light up some LEDS. I am trying to use the library that can be found here: https://github.com/sh4wn/tlc5940-raspberry

However, I am unable to light up any LEDs at all and I was wondering if you have any idea what the problem might be. Done and re-done the circuit tens of times (as in the code), I am sure the wiring is ok.

The code is this:

#include <tlc5940-raspberry/tlc-controller.h>
#include <tlc5940-raspberry/raspberry-gpio.h>

#include <wiringPi.h>
#include <iostream>
#include <thread>
#include <chrono>

uint16_t bitpattern;

void update_thread()
{
        RaspberryGPIOPin tlc_vprg(6); // Not used in this example
        RaspberryGPIOPin tlc_sin(1);
        RaspberryGPIOPin tlc_sclk(14);
        RaspberryGPIOPin tlc_xlat(10);
        RaspberryGPIOPin tlc_blank(4);

        RaspberryGPIOPin tlc_dcprg(5);
        RaspberryGPIOPin tlc_gsclk(11);

        tlc_sin.setOutput();
        tlc_sclk.setOutput();
        tlc_blank.setOutput();
        tlc_dcprg.setOutput();
        tlc_vprg.setOutput();
        tlc_xlat.setOutput();
        tlc_gsclk.setOutput();

        SingleTLCController tlc_controller(&tlc_sin, &tlc_sclk, &tlc_blank, &tlc_dcprg, &tlc_vprg, &tlc_xlat, &tlc_gsclk);

        while(true)

                tlc_controller.setChannel(1, 4095);

                tlc_controller.update();
 }
}


int main()
{
        // Initialize GPIO Pins
        if(wiringPiSetup() == -1)
        {
                throw std::runtime_error("Could not setup wiringPi, running as root?");
        }

        bitpattern = 0;

        update_thread();
}

1 Answer 1

1

It looks like you've created an infinite loop. Your while statement needs braces. If you don't include braces in loops or if statements, they will only affect the line directly beneath them. In effect, you're constantly setting the channel, but never update the controller.

Change your code to

while(true)
{
    tlc_controller.setChannel(1, 4095);
    tlc_controller.update();
}
3
  • Thank you very much for that, I must have deleted the braces before copying the code here when I tried to delete the extra bits I tried before and were commented now. Added the braces, it still does not work.
    – Mika
    Jan 22, 2016 at 12:13
  • @Mika: in your example, you're always updating to the exact same value. Why?
    – Jacobm001
    Jan 25, 2016 at 4:33
  • I am just trying to turn on one pin only to light up one LED. I figured that if I can light up the LED, I can then do more complex calculations. I think the problem is the library - it does not use the Raspberry Pi SPI pins, but tries to implement them on other pins- my problem is that I can't "talk" to the chip.
    – Mika
    Jan 25, 2016 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.