GPS-Controlled Binary Clock

I reckon this project has been about twenty years in the making. Which is slow, even for me!

In the mid-nineties I started playing with PIC microcontrollers. Remember those? An ancestor of the Arduino – an IC that held a microprocessor, RAM, ROM, and some general-purpose I/O pins. You just needed a clock circuit to drive it.

I used one to build a Binary Clock. I’d originally seen it as a desktop silly for BeOS (remember that?) and I imagine the author of that had, in turn, seen it on a X-Windows install somewhere, etc, and that had, in turn, come from an Amiga OS desktop thing, etc. You get the idea. Anyway, I thought it would be cool to make a real one.

My circuit drove a grid of LEDs in a scanning matrix: only one column was lit at a time, but it refreshed so quickly your brain was fooled into thinking it was all lit. Each row and column needed a couple of transistors to drive it, and you made the LEDs as bright as possible by omiting current-limiting resistors. This worked OK as long as your circuit scanned the rows at a fast rate … but if it went too slow (or if your code crashed) then a column of LEDs would be lit for too long and they’d pop.

It looked cool, taught you to read binary at speed, and was hopefully useful. And it was a bit of a disaster.

This was largely because I’d built it on stripboard (so it looked terrible) but also because it kept hopeless time – making it useless as a timepiece. So it went into a box and was never seen again. That is, until I found my notes on it whilst sorting through some boxes last October.

So I decided to have another stab at it. After all: PCB manufacturing is cheaper these days, Arduino C development is easier than PIC assembly and there are some interesting new components available that make the task much more fun!

How it looks now

For those of us who don’t like to read all the waffle … here is the result:

The display

My original display was being done by the PIC, which was refreshing the screen whilst also trying to read button inputs and track the time.

So what was being done by a microprocessor and ten transistors back then can now be done by a single component: the MAX7219. This will drive a matrix of 8×8 LEDs, or eight seven-segment LED displays. Just send the bitpattern of data to the IC, and it will take care of keeping the screen refreshed. The “host” circuit only needs to send data when what is being displayed needs to change.

Tracking the time with a realtime clock

To keep track of time, my original circuit just counted processor ticks. But processor speeds can vary a lot throughout the day, mostly due to changes in room temperature and the inherent tolerances of the components.

Instead, we use an RTC (“realtime clock”). This is an IC that keeps track of time, and can generate a 1Hz pulse. Optionally, it can be connected to a backup battery (like a watch battery) so it’ll keep track of the time even when the rest of the project is powered-off. I’m using a DS1307, just because I seem to have lots of them around.

Knowing the right time

One of those things that bothers me (far more than it should) is when clocks don’t tell the right time. I used to work with someone who deliberately set his car’s dashboard clock 10 minutes too fast because “otherwise I’d be late for everything”. No, you idiot! You know it’s telling the wrong time, so your subconscious just compensates for it! Why not just have the clock tell you the right time, and then leave the house ten minutes earlier?

They never found his body …

I love clocks that set themselves! I need to have something around the house that’s telling a time I can rely on! And these days, there are all sorts of ways of getting the accurate time.

For this project, I’ve used a GPS receiver. Which seems like an odd thing (a GPS receiver for an indoor project?) but hear me out.

GPS receivers need to know the current time because that’s a fundamental requirement of how GPS works. The receiver times the delay between the signal leaving the satellite, and it receiving it (the schedule of these broadcasts are stored in the receiver’s Almanac). To do this, the GPS receiver must have an incredibly accurate internal clock. The GPS receiver uses messages broadcast from the satellite to calibrate its own internal clock. When it feels it knows the right time, it then moves on to calculating a position. So whilst a GPS receiver located indoors might never get a proper fix on its position, it can normally get the current time after only a few minutes.

My home office is my garage – it has no windows, is insulated, has a big metal door, and is filled with computers and electronic equipment. And even in there, GPS receivers are able to get the time within about five minutes. Which is perfectly acceptable if you’re building a clock which will be hung on the wall and left running all day.

Interestingly: those same GPS receivers have much more difficulty at work. This is a nice, open office, with nice big windows … covered in that anti-glare tint stuff. It seems to kill GPS signals stone-dead. So if you’re thinking about building something like this, it’s worth thinking about where you’re going to situate it.

Next month I plan to make a variant that gets the exact time from the Internet, with the NTP protocol. If you don’t think GPS receivers will work in your office but you have Wifi access, then perhaps hang on for that.

The circuit

The host processor is an Atmega328P, driving a DS1307 (with optional backup battery), using a MAX7219 to drive the screen. It decodes data from a GPS receiver and uses that to set the time. Two pushbuttons mounted on the PCB allow cycling through any of the 39 timezones (time from GPS always comes in as UTC, so we need a way to configure for local time).

I’ve designed it so that the clock spans two PCBs. The matrix of LEDs goes on the front PCB, and all the driver electronics goes on the back. A simple pin-header connects the two boards electrically, along with standoffs at each corner to hold them together structurally.

The software

There’s not much to say about the software, as it is built on stuff that I’ve blogged about before (GPS data decoding, and RTC clocks via I2C). The only thing that’s new is using the MAX7219, so I’ll do a separate blog post just on that.

Reading the clock

The time is shown in “Binary Coded Decimal” format – which means each of the six digits of HH:MM:SS are represented as a binary column. For example:

The first column just has the “1” bit lit – so that’s a 1. The second column has “4” and “2” lit – so that’s a six. Reading from left to right, the time shown above is 16:50:29 … or just after ten-to-five in the evening.

It becomes obvious when you see it in action – particularly the seconds, as they update quickly enough for you to follow what’s going on. With a bit of practice (which is why I find it works well on my desk) it becomes very easy to read. It’s a useful and educational clock for all programmers, geeks and electronic enthusiasts … and a good way to annoy everyone else!

Display colours

I went a bit nuts buying different coloured LEDs. Twenty years ago your choices were red, yellow or green. Blue ones were an expensive luxury. These days there are lots of colours in lots of different kinds of plastic. So you can choose a colour scheme that works for you.

Personally I’ve found it looks best if you arrange colours for each column, or each pair of columns. It makes speed-reading it easier if the hours, minutes and seconds are in three different colours. I tried colouring things by row – it didn’t look too great. A bit incoherent. But maybe that’s my appalling lack of skill in colour combinations!

One colour for all 24 LEDs looks pretty good, too. Perhaps less is more?

Ordering the kit

I hope the kit will shortly be available to buy (when the administrators approve it) from Tindie, here. It includes all the components needed (including a pre-programmed microprocessor), a USB power cable (it consumes around 150mA at most, so you can run it from a spare USB port on your PC or a small power adaptor for charging mobile phones) and your choice of LEDs.

The GPS receiver is an optional extra, because it costs nearly the same as the rest of the kit. Personally, I love the obsessive accuracy – but it might not be somerthing that matters to you! If one isn’t present then it defaults to working like a regular clock (the two buttons on the back allow you to change hours and minutes). So it’s still a useful timepiece even if you live in a Faraday Cage. Without assistance, the DS1307 is accurate to within a few seconds a day.

The project doesn’t come with any form of enclosure – partly because I think it looks pretty cool “naked”, but also because I’m interested to see what ideas people have. Want to build a clear acrylic box? Or a wooden one? Are you going to hang it on the wall, sit it on your monitor, or buy a cradle for it? 3D-print some comedy clown shoes to stand it upright?

[Click here to go to the Binary Clock project page]

I sell on Tindie


Leave a Reply

Your email address will not be published. Required fields are marked *