Dangerpants Labs Darktimer Construction Guide

Materials Required

You will need the following materials, in addition to the electronic components called out in the Bill of Materials:

  • Solder
  • 18-22 ga stranded wire
  • Glue or double-sided tape
  • Mounting hardware for LCD

You will also need a relatively standard set of circuit building tools, including at least:

  • Soldering iron
  • Vise or circuit board clamp
  • Pliers
  • Diagonal or flush cutters
  • Tweezers
  • Desoldering tool/materials
  • Multimeter

If you are using a Pro model of Arduino (recommended for battery life reasons) such as the Pro or Pro Mini, you will need a USB to serial converter, such as this cable or this board to program the Arduino.

Compiling the Firmware

Setting Up Your Environment

If you haven't already, download the Arduino compiler from the Arduino website and install it. A standard installation is all that is required to program the Darktimer.

Tests

If you just want to build the code, you can ignore this part.

The Darktimer code was developed using Test-Driven Development for the majority of the work. It was actually designed to almost entirely be platform agnostic, with the only hardware-centric code contained in hardware.c and hardware.h. Everything else was developed on a Linux machine using GCC and CppUTest.

If you want to use the tests which were used in developing the Darktimer code, you'll need to download and configure CppUTest. This system is perfectly useable as-is, but I found James Grenning's Test Driven Development for Embedded C to be an invaluable resource in learning how to apply test-driven development to an embedded project like this. Once the CppUTest system is set up, running make in the main directory automatically compiles all the code and runs all tests.

Because the code was developed using a standard C compiler, you will find two copies of the code in the tarfile or Git repo: the code in src/ and include/, and the code in darktimer/. The code in darktimer/ is all symbolic links of the src/ and include/ code, arranged so the Arduino IDE will recognize it.

Configuring the Firmware

The file datatypes.h contains the majority of configuration options for the program. Specifically, this is where you can set:

  • the length of different beeps
  • the pitches of different beeps
  • the number of "final" beeps that get more urgent triple-beeps
  • new timer default values
  • key repeat timing

Avoid modifying the values outside the configuration variables unless you're excited about making changes to the code.

Once the settings are configured as you wish, compile the firmware just like any other Arduino program. Load darktimer/darktimer.ino in the Arduino IDE, and it will automatically include the other files, and build like you'd expect. If you haven't yet worked with Arduino, it would be worth purchasing an Arduino Uno and playing with some of the example sketches first.

Putting it All Together

[clicky-clicky]

In the absence of a proper printed circuit board, the Darktimer is best wired in the finest tradition of tube gear: point-to-point. I recommend that you put together the case first, mounting all the pieces where you want them. Once the LCD, buttons, speaker, batteries and Arduino board have been positioned, start cutting wires to the appropriate length to connect pieces together. Be sure to leave enough extra wire so the case can be easily opened. If you're not already familiar with soldering technique, there are many videos on YouTube which can show you what you need to know.

Most of the LCD connections go straight to the Arduino board, but the Contrast pin should be connected to the center pin (the wiper) of the 10k potentiometer. The outer pins of the pot should be connected to GND and +5v respectively. The pot can be glued or taped to the side of the case, or even just left to hang, so long as it doesn't risk coming into contact with other parts and causing a short-circuit.

Wire each switch to the pin specified in hardware.h, with the other leg of the switch wired to GND.

Connect the 100Ω resistor to the SPEAKER_PIN, and connect the + lead of the speaker to the resistor. Connect the speaker's - lead to GND.

Connect the - lead of the battery pack to the Arduino's GND connection (you may wish to set up a ground bar or screw terminal inside the case, since there are so many GND connections), and run the + lead to the power switch. Connect the other side of the power switch to the Arduino's +5v or Vcc pin.

Connecting the LCD

The LCD connections go as follows:

Name Arduino LCD Board
GND GND 1
+5v +5v 2
Contrast Center pin of potentiometer 3
RS 7 4
GND GND 5
EN 8 6
DB4 9 11
DB5 10 12
DB6 11 13
DB7 12 14

I recommend running one GND wire to the LCD, then running a jumper to the second GND connection.

Notes on Battery Power

The Darktimer may be powered directly with either 3 alkaline or 4 NiMH AA or AAA batteries, which produce between 4.5 and 5.5V. AAA batteries won't last as long, but are noticeably smaller, and you should choose your battery based on your own needs. Any battery combination which produces about 5V will work.

The Darktimer prototype (based on an Uno) draws about 45 mA of power typically, but that number will go down noticeably with a Pro Mini. A set of AA MiMH batteries at 2000 mAh should last for 20-30 hours of operation.

Tuning Your Timer

If you are in pursuit of the most accurate timer possible, it is possible to set the one-second timer to quite a precise interval. The hardware.h file contains the TIMER_TICKS define, which is the number of clock cycles (divided by 256 in this case) which should pass for a second to have passed.

If your Arduino's timing crystal is good quality (and most are, but some, particularly those of clone boards, are not), and you have a 5v/16 MHz board, TIMER_TICKS should be set to 62500. If you determine that this produces too-long or too-short seconds, you can modify the TIMER_TICKS value to adjust the length of one second. If your second is too long, make TIMER_TICKS smaller. If it's too short, make TIMER_TICKS larger.

Determining the actual length of a second is left as an exercise for the precision-minded reader.

If you successfully build a Darktimer, I would appreciate hearing about it by email to ian [at] dangerpants [dot] com.