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.