Go Down

Topic: Leonardo with the TLC5940 (Read 8409 times) previous topic - next topic


Jun 17, 2012, 06:53 am Last Edit: Jan 12, 2013, 06:08 pm by funkyguy4000 Reason: 1

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?
Accelerate to 88 miles per hour.

James C4S

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.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com


Accelerate to 88 miles per hour.


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.
Accelerate to 88 miles per hour.

Tom Carpenter

Jun 23, 2012, 11:36 pm Last Edit: Jun 23, 2012, 11:37 pm by TCWORLD Reason: 1
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.


Aw man i'ma have to check that out
Accelerate to 88 miles per hour.


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.



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.
Accelerate to 88 miles per hour.

James C4S

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.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com


Accelerate to 88 miles per hour.


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#
Accelerate to 88 miles per hour.


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*/

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

#include <avr/io.h>

#ifndef PB0
#define PB0     PORTB0
#define PH7     PORTH7

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

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

#error "Unknown Chip!"


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

#error "If you want bitbang mode, insert pin defs here"

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

// SCK (Leo inner center ICSP pin) -> SCLK (TLC pin 25)
#define TLC_SCK_PIN   1
#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_DDR   DDRB

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

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


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)


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.


Accelerate to 88 miles per hour.


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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131