Thursday, February 27, 2014

Shopping

Buying electronics on eBay; my favorite way to kill time :)
It's amazing how little you pay for hundreds of components, most of the time it's less than what you'd pay for shipping alone if you'd buy it from some European supplier like Conrad or Elfa. Sure, I have to wait a week or two for the items to arrive, but who cares? Here's a small selection of items that have arrived in the past week:
6 meter of rainbow flat cable, 100 meter 22AWG wire, 100 8P dupont connector housings, 10 electrolytic capacitors, 50 ceramic smd caps, 200 sot-23 transistors, 200 RGB LEDs and 5000 1K ohm 0603 resistors.

Some people ask me if I'm afraid to get ripped off. The answer is no, not really. I've done nearly 100 transactions in the last couple of years, only 1 never arrived, and I blame that on the mail :) None of the items on the photo above have cost me more than $20, so even if an item never arrives, I never lose a significant amount of money. I'd be more bummed by having to wait two more weeks :)

I have a few favorite sellers which I'll pick if the difference isn't too big. They are, in no particular order:
Ele-parts
G&C supermarket
Tayda2009

But most of the time, I'll just try to find the cheapest ;)

Creating a jig


Probably the most important tool when constructing the cube is the jig. It hold the wires and LEDs in place when you solder them, making life a whole lot easier. This jig is used to create a pillar of LEDs; 8 LEDs stacked on top of each other with all their cathodes connected.
I've bought a piece of wood, about 44 mm wide and 20 mm thick, and cut it into pieces. I've cut off eight pieces of 20 mm to hold the LEDs, and two pieces of 80mm to go on each end. The bottom part is about 250 mm. In the 8 "columns" I've drilled 5mm holes, 1 cm from the top. The distance between the hole and the edges of the columns determines the distance of the wires to the LED.
I've drilled three 3 mm holes on both ends to hold the wires. The position of these holes should match the top and sides of the columns, so the wires will touch the columns.

This was just a prototype I made to figure out the what works and what doesn't. I recommend taking your time for designing and constructing the jig, as it will eventually determine the quality of your cube.

Plan your cube; think about how large you want it to be. I'm going for a 1 inch spacing between all LEDs. This means that the front of a jig column should be one inch away from the front of the next and previous  jig column. The width of the columns shouldn't exceed 20mm, this leaves just 5 mm of space between the pillars of LEDs. As you can see, the design of the jig determines the dimensions of the cube. And make SURE you keep plenty of room between the bottom LED and the end of the jig, you'll need this extra wire to install the pillar.

Things that went wrong:
  • I'm not that great with wood, I used a hand saw and a portable electric drill. The result is far from perfect. Next time I'll use an electric jig saw for cutting and my Dremel workstation to drill straight holes.
  • Use glue. The columns rotate a bit, so next time I'll glue them first, then drill holes from the bottom before screwing them in place. This should keep them perfectly in place.
  • Make the columns thinner. The space between the columns is a bit too small to comfortably put the LEDs in and out; they tend to get stuck.
  • Make the columns narrower. Right now I'm creating pillars that are 20 mm wide, I think I'm going with 12 or 15 mm instead, so I'll have more space between the pillars.
 Here's the result of my first test with the jig:
 Not too shabby. I had to put quite a bit of force on it to get it out of the jig so it's a bit bent. A few more lessons learned:
  • Make sure you have plenty of clearance between the columns, one of the LEDs got stuck.
  • Make sure you bend the legs of all LEDs equally, or they might push the wire away making it difficult to solder other LEDs. I'm probably going to create a jig for bending the legs as well.
  • Place the LEDs before you place the wires, it's much easier that way.
  • When done, cut the wires at the top of the pillar first, then pull the pillar back so the LEDs are freed, then cut the wires at the bottom of the pillar on the outside of the jig, this gives you another extra cm of wire.
  • Straightening the wire is done by inserting them into the jig, tie their ends together and rotate the bunch. This will put tension on the wires and that will make them nice and straight. Don't put too much tension on them or they will break!
And a few things to keep in mind:
  • Test your LEDs before you put them in the jig, make sure they work and that the brightness is the same as the others; you really don't want to replace a LED when your cube is already constructed.
  • You can use a wire stripper to strip the wire, but I like to use a snap off knife. Just place the wire on a surface, place the knife on the wire and hold it almost parallel to the wire, then gently pull the wire along the knife and half of the insulation will be stripped away in one go. You can peel the other half off easily.
  • The wire I got is pre-tinned, and it looks great! Much better than bare copper in my opinion.
  • You can straighten the wires a bit before inserting them in the jig. Use two pliers to grab both ends of the wire, then tug on them gently a couple of times. Don't do this too hard or too often because the ends will suffer from metal fatigue and break.
  • WASH YOUR HANDS! You're not going to get lead poisoning from breathing fumes, only lung cancer. But the lead does get on your hands, so make sure you wash your hands thoroughly before you eat, drink, rub your eyes, scratch your <insert bodypart>, etc. Also clean your working surface and don't put food on it.
  • Don't breath the fumes, it's not exactly healthy. Using a small 12V computer fan is enough to blow most of the fumes away from you. Keep your mancave/shed/living room well ventilated.
That's it for now, once I'll have my final jig done I'll add another post on this subject.

Designing some PCBs

Having decided that I didn't want a big mess of wires and several square feet of prototype boards, I set out to design a PCB to accommodate all the circuitry. Initial drafts were made using Fritzing, a very accessible open source program.
I wanted to have one shift register with eight transistors and all required resistors on one small board, so I could control 8 cathodes. The design had to be small and stackable; you should be able to put multiple boards on top of each other easily.

Designing a PCB is surprisingly easy. All you need to do is create the schematic in the schematic view by placing all components and drawing wires between the connectors.

 Then you go to the PCB view and set all the right footprints for the components (components may come in various forms, like through hole or surface mount, check the datasheets of your components). After that it's simply a matter of placing the components on the PCB in a logical way. The software will draw lines between pads that need to be connected to each other (so called rats nests) and all you need to do is draw traces between unconnected pads, making sure they don't cross and aren't too close to each other. The software will check for the most obvious design faults.
The above pcb is about 5 by 2 cm (2 by 0.8 inch) and can control the cathodes of 8 LEDs. Check out the result in 3D (made with KiCad):
The row of 8 pins are connected to the cathodes of the LEDs. The double pin header next to the shift register are the data pins which are connected to the microcontroller. The pins of the bottom row are connected to the pins above them, except for the last one in each row. The bottom one is data in, the top one is data out. When you stack these boards, you can connect the top 4 pins (output) to the bottom 4 pins (input) of the board above it. The data out of the bottom board will be connected to data in of the board above it. Pretty neat eh? The signal on the other pins of that connector are the same for all boards. They´re (in no particular order) Clock, Reset and Latch. The three pin connector (drawn in blue) is the power connector.

Although Fritzing is very easy to use, it has its limitations. Which is why I switched to KiCad, which is also open source and free, but it's much more professional. Id' say Fritzing is nice to learn the basics, but KiCad is great when you start to run into Fritzing's limitations. The learning curve for KiCad is much higher though, but there are some great tutorials that'll help you get started. Plus it has a 3D view :)

I've also designed an Anode driver board to hold a shift register and the MOSFETs, it can be connected the same way as the Cathode boards.
You've probably noticed the thick traces, those are needed to handle the 5 A current that will be flowing when the cube is fully lit. It's about 7 by 5 cm (3 by 2 inch).

The cool thing about these boards is that you can use them not just for a cube, but also for LED bars or LED matrices.
Above pictures are of older versions, the current design has some minor improvements.

A cube simulator

How I love Qt. Here's something I wrote during lunch break:
It's a cube simulator! Sort of. I pasted one of Kevin Darrah's animations (the first one in this video) into my code and it worked pretty much straight out of the box.
LED information is stored in a 8x8x8 three dimensional array in RGB444 format. The render loop simply iterates over all x/y/z values and reads the color information. X and Y are decremented by 3.5 (to put the origin in the center of the cube) and then put in a 2D point after which a rotation matrix is applied. The resulting X and Y and the original Z are translated to 2D coordinates using the formula: Xwin = X + Y, Ywin = Z - 0.5X + 0.5Y.
Translucency is calculated by using the highest 4 bit R/G/B component, multiply by 4, add 192. So LEDs that are off are more transparent than LEDs that are on.

Shoppinglist

Here's a list of parts required to build the cube. The given quantities are the minimum, I recommend you get a few extra of each since you (read: me) are bound to make a few mistakes.

  • 512 RGB 5mm LEDs, common anode, diffused.
  • 200 2N3904 transistors. These are used as switches, 192 for the cathodes, 8 as MOSFET drivers for the anodes. (datasheet)
  • 25 74HC595 shift registers (datasheet)
  • 8 P-channel power MOSFETs, I'm using IRF9540 in TO-220 package. (datasheet)
  • 400 1 KOhm resistors to drive the transistors
  • 192 resistors of varying values to use as current limiters for the LEDs. The value depends on the color of the LED and the brightness you want/
  • 8 100 Ohm 1 Watt resistors for the MOSFETs
  • 8 100 uF electrolytic capacitors for the MOSFETs
  • 25 100 nF ceramic capacitors as bypass for the shift registers
  • 100 meter 22 AWG wire for the cube
That's just the bare minimum. You'll also need a microcontroller to run the thing, a power supply (5V, 10A = 50Watt at least), something to put your components on and loads of wire to connect it. Since I'm trying to make this look nice under the hood/cube, I've added the following to the shopping list:
  • loads of angled pin headers, both single and double row
  • dupont female connectors, 8P, 2x4P and 1P
  • a couple of meters of 40p rainbow cable
  • custom made PCBs, 24 cathode drivers, 1 anode driver
  • 25 surface mount LEDs for the drivers
  • resistors for aforementioned LEDs
Pretty much all of the parts you can get from China on eBay. Use search terms like "200pcs" and make sure you select "worldwide" as item location. Most of these items only cost a few dollars. LEDs cost about $17 per 200, but surface mount resistors as little as $5 for 5000 pieces and you get free shipping as well. The 100 meter wire I got from the UK (also through eBay) and the PCBs will be manufactured by OshPark.com

You'll need some tools as well of course:
  • soldering iron
  • solder
  • side cutters
  • wire stripper or a small sharp knife. I'm using a small snap off knife
And most likely you'll want to create one or more jigs to aid in putting parts together neatly, but I'll cover that in a different post.

I'm planning on making a display to put the cube and all electronics in as well, so some wood, a few acrylic sheets, paint and miscellaneous hardware will be added to the list as well.

That's it for now!

Wednesday, February 26, 2014

First!

Hi there!

A few weeks ago I stumbled across a movie on YouTube describing the build of an 8x8x8 RGB LED cube, made by Kevin Darrah. He did a great job in documenting his build and explaining the theory behind it, so I'm about to try and build one myself. I'm not an Electronics Engineer, I'm not even a half decent amateur, but I like electronics and I'm learning new stuff every day.

I'm a programmer, I've been programming for about 15 years now, over half of it professionally. Microcontrollers are my specialty (not my job though). I started out with the Zilog Z80, did some work with ARM7 and ARM9 (GBA and Nintendo DS), but have moved to AVR's a few years ago, primarily Atmega168/328 and Attiny13.

In this blog I hope to document every step of the build and explain what went well and what went wrong (and why). If you're new to LED cubes then I recommend you watch Kevin Darrah's movies on his website: www.kevindarrah.com
After that, come back and check out my build :)

There's a few things I want to try and do "better" than his build. Time will tell if it works, but I'll give it a shot.
  • Less of a wire mess, it looks cool and techy but I simply don't have that much room to keep an object of that size without having my wife complain about it ;) All electronics need to fit underneath the cube in a flat package.
  • I plan on designing some PCBs for the electronics instead of using prototype boards. I want to use SMD components to reduce the size of the boards and, with that, also the cost. Fortunately I have some family and colleagues with enough knowledge, experience and credentials to verify my designs.
  • A few major changes will be made to the code. In fact, I've already rewritten most of it and initial tests show a major performance improvement. A refresh rate of 100Hz should not be a problem and there will be plenty of CPU power left for animations.
  • I plan on streaming animations to the cube instead of having them generated at runtime by the microcontroller. Current calculations show that there's plenty of CPU time left to stream new frames in at 100 frames per second. I plan on streaming them from SD card or a PC using Ethernet. I've looked at using UART (serial port) for streaming but it seems impossible to provide a stable stream of data. 
Plenty of stuff on the wish list, so let's get started!