LED Cube

I was trying come up with something impressive to write about, after having the blog dormant since July. I tossed around a lot of different ideas… Although I haven’t been writing, I’ve been dabbling in a number of different projects. None of them are really in a state I’m ready to write about. That brings me to something I saw a few months ago on MAKE:. Bre and associates had constructed a simple 3x3x3 led cube, re-purposing a POV toy to drive the leds.

I figured this would be a good easy project I could finish in a day, so I drilled out a piece of pine board and set to soldering up some 3mm leds. I wasn’t very careful, so the little matrices look kind of ugly, but it all works and you can’t see the wires in the dark!

3x3 led matrix building

It didn’t take very long to toss three of these nine led matrices together. Assembling them into a twenty-seven led cube was a bit trickier. I used some gator clips to hold parts of the cube while I soldered it. Eventually I finished all the connections and had a passable cube with fairly even spacing.

3x3x3 led cube finished

Assembling the matrix is a pretty straight forward task. All you really do is tie all the cathodes together. Each matrix will become one row in the finished cube. Electrically, the cube is built as a 3×9 array, three rows and nine columns. You could probably build it the other way around, anode rows and cathode columns, but it is easier to sink a large current than source it. I think the MAKE: software only lights one led at a time, since they’re relying on the microcontroller to both source and sink current. My design is a bit different. The mcu sources current to each anode column, and N channel fets sink current for the entire row. The N channel is easily able to sink a few amps, so the cube can light an entire row at once without having to multiplex the individual leds.

In order to keep the PCB layout simple, the connections are spread all over the place in terms of the registers inside the pic. It would have been cleaner to organize eight of the nine columns as a single 8bit register on the pic, leaving only one bit left over to deal with. Instead, I’ve created symbols for each column, and set them individually from 9bit numbers.

Each anode column is current limited by a 75 ohm resistor. The value chosen was rather arbitrary, since the leds have such a low duty cycle, a lower value would have afforded me more brightness when the cube is battery powered. I can tweak the brightness a bit in the software, changing the scan rate the rows are multiplexed at.

That’s pretty much it. I’ve found there’s not a lot you can do with only 3x3x3 and 1 color, but it’s still kind of fun. Trying to think in three dimensions while drawing the animation frames is kind of tricky. I started with excel, but that wasn’t very useful – I spent more time copy and pasting formulas than I did ‘drawing’. Luckily my buddy Dan helped me out with that. He whipped up an awesome little php script that lets you draw animations 27 leds at a time, and it formats the resulting numbers so I can copy and paste them right into the code.

There’s a few videos of the cube doing various things on my Youtube Channel. Here is perhaps the most interesting one so far.

Thanks for reading, and Happy New Year!

LED Clock; Firmware taking shape

The firmware for my LED Sign / Clock project is taking shape.  I’ve worked out my initial wishlist of features, and put together a basic menu structure.  I figured a menu is the  easiest way to access a lot of options, while only relying on two buttons.

The basic menu consists of options for setting the time and date; minute, hour, day, date, month, year.   The basic options are pretty self explanatory.  I have also planned some more advanced options:

1. Adjustable display brightness – Varying the duty cycle and refresh rate of the matrix can effect its brightness.  I need to make a simple scale for these variances to allow for two or three brightness levels.

2. Adjustable scrolling speed – The program draws the same information several hundred times per ‘scroll’, changing this counter affects how fast the display appears to scroll.

3. Selectable time format – User can choose between 12 hour AM/PM time and 24 hours ‘Military’ formats

4. Message Mode – User can enable / disable scrolling messages as well as display a single message, a random message or messages in sequence.

Other than that, the code is still pretty basic.  I’ve completed a bunch of internal fixes, like the scrolling code now handles messages of variable lengths. up to sixteen characters.  I’ve also created i2c eeprom reading routines to extract menu prompts and other text strings I’ve stored in the eeprom to save flash space on the chip.

LED Sign has a purpose!

The single character LED sign I had been playing with now has a purpose! Shortly after discarding several ideas of having it as a serial display for PC/Server status, or hooking it up to the internet and a webcam, I came up with an actual useful purpose. The sign can be a clock! I have two ‘modes’ planned; traditional numbers and binary. All geeks love binary clocks, but most of us are lazy and would rather read regular ‘ol numbers.

To facilitate the role as an clock, I had to redesign the circuit quite a bit. Two new ICs were added, allowing the LED Sign to keep time, and providing some much needed storage.

led matrix sign clock rtc microcontroller schematic

The first of the new ICs is a Real Time Clock. Because I’m cheap, I chose the M41T80 from ST Micro. It’s an inexpensive clock, similar to the Dallas DS1307 but lacking a few minor features. First, the clock has no power-on reset detection. It just starts up as soon as power is supplied. The Dall 1307 has a stop bit which gets set if the clock experiences a POR, so the firmware can test if the clock needs to be initialized or not. The T80 datasheet mentions some registers may get set to default values on power up, so I’ll have to read it a few more times to see if there is a way I can check for a POR. Second, the T80 has no support for a separate backup battery. Instead, ST recommends you place a diode in series with the clock, and use a large capacitor to provide backup power. Last, there is no automatic leap year / leap second correction, oh well!

The second IC is a 16 kilobit serial eeprom, similar to the Microchip 24C16, I chose one from Catalyst semiconductor due to lower costs. The eeprom is arranged as eight banks of 256 bytes each. The chip contains a 16 byte write-buffer, I’m not sure if it can cross a bank boundary or not, I’ll program my firmware assuming it can not. The eeprom will be storing character strings related to operation of the LED Sign as a clock, as well as user programmed messages and possibly simple graphics.

I’ve also added some micro switches for adjusting the clock and changing settings, also a 32.768kHz crystal was added to providing the timing source for the RTC.

pcb layout led sign clock

At this point, the layout of the printed circuit board has become pretty complex. I tried making one of these at home, but didn’t have the patience to exactly align the top and bottom layers of my press and peel sandwich. So, I decided to try a pcb prototyping house. There are a lot of board houses to choose from, many of which cost an arm and a leg. All of the domestic board houses are ruled out, I’m sure they do a fine job, but they cost too darn much. I settled on Spark Fun’s BatchPCB service. They’re not the cheapest board house out there, but their cost is fair. They include a lot of features most other board houses charge extra for, like double sided silkscreen and solder mask, 8 mil pitch and spacing, 20 mil holes, etc. I placed my order on the 6th, and had the PCBs by the 22nd. All the time in between, by mind set to wandering, and I made some POV toys. Once the pcbs showed up, I incurred another delay. Turns out I hadn’t ordered my RTC chips yet! So, another few days wait brought goodies from Mouser (man they are quick, and inexpensive!)

batchpcb led clock circuit board

The boards from batchpcb look awesome. Nice bright green solder mask, tinned pads and holes, smooth clean edges. This is the ‘top’ side of my led sign. There are a few passives on this side, along with the two new ICs. This side is covered by the LED matrix once the board is fully assembled. Don’t mind the flux smeared everywhere – I did clean it off before soldering the matrix down.

led clock circuit board

The bottom of the board contains the PIC processor, mosfet column drivers, a crystal for the clock and some microswitches. Pin headers for power and programming the microcontroller have also been installed. The module is a bit thick at this point, thanks to the socketed IC and the pin headers. On the finished version, I’ll solder the IC straight to the circuit board, and probably use wires instead of a header to supply power.

led sign clock done

The firmware is in the early stages right now, so my next post on this subject will try to cover whatever features I’ve decided on. Right now I know I want a few things:

1. Scroll the time
2. Occasionally scroll the date
3. Occasionally scroll short messages, either randomly or programmaticlly
4. Support some sort of software brightness control

I’ve made some revisions to the design since I had these boards fabricated. One big oops I made was forgetting the pull-up resistors for the i2c bus! Luckily there’s plenty of room on the board, and both i2c lines ran near the Vcc rail. So a little quick scraping action to peel back the solder mask and presto, new lands for 0603 sides resistors. I’ve also added a diode and big capacitor for the RTC’s backup power.

I hope to work on the firmware more this week, so I should have more details about how the clock works next time!

EDIT: Added a quick video of the time scrolling

POV Toy

I recently had the urge to create some “eye candy”; Thinking along the lines of my LED Sign (it’s not dead, just waiting on parts!), I chose to create a similar effect, using only a single line of leds, instead of a 5×7 array.

Persistence of Vision is some sort of effect, either psychological or biological in nature, that allows our eyes and brain to ‘see’ motion and patterns in a sequence of rapidly stills (hence a movie projection). This effect can be exploited using basic digital electronics to create a virtual LED sign, which the viewer will ‘see’ when the pov toy is put in motion.

Commercial POV toys are usually some sort of led matrix attached to a spinning contraption, and display either a fixed or scrolling message. Those are fine, but the technical aspects of motorizing the display make it beyond the scope of a simple project. Therefore, my project relies entirely on elbow grease – swing the wand and watch the messages appear.

Revision one of my POV toy is compact. It measures approximately 2.25″ length wise by 1.1″ width wise. The circuit consists of an inexpensive Microchip PIC 12F683 microcontroller, and a 74HC595 serial shift register. The display consists of eight 3mm leds, I chose blue for the first unit, but I’ll probably make a few more with different colors, I especially want to see green and amber – those leds don’t see a lot of action in the world of consumer electronics.

pov led microcontroller shift register schematic

The circuit is very simple. A tiny microcontroller provides the brains, a simple and inexpensive shift register provides the brawn, and a switch and hall effect sensor provide some control. My first unit has no hall sensor, so power is controlled with the push button switch. When “off”, the pic is in a ultra-low power sleep state. Come to think of it, I could have put the shift register into a tri-state mode when “off”, but for now, it holds its gates at Vdd, which provides no bias across the leds, so there shouldn’t be much current going anywhere. The hall effect sensor will eventually control the power to the display, as well as provide some synchronization. Right now when swinging the wand, the message is legible in one direction, and backward in the next. I plan to try putting a small round magnet in a tube, and gluing it behind the hall sensor. When swung in one direction, the magnet will be forced over the sensor by g-force. When the wand is swung back, the magnet will be forced away from the sensor. This should let the microcontroller know not only to blank the leds during the ‘backward’ swing, but also how much time it has to render the entire message, speeding up the display for a quick swing, or slowing it for a long swing.

The circuit board is a single layer layout with two jumpers. I went with as many SMT components as I could afford, since I hate drilling holes in my home-made circuit boards. Power is currently provided by a 3.7 volt 1600mAh lithium ion cell.

I tried making some video of the unit in operation, but my camera wouldn’t play ball. Next weekend I may have more time to fiddle with photography and try to get some ‘action shots’.

Although version one has been a great success, and was easy, I was unsatisfied. The eye candy just isn’t sweet enough. Version two takes the flash factor up a notch, with RGB leds. I’m working on a ‘full color’ POV wand toy. Version 2.0 has been built, but it has some flaws – and is the subject of my next blog entry. Here is a video of “2.0” running a test pattern on its 24 led array.

LED Sign; Now With Scrolling!

This morning I hammered out a quick and dirty method to scroll a message on my single character LED sign. The scrolling is based around a few subroutines. A text message of 12 characters is passed to the scroll subroutine, along with the number of loops to make. The scrolling routine breaks the text message down into individual bytes, and loads up a static 60 byte message buffer based on data from the font table. Each “scroll” iteration causes the program to copy data from the message buffer into a 5 byte display buffer. The message buffer address is offset by one byte each iteration. Since one byte equals one column on the display, this action cause the display to appear to scroll. Another sub routine watches the address pointer, and wraps it around to the beginning when appropriate.

Single Character LED SIGN

We’ve all seen the various sites where someone put a massive led sign online, and they let people abuse it. What I’ve managed to build is a “single character” led sign. I don’t know if I’ll be able to get my sign online, but I’ll take a stab at it.

After wasting a lot of time to convert a font table I borrowed from somewhere, my little sign finally had a built in character generator. It can generate any of the printable original ascii characters (dec 32 to 127), and display them on the matrix. Data feeds into the sign at 4800 baud (I think i mentioned 19200 earlier – way too fast), and is displayed on the matrix for a few seconds.

If the display sits idle for too long, a basic screen saver (screen waster?) kicks in, and does a simple animation. Any received characters replace the animation and reset the screen saver timeout.

Although exposed, I haven’t implemented the i2c interface yet. This pc board has some issues, and is too large. I don’t like the connectors sticking out to the side like that, so it’s back to the cad package to try and re-arrange things a bit. I think I will fork this design into two separate paths. One async serial (rs232), and one sync serial (i2c / spi). The sync version would be used as a display for other projects. The async version would be hooked up to a PC, and programmed with a simple message. Once detached, the display would just repeat the message over and over. One problem I ran into is storage. I had hoped to store text strings and the font table in eeprom, but the processor I chose, the 16f737 has no on-board eeprom. So instead, the font table is stored in the flash program space along with a few short text strings. The next revision(s) of the board will include a spot for a so8 ‘seeprom’ for extra storage.

LED Matrix Backpack

I had purchased some huge (2″) 5×7 matrix a while ago, as part of my led sensor research. They’ve basically been banging around the lab since, getting pins bent and such. So this past weekend, I decided to put them to some other use. Their pin layout is sort of weird, it doesn’t match up with a breadboard at all (one of the reasons they never made it into the led research). So, I decided to make up some back-packs for them, or is it a carrier board? Anyway, the board features one 5×7 matrix, one pic 16f737, a few transistors and some data connectors. The board provides two means of serial communication; asynchronous rs232 at 19200 bps, or synchronous i2c at 100kbps. A second connector provides power and ICSP pins.

5x7 led matrix backpack

This project has no practical application as of yet. The main reason I made it was to improve on my double-sided pcb fab techniques. This time I found using point to point traces instead of a large “pour” made things work a lot smoother. I used the ‘sandwich’ method with press ‘n’ peel blue. Roughly 1.5 min per side.

5x7 serial led matrix backpack

One thing I had to keep in mind while doing this layout was accessibility to solder both sides, since I can’t through plate my own vias. So things had to be laid down in specific order. I soldered the vias first, using some cheap resistors with very fine leads as my conductors. The method involved sticking the resistor into the via, with just a bit poking out the other side, then bending the resistor 90 degrees and holding it to the board. Then a quick dab of solder onto each joint set them in place. Next, straighten out the resistor leads, and trim them off. Another quick few dabs with the soldering iron and each one was fully connected. Next came the smt parts. The switches were rather easy, but those blasted little 0603 capacitors always give me grief. I tin both pads, then apply a bit more flux as “glue”, then try to reheat one of the pads, to reflow the solder onto the part. It works great with 0805 and larger parts, but the little 0603 usually gets sucked onto the tip of the iron by the surface tension of the solder.

One hard choice I had to make was whether to solder the chip straight into the board, or use a socket. I opted for a socket, which meant a harder time soldering the “top” layer. Luckily, I was able to dig up some 14 pin machine pin sockets, and thanks to the machine pin itself, they stand proud of the board a little, just enough to sneak in with the soldering iron.

For whatever reason, I decided to solder the led display next, leaving the connectors for last. I partly wanted to see which side of the board the connectors would look better on… I think next revision, they’re going on the bottom. During assembly of the connectors, I nicked the display a couple times with the iron, oh well!

Right now, the display is flashing my initials. Oh, here is the schematic, nothing exciting really!

quick video:

Rainbow LED Chaser

I was bored this past sunday, and needed something to ease my racing brain … so I picked an easy project with lots of flash.

The parts list:

Eight Tri-Color or RGB leds … each led package contains three LEDs
Three 74HC595 Shift Registers … serial load, latching. other varieties would probably work too.
One Microcontroller … doesn’t matter what it is, I used a pic18f252 since it was handy.
Twenty-Four Resistors … I used 150 ohm to set my led current at 20mA, but use anything from 56-220 ohms

The tri-color leds I used are wired as common anode LEDs … each led inside the package has its own cathode pin and shares a common anode pin. So, all my anode pins connect to the postive rail on the breadboard. There’s no reason a person couldn’t use twenty-four discrete LEDs, or eight common cathode leds. Since my leds are “active low”, outputting a 0 turns them on, outputting a 1 turns them off… if you used common cathode leds, they would be “active high”, a 1 would turn them on and a 0 off. If you used discrete leds, well, hook ’em all up one way or the other.

Next comes the connections to the shift registers. Think of each register as a chip containing eight switches you can turn on or off remotely. Each of the 24 LEDs gets connected to an output on the register, and they need to be grouped by color and kept in order. So looking at the picture below, working left to right, I connected all the red leds to the first register, all the blue to the second, all the green to the third. This resulted in the rats nest of wires you see between the chips and the leds. Concerning the registers themselves, they have three connections of up-most importance. Pin seven is the ground connection, pin fourteen is the +5v connection, and pin thirteen is the enable or tri-state pin. The tri-state pin must be tied to ground in order for the outputs on the register to work. Next up is the data connections. The 595 offers a nifty feature of serial pass-through. Using this feature, you can chain a bunch of them together, and treat them as a large number (in the programming). This is done with the QH* and SER pins. QH* connects to SER on the next ic ‘down stream’. On the first IC (the rightmost in my picture), SER connects to the microcontroller. Now in order to ‘load’ the chips with serial data, the microcontroller has generate a ‘clock’ for all the chips to sync to. This clock signal is transmitted on the SCK (serial clock) line. All three SCK lines are wired in parallel to the microcontroller. Last, since we want the data to be retained by the registers, even if the pic stops transmitting, we need to latch the data. This is controlled by the last data line, RCK. When the microcontroller is finished transmitting data, it needs to pulse the latch clock RCK high briefly. Upon receiving this signal, the registers display the data which they just received, and continue to display it until told otherwise. I have some other lines connected, but don’t use them… they are the SCLR line, which clears the data from the buffers, and the enable line. The microcontroller keeps the enable line high (disabling the registers outputs) until it is read to start sending commands… this prevents the registers from powering up with weird random data being displayed.

That’s it for the hardware side … really simple. All the magic happens in software… which I will write about in part two (yes, I’ll post the code too). As a spoiler, all the software does is boolean math, shifting and inverting 8-bit words of 1’s and 0’s around.

Here is the breadboard:
rgb led microcontroller 74hc595 shift register
The parts in the grayed out areas are just stuff left over on the breadboard from an earlier project, or support components for the microcontroller.

Here are some videos:
Initial Test Program:

Chasing effect:

UPDATE:
Due to all the connections (24 of them between the registers and the LEDs), drawing a schematic can get messy. I chose to avoid this mess by using Eagle “BUS” feature, which allows a large number of signals to be combined into one wire. The schematic below is drawn using a much less expensive and smaller PIC than the one pictured in the breadboard … however the idea is still the same.

74hc595 shift register microcontroller rgb led chaser

Here is the source code (in BASIC of course) for the “center pulse” effect, it’s pretty much just taking binary patters of 1’s and 0’s and moving them around to create the ‘animation’.

click to download centerpulse.bas

Long Time, No See

Sorry I’ve been neglecting my blog!

I’ve been doing a lot of reading and research, as well as playing with a new toy.

Here are the top-5 items in my current project queue, sorted by priority:

1) LED backlit Rooster Project – Christmas Gift
2) High-End LED under cabinet lights – Christmas Gift
3) Rainbow LED chaser – New Toy / Fun Project
4) LEDs as Sensors – Interface Project
5) LED Matrix Display – 8×8 display modules

I’ll write more about the rainbow chaser tonight (I promise!)… The backlit rooster is just a cheezy Christmas gift I hope to do up cheap for someone who likes roosters and chickens in their kitchen decor. The high-end under cabinet lights are based on Nichia Jupiter LEDs – this project is currently in the very early design stages. I hope to get a proof of concept prototype built by xmas. LED as Sensors is sort-of stuck – I became obsessed with trying to build a large sensor array, but decided today, I don’t need a large sensor array… so I’ll regroup and start a fresh with actual application development for the sensors as I have them now, and worry about building them larger down the road. The LED matrix display will probably never get built, I just had some fun drawing up the designs… Once I priced out the cost to build them, my interest diminished (64 super flux LEDs for each module, 10-16 modules for a good sized display!).

Iron in the Fire II

In my previous post, I write about an LED matrix for a marquee. The display itself is a two-board solution, the second board or ‘daughterboard’ piggy-backs on some pin headers from the display board. This second PCB provides the control interface and logic for handling these 64 leds, and passing along control data to any upstream displays.

led matrix display schematic diagram

The controller uses a 595 shift register to provide the ON/OFF control for each of the eight columns. To provide maximum current to these columns, I have used the ULN2803 current-sink driver. The 2803 is basiclly a darlington array which uses a small current to sink up to 500mA, on each channel… and it has 8 channels. So if I really blast my piranha LEDs with their bleeding edge maximum current of 80mA and the data called for all eight columns to be active at once, the entire column would need a total sink of 640mA! I believe the 595 alone can only sink 200mA. The daughterboard has no circuitry on it for controlling the rows of the matrix – they are just wired in parallel to the daisy chain connectors, which will connect it to a current source on the ‘master control’ or interface board. I plan to use some P-Channel mosfets to handle sourcing potentionally several amps of current. For example, if I connect sixteen of these modules together, and want to turn an entire row on at once, that is 128 LEDs, each drawing 80mA, for a grand total of 10.24A. Wow, that is a lot of power, my goodness, good thing I have a bunch of old AT style switching power supplies laying around, with 15-20A on their 5v rails.

The 595 shift register is just a set of switches, which are set through a synchronous serial interface – a big long string of 1’s and 0’s is clocked out of whatever ends up controlling this marquee (most likely a PIC microcontroller). Each register takes eight bits, thats why I went with eight columns. So if I build a sign with sixteen of these modules, I’ll be pushing 128 bits out a serial port. The entire register will need to be updated for every row, so an entire refresh will take 128 * 8 bits or 1024 bits. At 20mHz, my pic can clock a bit out every two microseconds, so refreshing the entire marquee would take roughly 2.1 milliseconds. A frame rate of 30FPS should be entirely possible, since 1/30th of a second is approximately 33 mS, that leaves a LOT of extra time for the pic to take a nap with… and if I go crazy and build some huge mother of an array, I can beef the pic up to 48mHz, hammering those bits out more than twice as fast.

The display modules are ‘modular’. Daisy-chain connectors provide pass-through of the row current, and data-control signals from the microcontroller. The D-IN port connects the ‘upstream’ registers serial output (QH*) to the current registers serial input (SER), the D-OUT port connects this registers serial output to the next registers input. The rest of the signals are straight parallel. Only changes in the software of the microcontroller would be required to add or subtract display modules from the finished array.

The pcb design and layout is ‘diy compatible’ I’ve used all through-hole components, and jumpers instead of via’s. If I send these out to be fabbed, I’ll probably change the signal routing around, switching the jumpers to vias, perhaps I’ll go with smt ICs, depends on how the layout works out… I might keep the through-hole because I like being able to run signals between the pins and under the ICs, which is hard to do when they’re tiny! The notations “dont move” are just to remind myself (or anyone else) that you can’t move the ARx (anode row) and CGx (column group) connectors, because they’re specificly positioned to mate with the display board.

composite pcb layout image
composite image of controller layout and top+bottom layers.

same disclaimer as my earlier post, these designs and images are not public domain… please read the disclaimer in my earlier post.