LED Cube – How to Build One
Tuesday, November 8th, 2011Coding4Fun have just published my article on how to build a 512 LED cube controlled by a Netduino Mini.
Coding4Fun have just published my article on how to build a 512 LED cube controlled by a Netduino Mini.
A while ago I created a circuit and some code to control the TLC5940 LED driver using a Netduino Mini. This chip allowed the programmer to control 16 LEDs using a serial interface. In the conclusions I noted that it should be possible to control two or more of these chips by cascading the serial output from one chip into another. This article discusses the additional hardware required along with the software to control up to 32 LEDs using two of these chips linked together.
It is assumed that you have read and understood the previous article before you proceed further.
Linking two of these chips is a relatively simple affair and requires the LEDs you wish to control and only 1 additional component, namely a 2K2 ohm resistor, and some additional wire (assuming you are using breadboard).
Starting with the simplest part, the 2K2 ohm resistor connects the IREF pin on the second TLC5940 to ground. This sets the reference voltage for the LEDs connected to the second TLC5940.
The next part of the problem is to connect the two chips together. This is achieved by connecting the following pins:
TLC5940 (1) | TLC5940 (2) |
SCLK | SCLK |
BLANK | BLANK |
XLAT | XLAT |
GSCLK | GSCLK |
VPRG | VPRG |
SOUT | SIN |
XERR | XERR |
DCPRG on TLC5940 is connected to Vcc as it is on the first driver chip and the LED controller pins connected to the appropriate LEDs.
This PDF (PWMLEDControlv0.03.pdf) contains the full circuit diagram showing the connections required.
Now we have the additional LEDs in the circuit we will need to be able tell the software driver for the chips how many LEDs we want to control and then be able to control the brightness of the LEDs. In order to do this an additional parameter was added to the constructor numberOfLEDs. This parameter allows the system to work out how many TLC5940’s should be connected together. Once we have the number of chips calculated we can then work out the size of the buffers for the Dot Correction and the Grey Scale data.
The class uses two buffers for both the Dot Correction and the Grey Scale data. This may seem superfluous but doing this allows two different modes of operation:
For the moment we will be discussing the basic mode. In this mode, the software driver hides much of the implementation and the user only really needs to perform three tasks:
Tlc5940 leds = new Tlc5940(numberOfLEDs: 32);
You can of course use the additional parameters to define the pins used for the various control signals or just use the defaults.
The class contains a method which overloads the array indexing operator. Setting the brightness for a LED is simply a case of using this operator as follows:
leds[10] = 767;
This will set the brightness of LED 10 to the value 767.
An important note here is that the LEDs are numbered from 0 to 15 on the TLC5940 connected to the Netduino Mini, 16 to 31 on the next LED in sequence and so on.
The final piece of the puzzle is to output the data to the series of TLC5940s connected to the Netduino Mini. This is achieved by calling the Display method in the Tlc5940 class.
The source code for the controller class and a simple main program can be found here (CascadedTLC5940.zip).
The work with this chip has not yet finished as there are still some points which need addressing in order to round off this class:
One final item which needs addressing is to round off the code once these final feature have been implemented. A topic for another day.