A few days ago I shared on the Facebook page a video on building a 4x4x4 LED cube with Arduino Nano. A nice project, it got plenty of likes and shares. And a simple idea was born: I should make one of those LED cubes myself. But why just copy someone’s project, and not improve it: I will use a DM164142 development board from Microchip (with PIC16F18877 microcontroller) instead of the ubiquitous Arduino. Obviously, MPLAB Xpress IDE and the XC8 compiler will be used instead of Arduino IDE.
My initial thought was: this will be a simple project, I will complete it in a day or two. Oh, man, I was wrong! It took me twice that time.
I’ve started building the LED cube armed with a tutorial from Instructables.com, which I intended to follow and replace the Arduino Nano with the DM164142 board.
The first step, building the templates for bending the LED pins and for keeping the LEDs in place while soldering went OK, without any issues.
The second step is to form the LEDs terminals. As in the video and the Instructables tutorial, I bent the anode sideways, and I have formed the cathode around the pin driven in the small template. In the end, all the anodes will be connected, forming the “levels,” and the cathodes will become the “columns”.
I’ve later realized this is a big design mistake. I should have connected the LEDs with the cathode to the columns and with the anode to the columns. Then, with the addition of only four transistors and four extra resistors, I would have greatly simplified the operation of the LED cube, and the code would have been simpler.
Unfortunately, it was too late to change anything, so I had to continue this way. And I went to the next step, of building the levels.
On each row, four LEDs are connected with 0.9mm silver plated copper wire. Two extra wires are used to join the rows. Four identical “levels” or “floors” have to be made. Pretty boring stuff, I haven’t realized the sheer amount of soldering time needed to complete this project. In the end, I’ve counted over 300 solder joints to make the LED cube.
A lot of solder fumes are released during the soldering work. So, get a fume absorber. Even a cheap one will make a big difference.
Another advice is that, if you want to build such a LED cube yourself, do allow plenty of time for the soldering. It’s a very boring activity, and even if you don’t make any soldering mistakes, it still takes a tremendous amount of time.
Don’t forget to test everything after completing each level. It will be harder to correct any mistakes when the cube is fully assembled.
Then, even more soldering: one must thread the columns through the loops created on the cathodes. Leave the wires longer than you think you need them; you can trim them after you do the final soldering.
Now, take a piece of protoboard, solder the sockets for the DM164142 board, and add the 100R current limiter resistors. In my particular case, the LEDs have the typical forward voltage of 3.1V, and the maximum current of 30mA. For a current limiting resistor of 100R, through each LED will flow a current of 20mA.
Then, connect pins RB0 (top level) to RB3 (bottom level) to each level of the LED cube. Connect the columns to pins RC0-RC7 and RD0-RD7 to columns, as shown in the picture below.
Once again, test everything before going to the next step.
[Optional, but reccomended] If everything is OK, apply a generous amount of hot glue to keep all the wires in place.
The code for the LED cube will rely on the persistence of vision effect, turning on and off LEDs for a brief amount of time, but with a high frequency. Considering the number of LEDs and that of available microcontroller pins, I will have to do some Charlieplexing in the software. The PIC16F18877 can source/sink 50mA per pin. That means I can turn on only two LEDs at a time as not to exceed the maximum current on pins RB0 – RB3 (pins that are connected to the “floors”). As a result, the overall brightness is a bit low. There’s nothing to do about this.
Now, the hardware is ready, let’s write some code.