Alex’s Nixie Clock

Liz: Alex is ten years old. He lives in Texas. He shared his most recent school project with us. It’s a great project and a fantastically clear tutorial: we thought you ought to see it too.

My Mom wanted a Nixie Clock, and I needed to do a project for school. I had a Raspberry Pi I wasn’t using, so I built a Nixie Clock. It took me about 2 months.

Raspberry Pi Nixie Clock

This is my Raspberry Pi Nixie Clock. It took me about 2 months to build because I had to learn so much. Full details can be found on my blog: http://alex.atomicburn.com

My Dad ordered some Nixie tubes and chips from Russia, and bought a 170V power supply to power the Nixie tubes. The first thing to do was to test them:

nixie1

To start with I installed a tube, chip and power supply onto a breadboard. The chip has 4 input lines (A, B, C, and D) that are used to tell it which number to light up. For example in binary 7 is 0111, so you need to set input A to high, B to high, C to high and D to low (A=1, B=2, C=4 and D=8) to light up the number 7. I tested the first one by using a jumper cable to connect the 4 inputs to either 0V (low) or 5V (high).

Once I knew the first tube and chip worked, I wrote a program on the Rasberry Pi to test them. I used 4 GPIO pins, wired to pins A,B, C and D on the chip. My program would loop through the numbers 0 to 9, and turn on/off the pins by converting to binary using logical AND’s.

For example – for the number 7:

  • 7 AND 1 = 1, so pin A would be set high.
  • 7 AND 2 = 2, so pin B would be set high.
  • 7 AND 4 = 4, so pin C would be set high.
  • 7 AND 8 = 0, so pin D would be set low.

Once I had the program working, it was easy to test all the chips and Nixie Tubes. Everything worked, except one tube – the 3 and the 9 would light up at the same time. So I used this for the first digit for the hours, since that only ever needs to show 1.

The Program:

When the Raspberry Pi starts up, it automatically starts my clock program.

I wrote the clock program in C using the geany editor.

When the program starts, first it sets all the digital pins to OUTPUT and LOW to make sure everything is off.

Then I turn on pin 0, which turns on the high voltage power supply using a transistor.

Then I test the clock, which makes the hours show 1 to 12, and minutes 0-59.

Then I start the loop. Once every second I do the following:

  • Ask the computer the time (if it is connected to the internet, it will always show the right time).
  • The hours come back as a number between 1 and 23, so if the hour is bigger than 12, I subtract 12 from it.
  • Then I break out the hour into 2 digits, and the minutes into 2 digits. The first digit is the quotient of the hour divided by 10. The second digit it the remainder of the hour divided by 10. Then I do the same for the minutes.
  • For each number, I have to convert it into binary (for example 7 is 0111 in binary). Each number has up to 4 wires, each wire is for a binary digit. If the digit is 0 the pin/wire is set to LOW, if it is a 1 it is set to HIGH. So for the number 7 the wires are LOW, HIGH, HIGH, HIGH.
  • These wires are soldered to the driver chip. The chip has 10 switches in it, one for each number in the Nixie Tubes. These switches are connected to the chips with yellow wires. The chips look at the 4 wires to see which binary number it is, and then switches on the correct light in the Nixie Tube.

The table below shows the wires and their values for each digit.

Digit Black Wire Blue Wire Grey Wire White Wire Binary
0 LOW LOW LOW LOW 0000
1 LOW LOW LOW HIGH 0001
2 LOW LOW HIGH LOW 0010
3 LOW LOW HIGH HIGH 0011
4 LOW HIGH LOW LOW 0100
5 LOW HIGH LOW HIGH 0101
6 LOW HIGH HIGH LOW 0110
7 LOW HIGH HIGH HIGH 0111
8 HIGH LOW LOW LOW 1000
9 HIGH LOW LOW HIGH 1001

Here is the source code in C:

#include       /* These are libraries */
#include 
#include 
#include 

// turns a pin on or off
void nixiePin(int p, int v){

  if (p != -1) {
    digitalWrite(p, v);
  }
}


// converts to binary and sends values to 4 pins
void nixiePins(int p1, int p2, int p4, int p8, int v){

  nixiePin(p1,v&1);
  nixiePin(p2,v&2);
  nixiePin(p4,v&4);
  nixiePin(p8,v&8);
}


// splits the time into digits
void nixieTime(int h,int m, int s) {

  nixiePins( 1, -1, -1, -1, h/10);  /* quotient of hour / 10  */
  nixiePins( 2,  3,  4,  5, h%10);  /* remainder of hour / 10 */
  nixiePins( 6,  7, 21, -1, m/10);  /* quotient of minute / 10*/
  nixiePins(22, 23, 24, 25, m%10);  /* remainder or min / 10  */
}


// makue sure all the digits work
void testClock(void){
  int i;
  
  for (i=1; i<=12; i++) {
     nixieTime(i,0,0);
     delay(250);
  }
  for (i=1; i<=59; i++) {
     nixieTime(12,i,i);
     delay(250);
  }
}	


// set up the pins we will use
void initPin(int p) {
  pinMode(p, OUTPUT);
  digitalWrite(p, LOW);	
}


// this is the main part of the program
int main (void) {           
  time_t now;         /* its a variable that holds time info */
  struct tm *ntm;     /* it is a variable */
  int i;
  
  wiringPiSetup();    /* set up pins 0-7 and 21-29 to use  */
  for (i=0; i <=7;i++) {
    initPin(i);
  }
  for (i=21; i <=29;i++) { 
    initPin(i); 
  } 
  digitalWrite(0, HIGH);            /* turn on high voltage power */ 
  testClock();                      /* test all the digits */ 

  while (1) {                       /*starts and infinite loop */ 
    now=time(NULL);                 /* ask the computer for the time */ 
    ntm=localtime(&now);            /* it formats the time */ 
    if (ntm->tm_hour > 12) {        /* if hour is more than 12 - 12 */
      ntm->tm_hour = ntm->tm_hour-12;
    }

    /* it tells it to write that number to the nixie tubes*/
    nixieTime(ntm->tm_hour,ntm->tm_min,ntm->tm_sec);   

    delay (1000);   /* wait for 1 second */
  }

  return(0);
}

The Circuit Board:

nixie2

My dad drilled a piece of plastic for me for the Nixie Tubes to sit on.

The circuit board has 4 Nixie tubes, and 4 chips (one for each).

The chips are wired to the Nixie Tubes with yellow wires.

Black wires are used for Ground, and red wires for 5 and 12 Volts. 5V and Ground was wired to each chip.

The Nixie Tubes require 170V DC to work, so in one corner I have soldered a high voltage power supply. This takes 12V and turns it into 170V. All 170V wires are green.

The Nixie Tubes need resistors attached to them, so they don’t take too much current and burn out. The resistors limit the current to 2mA.

There is also a Transistor with 2 more resistors to limit the current.  This transistor acts as a switch, and lets my program turn the High Voltage Power Supply on or off.

I also added a USB port, and wired it so it has 5V and Ground. This lets me use it as a power supply for the Raspberry Pi.

Then the inputs to the chips were wired to pins on the Raspberry Pi GPIO (see code for pin numbers).

Soldering took a very long time. Before we turned it on, my Dad checked over everything, making sure the 170V was safe. He found a couple of shorts that had to be fixed.

When I turned it on the first time, the tubes just half glowed and flickered. However if I took two chips out of the sockets, then the other two would work. This was because the 170V power supply wasn’t powerful enough. I double checked the datasheet, I should have been using about 1.5W, well under the 5W the power supply should be able to make from 5V. Instead of running the high voltage power supply on 5V, I tried 12V (it is rated up to 16V input), and that solved the power problem.

The Case:

I made a box out of wood and plastic. I got to use a big circular miter saw with my Dad supervising to cut the wood. The plastic is cut by using a sharp blade to cut into it, and then snapping it. Then everything was screwed together:

AlexNixie

What’s Next:

I was very nervous about taking it into school – the last boy that took an electronic clock into school in Texas got arrested, so my Dad contacted the school first to let them know. I think my teacher was impressed, I had to explain everything in detail to her.

This is only the start of the project. I want to put it in a nicer case with my Dad’s help before I give it to my Mom. I want to add an alarm. I also want to add a hidden camera, microphone and speaker, so it can run voice/face recognition. Then I can turn it into J.A.R.V.I.S. from Ironman. That may take me a while, but I’ll add more posts on my blog as I do things to it.

Liz: Have you made a school project with the Pi that you’d like to share with us? Leave us a note in the comments!