Saturday, January 16, 2016

Arduino - True Binary Digital Clock

So, nearly a year ago I posted this: It basically is the intent statement for the binary clock I was developing and a teaser sketch. I fully developed my clock shortly after posting that but life got busy and I never got around to publishing the results. Today I rectify that oversight.

I've always thought binary clocks are cool. Unfortunately, most of them are LED based and used BCD instead of real binary output. BCD takes up a huge amount of space and is far slower to read than real binary, so I knew that isn't what I wanted. Also, if you're going to do it on a microcontroller, it takes a ton of GPIO ports to do BCD. After scouring the net for days I couldn't find a single clock that outputs the time the way I wanted, so I knew I had to make it...

As you can see, it's really quite simple. Thanks to the I2C "TWI" communications interface it is very easy to put together and interfaces beautifully with readily available inexpensive peripherals. The real magic happens inside the C program written for it. Here we poll the Real Time Clock for the current time (integer) and do some math and a clever trick using the itoa() function to convert that value into binary (string). Then we send the data to the LCD which updates once a second. Not content with an ill-centered output, I added a series of conditional statements to pad the MSB with [string] 0s as needed to keep the time centered on the screen.

Here is the data file you can download that contains all of the files; source code, required libraries, parts list, and instructions. Enjoy! Binary Clock Data File

If you just want to see the source code here is the stand-alone .txt file.

p.s. I do NOT recommend using the housing I used. It has been a serious pain in the ass because the inaccessible nuts that the screws mount into are set into blind holes which have not been bored out to accommodate said screws. Additionally, the housing's thickness is not great enough to allow pin header cables to connect normally to the pins on the back of the I2C LCD. I had to bend the pins 90deg and then solder the header cables to it. I didn't explicitly show it, but the RTC module nests nicely on the right side of the UNO in the space there, requiring no mechanical restraints.

No comments:

Post a Comment