How to make a binary clock: design

Friday, June 12, 2020

How to make a binary clock: design

Description

Want to make an Arduino project a bit more complicated than blink? In today's episode of House of Hacks, Harley starts a project on how to make a binary clock. This project will use an Arduino and be presented in multiple parts. Today, the first part will be the overall requirements and design. In future videos, the software, circuit and finishing it off with an enclosure will be covered.

Resources

  • All the information to make this project: https://www.house-of-hacks.com/p/arduino-project-binary-clock.html
  • If you just want to buy one: https://amzn.to/3eGXFVD (Amazon affiliate link)
  • Get a digital version of the new Arduino poster by signing up for the House of Hacks newsletter: https://list-optin.house-of-hacks.com/arduino
  • Or a printed copy of the poster can be bought on the House of Hacks store: http://store.house-of-hacks.com

Contents

  • 0:00 Project introduction
  • 0:59 Welcome and about House of Hacks
  • 1:19 Description of BCD
  • 2:14 BCD for binary clocks
  • 3:05 Project requirements
  • 4:02 Controlling the LEDs
  • 5:45 Tracking the time
  • 6:18 Adjusting the time
  • 7:23 Arduino selection

About

Here at House of Hacks we do tutorials, project overviews, tool reviews and more related to making things around the home and shop. Generally this involves wood and metal working, electronics, photography and other similar things. If this sounds interesting to you, you may subscribe here.

If you’re interested in learning more about the House of Hacks' values, here’s a playlist for you.

And here’s the most recent video.

For a written transcript, go to How to make a binary clock

Here's a list of the tools I use.

Music under Creative Commons License By Attribution 4.0 by Kevin MacLeod at http://incompetech.com.
Intro/Exit: "Hot Swing"

Transcript

A number of years ago, at a software conference, one of the evening activities as an outing to a hands-on science museum.

While there, I noticed and picked up this binary clock.

It uses something called BCD encoding and I thought it'd be kind of cool to make my own version of this as a project.

Technically, it could be done with some simple logic circuits and a timer.

But this would involve more hardware design and wiring than I wanted to be involved with and so I'm going to go the easy route and use an Arduino.

This is going to be done in four parts.

Part one today is the basic requirements and design.

Than as I'm waiting for parts to come in, I'll go over the software design and how to actually do some testing without having a complete circuit finished.

The third video I'll assemble all the circuits and get it running.

And then the fourth video will be creating an enclosure for it.

Welcome to the House of Hacks. If we’re just meeting, I’m Harley and I make stuff out a variety of materials.

For example, in this project, we're doing design discussions, and software and electronics and mixed media for the enclosure.

If making a things out of a variety of materials in the workshop is something that's your thing, consider subscribing and you won’t miss future episodes.

BCD is an acronym for Binary Coded Decimal and this was an encoding system that IBM came up with nearly a 100 years ago in the 1920s for use in their early mechanical devices.

As early computers came on the scene, they took this basic coding that they used and expanded upon it to use in the computers.

It was called EBCDIC at the time and was actually used until relatively recently.

Interestingly, early in my career, I had to write an ASCII to EBCDIC conversion routine for use by our business partners.

Before going to the whiteboard, a couple notes.

First, the code and schematics for this project, is available for free download off of GitHub.

And second, a commercial version of this clock, kind of like the one that I picked up at the conference, as well as all the materials I'm using in the project are available on Amazon. I’ll leave links for everything down in the description below.

In BCD, each column represents a decimal digit, coded in binary. The first column is the tens digit for the hours, the second is the units column for the hours. Next, we have the tens and units digits for the minutes and the tens and units digits for the seconds.

In decimal, we need four bits to cover the all digits 0-9 in binary. So all the units columns on the LEDs have four LEDs. Because on a clock, none of the tens digits go all the way to 9, we don’t need a full 4 bits for each of the tens columns. Hours for example only go to 2, so we only need 2 bits for a 24 hour clock. The minutes and seconds only go to five so we only need three bits for those.

So, to make this, what are our requirements?

For the LEDs, we have 3 groups of 4 and 2 groups of 3 for a total of 18 and another 2 for a total of 20 LEDs that we need to control.

Second, we need a way of keeping track of the time.

Third, we need a way to set the time.

I’ll talk about all these requirements in detail but first I’m excited to announce that I’m working on some Arduino training materials. I have an Arduino reference poster available now and am working on a book for people new to digital electronics and programming the Arduino. A digital version of the poster is available by just signing up to the House of Hacks mailing list where I’ll keep you updated on things happening here. I won’t bombard your email with a bunch of stuff. Just occasional updates when products are released and an occasional news item that I think you might find interesting related to making things. If you’re interested in this, there’s a link below in the description below.

Now, back to the design...

Looking at controlling the LEDs, my first inclination was to think about this as a single string of 20 bits where each digit in each group was put inline with the rest of the bits. The common way of working with large numbers of LEDs is to use a '595 based shift register. This only requires three pins on the Arduino but provides a number of digital outputs. This is so commonly used that there’s a shiftOut command built into the Arduino ecosystem. ‘595 chips typically only work with 8 bits (although there are variants that have more bits) but they can be daisy chained together so you can have an almost arbitrary number of digital outputs, all controlled by only three pins.

Since there’s 20 bits needed and each ‘595 provides 8 bits, I thought about using three shift registers, daisy chained together. This would give 8 times 3, or 24, bits. The first 20 bits would be used and the last 4 bits would be ignored.

I coded up a prototype sketch using this idea but it ended up being more messy than I really liked. All the code was one big blob with a bunch of dependencies spread throughout the whole thing. Some of that mess could be cleaned up with some refactoring, but it was still going to be more messy than I really liked.

Upon reflection, I realized each group of two numbers only needs at most 7 bits and I have three groups. For the purposes of this project, I could still use the three ‘595s but instead of daisy chaining them together, I could connect each one to the Arduino directly. This would help make the code cleaner. Each ‘595 needs three pins, so that’d be a total of 9 pins for the LEDs instead of 3. Let’s look at the rest of the requirements and see if there are enough pins.

To track time, the most reliable would be to use a clock module. A real time clock module, also called an RTC, is designed to interface with micro controllers and has it’s own battery backup. There are a number of different models. I selected to use a DS1307 because they can be had inexpensively and communicate with the Arduino using only three pins over the I2C bus.

It would also be possible to use the Arduino itself to track the time although I’m not to sure how accurate that would be. It would provide a software only solution though.

Finally, we need a way to set the time.

The commercial unit I have uses two buttons. One increases the hour each time it’s pressed. The other increases the minute each time it’s pressed and if they’re both pressed at the same time, the seconds are increased.

This could work, but I don’t have any good buttons that’d be appropriate for mounting in an enclosure and, in my spare parts bin, I have a rotary encoder.

Rotary encoders come in different styles. This particular one allows the user to spin it in either direction without any limits. It can also be pressed to indicate an event. The micro controller can detect which direction it’s turned and take appropriate action.

I think this would be easier to make accessible to the user in the enclosure, so I’m going to use it. It uses two pins to the Arduino to communicate the rotary action and one pin to communicate being pressed.

So, all in all, I’m looking at using 9 pins for the three ‘595s, 2 pins for the clock module and 3 pins for the rotary encoder. A total of 14 pins.

Since I want to keep this pretty compact, I’m going to select the Arduino Micro. It’s only about 2 inches long and about 3/4 inch wide and designed to go in breadboards and pre-made circuit boards with standard hole spacing. And it has 18 digital I/O pins. Four more than then 14 that we need.

I think it should work well.

So, I’ll go order the parts and, while waiting for them, I'll show you the software in this video.

If that video hasn’t been released yet, I’ll see you in this other video where I do an Arduino project simulating wind to make wind chimes sound indoors.

After watching that, go make something.

Perfection isn't required. Fun is!