Sunday, January 25, 2015

Arduino Binary Clock - Serial Output

An upcoming project of mine is a standalone Numerical Sexagesimal Binary Clock that will run on Arduino, and use a high accuracy RealTimeClock to keep time. In the mean time I've worked out a simple program that uses the UNO's onboard 16MHz system clock (oscillator) to keep time. The resultant one Hz events are tallied sexagesimally and then converted to binary. Both binary and decimal outputs are sent to the serial line for viewing on the arduino compiler's serial monitor.

Nearly all, if not all currently made "Binary Clocks" use Binary Coded Decimals (BCD) to display time. BCD is when you use binary for each digit of a sexagesimal time. This is popular because it is much simpler to implement, most people can read easy since all the "binary" numbers are low values, and it adapts easily to graphical and LED display.

Here's an example of Binary Coded Decimals: 1's represent Lit LEDs, 0's represent Unlit LEDs


You read each vertical column as if it were a true binary number and then assemble the sexagesimal time code. So, the above timestamp is assembled from the binary numbers:

0000 or 0
0010 or 2
0011 or 3
0111 or 7
0000 or 0
1001 or 0

This is not how my binary clocks will work.

My clocks will output true binary time; 02:37:09 will be displayed as 0010:100101:001001.

So, check back in the future for the project post for my standalone arduino binary LCD clock. Until then, enjoy messing around with this bit of code!

NOTE: You set the time at point of compiling and uploading, but the arduino doesn't actually begin keeping time until the serial monitor is opened. So, set the time about 30sec ahead, upload, and then open the serial monitor just before it is the set time. On my system it takes about two seconds for the monitor to initialize and the arduino to sync up to it. I use for reference. You could also just set the time for the next minute and watch as it rolls over, then start the serial monitor; this would be less accurate by a few seconds + your response time.

BIGGER NOTE: The arduino's intrinsic time keeping ability is heavily limited by the accuracy of the 16MHz clock. Mine is slow by about 5 seconds per hour, or 2 minutes per day. I've added a few lines that wait for until the arduino has been running for 12 hours and the current minute is near the end of the hour, then it advances the minutes one minute to compensate. Depending on what time it was when you uploaded and started the serial monitor it may have to wait an extra hour until correction. So, this doesn't really fix the inaccuracy problem, but it lessens it greatly, from 2 minutes per day down to no more than ten seconds per day. Your mileage may vary. There's a reason this was just an exercise in getting the decimal to binary conversion working well.

No comments:

Post a Comment