Leonardo with the TLC5940

Hello,

I am working on a small project and I am finding it difficult to have a good spot for reprogramming headers. As a result, I was looking at the leonardo as a middleman for me to learn how to use the Atmega32U4.

Does anybody know if the library for the TLC5940 works properly with the leonardo?

The Leonardo implements SPI different from the Uno.

You might have to change the TLC5940 library to use "bit-bang" mode instead of SPI until a pin mapping for the 32u4 is created. Look at the tlc_config.h file to see how to change the mode and setup the 2 pins to use.

Ok. Thank you!

So I emailed the guy who made the previous libraries for the TLC5940 work with the arduino and here it is

Hi Shannon,
I haven't played around with a Leonardo yet, so the library won't be updated anytime soon. Hopefully someone will contribute code to get it working :-). The library uses two timers and the hardware SPI module. If you want to try updating it, try comparing the timer section/SPI section in the Atmega168 datasheet with the 32U4 datasheet.

  • Alex

I'm thinking it would be nifty to try to do it although I have absolutely no idea what I'd be doing.

The Leonardo uses an ATMega32U4, the same chip used by the Teensy 2.0 which the TLC5940 Library already supports.

It should work without modification.

REALLY!?
Aw man i'ma have to check that out

I've been trying to get the TLC5940 to work with a Leonardo for 2 days now. One problem is that the hardware SPI is now only available on the ICSP header rather than pins 10-13. The other is that the pin mappings in the Teensy pinout file don't seem to line up with the datasheet for the chip on the Leonardo.

If anyone has had success modifying this library, or if you might have ideas on how to get it going, myself as well as others would appreciate it.

Thanks.

If it is just pin mapping, it shouldn't be an issue.

As soon as I get my leonardo working, i'll take a look into it and modify the library if i'm able.

amps:
One problem is that the hardware SPI is now only available on the ICSP header rather than pins 10-13.

So? Make your connections to the ICSP header instead of the digital pins.

I don't have F/M headers :frowning:

I should have mentioned that I tried connecting directly to the ICSP but didn't have any luck. I think the problem lays in my attempt at rewriting the pin layouts. The Atmega_xx8 file uses pin designations like PB0 and PD5 whereas the Teensy_XXuh file uses numbered pins such as 16, 17, etc..

I've tried both methods of mapping but still have the same blank result. Mind you I'm a complete newbie when it comes to this so I'm sure I'm missing something simple.

Interesting. You tried the PB# method? Maybe instead of PB# it uses PORTB#

Hello I'm a beginner with Arduino and I got same problem.

I've to clear the solution but it works and it's something.

You have to backup and then edit .../arduinoIDEfolder/libraries/TLC5940/pinouts/chip_includes.h
after the abbrevation port definitions (many sentences like '#define PB0 PORTB0') delete all and left it like this:

/* Copyright blablabla*/
#ifndef TLC_CHIP_INCLUDES_H
#define TLC_CHIP_INCLUDES_H

/** \file
Includes the chip-specfic defaults and pin definitions. */

#include <avr/io.h>

#ifndef PB0
#define PB0 PORTB0
...
#define PH7 PORTH7
#endif

/* Chip Specific Pinouts */
#if defined (AVR_ATmega32U4)

/* Leonardo */
#include "Arduino_Leonardo.h"

#else
#error "Unknown Chip!"
#endif

#endif

Then copy 'Teensy_xxU4.h' (in the same folder), rename the copy to 'Arduino_Leonardo.h' and edit it like this:

#ifndef TLC_Teensy_xxU4_h
#define TLC_Teensy_xxU4_h

#if DATA_TRANSFER_MODE == TLC_BITBANG
#error "If you want bitbang mode, insert pin defs here"
#endif

// MOSI (Leo outter center ICSP pin) -> SIN (TLC pin 26)
#define TLC_MOSI_PIN 2
#define TLC_MOSI_PORT PORTB
#define TLC_MOSI_DDR DDRB

// SCK (Leo inner center ICSP pin) -> SCLK (TLC pin 25)
#define TLC_SCK_PIN 1
#define TLC_SCK_PORT PORTB
#define TLC_SCK_DDR DDRB

// SS (Leo RX LED)
#define TLC_SS_PIN 0
#define TLC_SS_DDR DDRB

// OC1A (Leo pin 9) -> XLAT (TLC pin 24)
#define XLAT_PIN 5
#define XLAT_PORT PORTB
#define XLAT_DDR DDRB

// OC1B (Leo pin 10) -> BLANK (TLC pin 23)
#define BLANK_PIN 6
#define BLANK_PORT PORTB
#define BLANK_DDR DDRB

// OC3A (Leo pin 5) -> GSCLK (TLC pin 18)
#define GSCLK_PIN 6
#define GSCLK_PORT PORTC
#define GSCLK_DDR DDRC
#define TLC_TIMER3_GSCLK 1

#endif

You must advise that the pin numbers are different to the Teensy, even more, you must use the SCK and MOSI signals from the ICSP connector (not mapped to digital pins in Leonardo) and the SS signal from the RX LED board). See the next images for more help (the first is for the ICSP detail algthou is not Leonardo board, and the second is for the board conection to the SS signal)

ICSP:



SS:
http://provideyourown.com/wordpress/wp-content/uploads/rx-pin-150x148.jpg

Be sure too that in .../arduinoIDEfolder/libraries/TLC5940/tlc_config.h you have correctly the numbers of TLC you're using '#define NUM_TLCS 2' (for 2 TLC5940's) at Line55

I hope this helps anyone new with Arduino Leonardo board and the TLC5940 chip.
Sorry for my english.

This fix works?

funkyguy4000:
This fix works?

Yes, I've to integrate it correctly in 'chip_includes.h' in order to not delete the rest of include orders.

At the moment this fix is usefull only for Arduino Leornardo board as the rest of hardware (#includes) are being ignored.

Is "Love" a strong word for what I feel? Thanks so much.

The new pin definitions worked perfectly.

Happy days!

Of course its not.
I...(brings up courage) love it too

Oooh guys, you make me cry :slight_smile:

However, admittedly I do not fully understand which pin/part of the leonardo to connect exactly to which pin of TLC. Could someone be so kind to clearify this? Maybe in the form as it is done explained in the BasicUse example of the TLC library?

Thanks a lot already!!

Nvermind. I have figured it out myself.
The only thing I do not understand so far is what you do with the Rx Led pin...

Okay so I noticed last night while building a circuitboard that the TLC5940 Grayscale clock (for the PWM function) is connected to the INT1 pin when set-up with an ATmega328p. When connecting it up like that on the 32U4, I noticeced the INT1 pin is also the SDA pin (for I2C/TWI). Unfortunatly my project requires the I2C bus for a different IC.

Can I change the grayscale pin for this to another pin and will still work?