söndag 3 april 2016

The quest for time, in plain old words!

The idea was born discussing different projects at work. One of my colleagues told me about a clock called Qlock2, it is a clock that tells time in words. The first thought that ran through my head after seeing it in action was
"Oh my, I have to have me one of those, and wouldn't the best way to get hold of one be to build one?!"
So the first task was to just try to figure out where to start. For you to get an idea on how this clock looks and perhaps get a notion about which kind of problems that needed to be figured out in order to build it your selves look at this:
The time is shown in five minute intervals, notice though the corners, each LED in the corners represent a minute within the interval. Thus when the time is 07:57 the clock will say "IT IS TEN TO EIGHT" and two corners are lit.

Starting up.

The first thing that struck me was the need for the word matrix, and what would be cooler than getting it cut out in steel? Nothing! Thus I got hold of a friend of mine that I knew had access to a laser that was able to cut steel. And voilá the words were born:

The first stumbling steps.

Well, now I had the steel plate with all the words. What would be the next logical step? Of course figuring out how to light up each individual letter on it's own. Given that we have 11 rows and 10 columns we have 110 points that need to be individually addressed. The initial feeling is
What kind of micro controller has 110 outputs? Let alone what kind of light source would one use? Short cuts could be made by "cheating", which would mean that instead of individually light up each point on the matrix, one could have a single control for each word instead, but how cool would that be? So that was actually never an option for this project. Getting back to the great questions about which light source to choose it turned out that the answer was right above my head. When building my man cave (yes, of course I have one!) I used LED-strip as overhead light source, this strip can be cut every three LED. The length of a cut strip fits very well for the letters on the steel plate. Thus began the work of creating the LED-strips for each letter on the board. First of all, creation of the strips. Cut, solder, repeat...

A lot of soldering later the boards points were completed, great success! But while that this was well and good, the problem of individually controlling these LEDs was still not figured out. Since I have done some work previously with the great Arduino board, it would be a good idea to use that one as the controller for the clock. Problem is that the basic Arduino board only has 14 outputs, and I must control 114 (there are the corner LEDs as well!). Furthermore the LEDs of choice or at least those I bought from China to a very good price operates at 12V, the Arduino operates and outputs only 5V. Also all these LEDs (342 of them in total, remember three for each letter) would require quite a lot of current as well in order to light up properly. Attacking the problem head on I decided to address the fact with the limited number of outputs from the micro controller. In order to extend the number of outputs I found a small chip called 74HC595. Three of these setup in a daisy chain (no that is not a bracelet) made me access the power of 24 outputs directly by only using 3 on the Arduino board. Of course you are now wondering why on earth settle with only 24 outputs? Well in fact I really do not need that many, I only need 21, 10 for the rows and 11 for the columns, let's investigate that a little further. What I use is a technique called multiplexing.

Multiplexing bonanza

In order not to have a single output setup for each point on the clock we can use the fact that the human brain in combination with its sensor called "eye" is somewhat of a slow mover. In fact we are so slow, in comparison with how fast a little micro controller can operate (at a lightning fast 16MHZ), that if we were to switch a light bulb on and off really really fast, I mean insanely fast, our slow sensors would never understand that the bulb in fact turned off. This phenomenon is called [persistence of vision(https://en.wikipedia.org/wiki/Persistence_of_vision). So in order to be the evil master mind and fool all tear stained eyes beholding the clock, the words are individually lit up by turning each row and column on and off really fast. See pictures below for a mesmerizing explanation.

Courtesy of instructables

Picture above taken from a project on Instructables.

We need to prepare the LEDs and set them up in columns and rows:
Place the led strips.

Make room for wiring.

Rows and columns my folks, just rows and columns...
Finished, with power on all LEDs.
As you can see we can now power up all the LEDs.

Voltage, WATT about it. 

But wait there is still trouble in clock land. Even though all the dots of the matrix now are interconnected in order to support the multiplexing, the Arduino still stubbornly only provides 5 volts while the LEDs screams for more than twice that. A really cool invention, for which the Nobel prize actually has been awarded (1956), all though to the wrong people as the committee missed the fact that there had been patents given as early as 1923 for the awesomeness called transistors.

A transistor can be used as an amplifier, a switch or as a voltage regulator among other things. It works sort of like a tap water crane where you use one force (your arm) to control another force (the water flow). Thus applying and differentiating a base voltage a higher voltage can be controlled through the transistor. That is exactly what is needed in order to get the clock dots light up!

Each column need to be grounded at certain points in time (oh, no they are not misbehaving, i.e. it is not house arrest we are talking about here). We need to connect them to the electrical ground when we want current to flow through the LEDs. This is called low side switching and can be achieved by using a NPN-transistor, which in fact is the most common one.

This little critter will open the gates of electrons if a certain voltage is applied to the base of the transistor. See below schematics.

A small current controlling the BIG current..

So, ok we are now able to use the 74HC595 to switch the transistors on the low side on and off on demand. Hurray! So if we apply 12V at each row we can now individually turn each column on and off using the switching, which means that we ground each row at the columns.

That is only half the solution though. We must also be able to individually switch on and of the 12V feed on the rows. The PNP transistor is then what we need. It however operates a little bit differently from that of the NPN. It will only turn off if we apply the same voltage on the base as what we are trying to control. But wait, and hold all the horses, didn't I just mention that a transistor use one voltage on the base and another as the flow? Yes, indeed I did, but the PNP does not. It is possible to use another NPN transistor and connect that one to the base of the PNP and thus be able to turn it on and off using only 5V. Another hurray! The schematics can look something like this

NPN to rule a PNP, thus controlling the high side!

Off to the soldering iron once again, to make the schematics happen. This can look something like this:

Testing some multiplex circuits, great fun!
Making some  circuit boards.
Aahw, would you just look at all those beautiful wires!

Let there be light!

Minutes, what about them?

To show which current minute within the five minute span the time is, a diode is lit up on the corner, one for every minute past five minutes. A type of LED mostly suitable for the job is the neo pixel for this, a chainable addressable little smart LED that runs on 5 volts. A plus side is also that they are RGB, that is we can have any color we want!

The code, another fun part. 

All hail to the hardware, but what about the software? We badly need it in order to control all this magnificent hardware. For instance we need to translate a certain point in time into the words on the clock. We also need do the heavy duty switching of the transistors so that we get a steady light.

Coding stuff for the Arduino is just as easy as writing some C++ code. What that actually means is that it can be extremely difficult and tedious as we don't get to know anything about what might have broken the program, just because we try to write stuff into an array and don't stick to its size etc.

However the program that we need for this little clock is not that advanced, as I said before we just need to figure out a way to translate a timestamp into which words that need to be lit up on the clock. Since we know which intervals we have to work with we just divide the current time with 5, and look, what we get is an index that we can use to fetch the definition from a predefined list. If the division doesn't add up it just means that we are in between two intervals, and "the rest" can be used to figure out which minute LED (that is corners) that need to be lit.

If you are not that familiar with programming it might sound like magic what you have just read. And that my friend is because it is pure magic :-). I will write more about the solution in later blog posts.

A picture is nothing without a frame.

Using simple wooden 90 degree angled pieces and some ninja moves with a hand saw the base frame of the clock was set together. Well, there was also a pneumatic nail gun and some glue involved to be honest.

Glue and stuff.

Power and control buttons.

Adjusting the board.

Look it fits!

Are we there yet? 

After applying the steel sheet on the frame one could but only be unsatisfied with the result! Without a diffusing barrier between the letter in the steel plate and the actual light source things sort of look kind of non coherent and well to be honest not anything to be proud of. The outcome can be viewed in the video which also quite well displays the code in action!

The great shop of Biltema could perhaps help with this predicament of mine? It turns out, well indeed they have plastic sheets that are diffused. Happy having found the material to realize the idea of diffusing the light source I headed home and did some preliminary tests. This is what it looked like.

Now at last are we actually finished? Could I place this on the wall of my living room and each night gaze upon the creation in wonder with a feeling of that I could not have done any better? Well, of course not. Looking at it, there are a number of flaws in the design. The biggest being the light intensity, mainly this is due to the refresh rate of the multiplexing. So how can we do better? ... this will be continued in blogpost #2 about the dazzling quest for time where the hero will face the Neopixel grid, a lot of milling, spray painting, code and of course the need for serious soldering kung fu......

Your hero for today and author of this blog post is Henrik Grankvist!

Inga kommentarer:

Skicka en kommentar