DefVar | Electronics and Software

Tutorial: ESP32 and TLC5940

This Tutorial shows you how to use my library for the ESP32 to control the TLC5940 Greyscale values (PWM). I wrote my library because the library from Paul Stoffregen seems to support the ESP32, but doesn’t. If you want to check it out for your own, read this library.properties and follow the #elseif ESP32 in this file (Spoiler the ESP32 processor isn’t covered).

Hardware Setup

ESP32 GPIO PinTLC5940
27 (Random PWM Pin)GSCLK
12 (HSPI_Q ) BLANK
13 (HSPI_ID)SIN
14 (HSPI_CLK)SCLK
15 (HSPI_CS0)XLAT
?? (Random PWM Pin) // Optional VPRG
ESP32—TLC5040 Connection

If you want to use the DOT correction, you need to wire up the VPRG Pin to the ESP32. Currently, my library does not support Dot correction.

Software

I wrote I library for the ESP32 to use it with the TLC5940. The library can be found here.

https://registry.platformio.org/libraries/defvar/ESP32%20TLC5940

Example Platformio.ini for the code. The Library is not (yet) listed in the Arduino—Library. For those how use the Arduino IDE you have to manually download the library from its source and copy the files in the library’s folder from the Arduino.

Download Link: https://github.com/Def-Var/TLC5940

[env:esp32dev]
platform = espressif32

board = esp32dev
framework = arduino
lib_deps = 
	"defvar/ESP32 TLC5940"

If you encounter any problems during use or installation, feel free to leave a comment or open an issue on GitHub.

Example

In the tlc_config.h you can specify how many TLC’s you have in sequence. For an easy use, my library does use the same configuration file as its Arduino brother from Paul Stoffregen.

...
#ifndef NUM_TLCS
#define NUM_TLCS  3  // Here the number of TLC
#endif
...
#include <Arduino.h>
#include <Tlc5940.h>
/*************************************************** 
Example fot the TLC5940 Lib. 
 ****************************************************/


Tlc5940 *tlc = NULL;


void setup() {

  Serial.begin(9600);

  tlc = new Tlc5940();
  tlc->init();

}


void loop() {
  for (int index = 0; index < NUM_TLCS*16; index++) { 
     tlc->set(index, 4095);
     tlc->update();
     delay(500);
  }
}

I wrote the library because I want to upgrade a 4x4x4 RGB Cube from an Arduino to an ESP32. The PCA9685 is too slow for this kind of task.

SparkFun TLC5940 Breakout Board

TLC5940 Breakout Board from SparkFun: https://www.sparkfun.com/products/10616

The breakout board from SparkFun uses the same chip that I used at the beginning of the tutorial. It just uses the VQFN package instead of the PDIP package I used.
In addition to the TLC5940, a voltage regulator is also integrated. From the schematic of the board, it can be seen that JP22 can be used as input from the ESP32 and JP23 is used to daisy-chain additional ICs.

Schematic from https://www.sparkfun.com/products/10616 (Downloads)

Without having tested it on me, I am sure that this board will work with my Library.

2 Comments

  1. Max

    Hey thanks for this tutorial.

    I wonder whether you can say anything about the TLC 5940 Breakout board from SparkFun (https://www.sparkfun.com/products/10616).

    Does your library work with it?

    • DefVar

      Thank you for your interest Max, I have added another chapter to your request. The SparkFun board should work fine. Please tell me when you have tried it out.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

© 2024 DefVar

Theme by Anders NorenUp ↑