Time is on Your Side

Or at least it will be, once you build this network-based clock

4 min read
Time is on Your Side

There’s no longer any excuse for having the wrong time. Computers, set-top boxes, and even some wristwatches can get their time from the U.S. Naval Observatory or some other authoritative source. But what about a device you build yourself? Many will come with a timing chip that you can use as a counter, but they won’t tell you what time it is in the real world or self-adjust for daylight saving time. What you want is a microprocessor on a computer board that will query a network for the correct time and pass it on to the rest of your device. This month’s project is just that, a clock on a single-board computer that uses the Network Time Protocol (NTP) to give you millisecond accuracy for about US $115.

Single-board computers (SBCs) are cool because they pack a lot of functionality into a very tight package. They’re scary, too, because they involve you in technologies that are usually taken care of by off-the-shelf computing hardware. For one thing, SBCs don’t usually come with such niceties as displays and USB ports. And when you get down to the smallest of the small, you are pretty much dealing with a processor, some flash memory, a few input/output ports, and a way to burn an image to an electrically erasable programmable read-only memory (EEPROM).

It can get pretty complicated, so a kit makes for a nice introduction. Tuxgraphics, of St-Laurent, Que., Canada, has one for 50.50, or about US $70. You’ll get an SBC based on the ATmega168 processor, an 8-bit reduced-instruction-set computer chip running at 20 megahertz. The SBC has 16 kilobytes of flash memory, 5 kilobits of EEPROM, and a whopping 1 KB of RAM, so you’re not going to be booting up Linux or running Photoshop here. But what the board lacks in memory, it more than makes up for in hardware—it has an Ethernet port, digital I/O ports, eight analog inputs, and an LED socket.

The second major component in the box is a 16- by 2-character LCD panel for displaying the time. Then there are a few odds and ends—a 3.3-volt voltage regulator, an LED, and a 5-pin header for programming the device—which all get soldered directly onto the SBC. You need your own wire to hook the SBC up to the LCD. I used 22-gauge rainbow speaker wire. There are also three resistors that attach to the LCD module. Two control contrast and brightness, and one goes between +5 volts and the LCD backlight power.

You solder in the voltage regulator and the LED on the SBC, attach six wires between the SBC and the LCD module, solder on the programming header, and finally run +5 and ground to the SBC and LCD module. The holes are tightly spaced, so if you haven’t picked up an iron in a while, you might want to get in some practice first.

Along with the wire, you will also need to provide a source of +5. I was able to find a leftover wall wart with just that voltage, but watch out—some sources claim +5 but really put out far more.

The first time you power up you’ll see only the LCD’s backlight—the SBC comes with nothing installed on it. To get the board running, you’ll need to burn software and data onto the EEPROM and the flash memory, and therein lies the major ”gotcha” of this project.

First, you’re also going to need to buy a programmer for the SBC. Tuxgraphics sells several; the one I got cost 40.50 ($53.58). Essentially, it’s a USB cable with a processor built into it on one end and a 5-pin connector on the other end that plugs into the SBC. The programmer also comes with a LiveCD of a Linux distribution prebuilt to program the SBC.

If you don’t feel like booting up Linux every time you want to program the device, the kit also comes with a version of GCC (GNU Compiler Collection) that runs on your regular desktop and compiles for the ATmega168 instruction set, together with the AVR Downloader/Uploader (AVRDUDE), a tool that can communicate with various programming peripherals (including the USB cable I had bought), so that you can program directly on the device. The CD includes precompiled versions of a test program that flashes the LED and displays an OK message on the LCD, a good initial smoke test to ensure you didn’t fry anything.

The disk also includes a copy of the NTP application ready to run, but you’ll probably need to make some changes—it’s preset for a class A subnet, which is ideal for General Electric or MIT but not typically used with a home network. You’re going to edit the main.c file, changing the IP address of the device, as well as the IP address of your gateway, the IP address of the NTP server you want to use, and your time zone.

With these edits made, you use the ”make” command to build a hex file with the compiled code, and then the avrdude command to write it out to the SBC, which needs to be powered up and connected by the programmer cable. Once installed, the program will try to connect through the gateway you defined to the NTP server. Then it’ll start displaying the current time on the LCD, syncing with the server once every hour after that.




Your other do-it-yourself computer projects will know what time it is if you add a single-board computer, such as this one, from Tuxgraphics. It uses the Network Time Protocol to get continual updates from authoritative time servers on the Internet.


For me, the hardest part of the project was the soldering. All told, it took about 3 hours (and several trips to RadioShack) over the course of a week or so to get everything hooked up. Once the programming cable came, it was another 2 hours to get all the software installed and burn the program onto the device.

The final product is a plain black box that tells me what time it is, as long as I have a network connection handy. It also will provide the same data if I point a browser at the IP address of the device. While the project was interesting for its own sake, I’m looking forward to seeing what else I can do with a network-capable SBC in a box, because I can burn onto it whatever software I care to write.

About the Author

James Turner is a contributing editor for O'Reilly Media and a correspondent for the Christian Science Monitor.

This article is for IEEE members only. Join IEEE to access our full archive.

Join the world’s largest professional organization devoted to engineering and applied sciences and get access to all of Spectrum’s articles, podcasts, and special reports. Learn more →

If you're already an IEEE member, please sign in to continue reading.

Membership includes:

  • Get unlimited access to IEEE Spectrum content
  • Follow your favorite topics to create a personalized feed of IEEE Spectrum content
  • Save Spectrum articles to read later
  • Network with other technology professionals
  • Establish a professional profile
  • Create a group to share and collaborate on projects
  • Discover IEEE events and activities
  • Join and participate in discussions