The Dev Bin

Software Development for Fun and Profit

Feb 12
by admin
0 comments

Netduino Nixie Tube Clock Part I: Concept

In this next series of blog posts I am going to cover building a Nixie Tube Clock using a Netduino. I will cover planning, acquiring parts, prototyping the different circuits, programming, and the final assembly. In this section will will describe the project and the basic concepts behind building a DIY nixie tube clock.

What is a Nixie Tube Clock?

A Nixie Tube Clock from Wikipedia

Nixie Tubes

Russian IN-14 Nixie Tube

A Nixie Tube Clock is a clock that uses nixie tubes for display rather than 7 segment displays, lcds, or leds. That begs the further question what is a Nixie Tube?

A Nixie Tube is a gas filled display tube, similar to a neon light. A current of 170 V is passed between the cathode and anode of the desired number, which causes the number to glow usually reddish orange.

Usually a nixie tube will have a number of pins / wires extending from the bottom. Each number will have corresponding cathode, and there will be one anode.

For my project I purchased IN-14 tubes from the Ukraine. Old Soviet Era surplus nixie tubes are the most readily available, but due to the cult following and age they have become expensive especially the Russian IN-18, which from what I have read is the Cadillac of nixie tubes.

So if you plan on building your own clock do your research on the various tubes. the best resource I found on various tubes was Sphere’s Nixie Tube Page. You can also purchase tubes here.

Building a Nixie Tube Clock

There are number of steps and components necessary to build a nixie tube clock. Here is a quick overview. I will cover each step in slightly more detail.

  1. Nixie Tubes
  2. 170V Power Supply (Boost Converter)
  3. Nixie Tube Drivers (74141 Chips)
  4. Shift Registers (Optional)
  5. Real Time Clock Chip or Circuit
  6. Processor (Netduino or other chip/board)
  7. User Interface (Buttons)
  8. Container or Clock Body

Powering a Nixie Tube Clock

IN-14 Pinout

IN-14 Pinout

The trick with nixie tubes is they run on a considerably higher voltage than modern electronics platforms 170V DC vs. 3.3V. This is a considerable jump. So working with a project like this comes with a number of challenges, the first being producing 170 VDC to light a nixie tube, and then directing that voltage to the proper cathodes on the nixie tube.

To deal with this will need to construct a power supply that can reach the voltage. My electronics setup is fairly simple so I am definitely rely on the wisdom of the internet to help me design this.

My research led to using a Boost Converter based on an inductor, transistor and 555 timer control circuit. Here is a very good primer on Boost Converters, and Flyback Converters. I will cover the power supply circuit construction in another section.

Controlling a Nixie Tube Clock

74141 Binary Decimal Decoder Pinout

Next we will need some way to direct current to the proper locations. The traditional way is to use a binary decimal decoder chip aka 74141 / 7441. These chips are original chips specifically manufactured for nixie circuits. These chips are binary to decimal decoders. They will take in a low voltage binary value usually 4 inputs (bits) plus a high voltage supply and provide power to the corresponding decimal output at the higher voltage.

Most likely I will combine a 74141 with a shift register as display control circuit for the nixie tubes, which will be fed by the Netduino. Along with the binary decoders the shift registers will allow me to conserve the number of IO pins that the project uses, and drastically reduce the circuit’s foot print and wires.

User Interface

The user interface for the project will most likely consist of 2 – 6 push buttons on the body of the clock to control mode, and be responsible for updating the time. These will feed directly into the Netduino.

Clock

Real Time Clock Chip

I will use a real time clock chip probably using I2C such as the DS1307 board from Sparkfun. This will connect to the Netduino. Also I2C is simple protocol that does not require that many wires

There are a number of other chips I could use, but this clock concept is a prototype, and the accuracy is not the primary goal, and this is provides a nice shortcut to the goal.

CPU and Programming

The cpu and board will be the Netduino. I will use the board to take in input from the clock chip translate date and time information to shift registers, which will send the information to 74141 chips, which will take the high voltage input from boost converter and power the Nixie tubes. The clock display, and time will be modified by the buttons on the outside of the clock.

The programming for this will consist of a very basic application. Ideally I would like to use the Netduino as a first prototype and possibly switch to a less expensive chipset.

Clock Body

I plan to construct the clock body out of a high quality hardwood board, and finish it. Basically it will be a box with holes drilled in it for the nixie tubes, buttons, and power cord. I will most likely add stain and ornamentation.

Next Steps

I covered the basic project outline and concept in this article. In the next article I will discuss the boost converter, and power supplies in detail.

Dec 23
by admin
0 comments

Netduino Tutorial 7: Ringtone Player (RTTTL)

Now we have covered the basics of pulse width modulation and playing a tone using our Netduino. We can use abstraction and quickly start playing melodies. In fact we can build code to parse and play Nokia Ring Tone Transfer Language. The good news is the wiring diagram is the same as the last tutorial. All we have to do is write new code, but first we have to discuss what is needed to play melodies, and ring tones.


Download the Code

https://github.com/ianlintner/Netduino-Ring-Tone-Player

Playing a melody requires two elements Pitch (Note) and Duration. Once we have those two elements we can closely mimic most single note melody. Thirdly we will need a tempo to determine how fast we play the melody.

Pitch is the frequency of the current sound being played, usually expressed by a letter and sharp or flat, e.g. C#,D, E, F#

Duration is the length of the note usually expressed as fraction of a whole note e.g. whole (1/1), half note (1/2, quarter (1/4), eight (1/8)

Tempo determines how fast we play it is commonly expressed as beats (quarter-notes) per minute: 60 bpm, 120 bpm, 130 bpm.

From the last tutorial we already know how to play a tone (SetPulse), and how long to play it (Thread.Sleep). We could just string these calls together, or we could abstract this out to play more melodies.


Code Organization

Main Program — See Below for explanation of Classes and Functionality

         public class Program
    {

        static bool IsPlay = true;
        static PWM Speaker = new PWM(Pins.GPIO_PIN_D5);
        static Song CurrentSong;
        static InterruptPort Button = new InterruptPort(Pins.ONBOARD_SW1, false, ResistorModes.Disabled, InterruptModes.InterruptEdgeBoth);
        static Queue SongQueue = new Queue();
        public static void Main()
        {
            //Set interuppt
            Button.OnInterrupt += new NativeEventHandler(ButtonPushed);

            //Looping
            while (true)
            {

                //Reload the Queue -- Not exactly efficient but it's just for fun
                if(SongQueue.Count < 1)
                {
                    SongQueue = Playlist.GetQueue();
                }

                //Check to see what stat our play variable is at based on switch press
                if (IsPlay)
                {
                    CurrentSong = (Song)SongQueue.Dequeue();
                    Play();
                    Thread.Sleep(2000);
                }
                else
                {
                    Thread.Sleep(100);
                }
            }
        }

        //Function to play notes from song class -- our work horse
        public static void Play()
        {

            //loop through each notation object in the arraylist
            foreach (Notation myNotation in CurrentSong.Notations)
            {
                if (IsPlay)
                {
                    //see earlier tutorial on playing on notes on netduino using a piezo
                    if (myNotation.Note != 0)
                    {
                        Speaker.SetPulse(myNotation.Period, myNotation.Period / 2);
                        Thread.Sleep(myNotation.SleepDuration(CurrentSong.Interval()));
                        Speaker.SetDutyCycle(0);
                        Thread.Sleep(10);

                    }
                    else
                    {
                        Speaker.SetDutyCycle(0);
                        Thread.Sleep(myNotation.SleepDuration(CurrentSong.Interval()));
                    }
                }
            }
        }

        //Changes IsPlay state on button press
        public static void ButtonPushed(uint data1, uint data2, DateTime time)
        {
            Microsoft.SPOT.Debug.Print(data2.ToString());

            if (data2 == 0)
            {
                //
            }
            else
            {
                IsPlay = !IsPlay;
            }

        }

    }


To build the code we need we are going to need some basic classes to organize our data.

  • Note Class to Store all the Note Names / Frequencies for easy access.
  • Notation Class to store a pitch, duration, and do basic calculations to convert properties into machine usable values.
  • Song Class to store a List of Notations and other song information.

Combine these elements with a basic SetPulse / Sleep loop (and a little logic) we have everything we need to play melodies.

We are not going to stop here, As I said we would parse and play RTTTL Ringtones. Which requires the addition of one more class:

  • RTTTL Class to store and parse RTTTL values.

The RTTTL Class is a pretty heavy class in relation. The parsing of the Ringtones are straightforward, but there are some pitfalls.

Here is a RTTTL string:

StWars:d=4,o=5,b=180:8f,8f,8f,2a#.,2f.6,8d#6,8d6,8c6,2a#.6,...

Our RTTTL class first will have to divide the RTTL into three parts, which are delimited by a colon (:).

  • Title: String of Song Title (StWars)
  • Song Setup: Duration, Octave, Beat (d=4,o=5,b=180)
  • Song Data: The Notes (8f,8f,8f,2a#.,2f.6,8d#6,8d6,8c6,2a#.6)
            //Code to Parse Header and Get Notes to Parsable format
            Divisions = song.Split(':');

            Name = Divisions[0];
            Header = Divisions[1].Split(',');
            Notes = Divisions[2].Split(',');

            Duration = int.Parse(Header[0].Substring(2, Header[0].Length - 2));
            Octave = int.Parse(Header[1].Substring(2, Header[1].Length - 2));
            Beat = int.Parse(Header[2].Substring(2, Header[2].Length - 2));

To view the rest of the RTTTL Parsing Code Go Here.

Here is a good place to start finding RTTTL Ringtones.
Here is a geekier site dedicated to video game ringtones ArcadeTones.

Finally we will add one more utility class:

  • Playlist a simple class to hard code songs onto the Netduino.

Nov 26
by admin
1 Comment

Netduino Tutorial 6: Piezo Speaker and PWM

In this tutorial I will demonstrate how to build a simple circuit using a Piezo Electric Speaker and create basic tones using pulse width modulation or PWM.

Building the Circuit

The parts I used for this was a 8 Ohm Piezo Speaker. A piezo electrong speaker is a very simple electrical speaker.  you can buy them at Radio Shack, but I scavanged my from a toy with a speaker, but I believe that the Audio Greeting cards also contain suitable speakers.

Then I used a 100 Ohm resistor, ideally for a speaker project you may want to get a variable resistor or potentiometer (pot) to change the resistance, thus changing the volume.

The circuit is very simple to wire on the breadboard.

Once the circuit is wired up we need to write the code.

What is Pulse Width Modulation.

The LED code was pretty basic it was just Boolean Logic. Producing basic digital audio requires a slightly more advanced knowledge of electronics. Specifically Pulse Width Modulation (PWM). The short of pulse width modulation is: we use the Netduino to alternate or modulate the voltage of the current quickly from high to low. The oscillation of the current drives the speaker at the frequency of the oscillation thus producing a specific tone. Tone’s frequencies are measured in Hertz (Hz).

E.g. Middle C: 261.626 Hz – Piano Key Frequencies

The Netduino provides a basic Pulse Width Modulation features on some of the Pins. This allows us to create a square wave, which doesn’t sound very good, but it’s just good enough.

How do I use Pulse Width Modulation with the Netduino:

static PWM speaker = new PWM(Pins.GPIO_PIN_D5);

To send the PWM signal from our Netduino to the speaker we will call the following code:

//define the Period
uint myPeriod = 1000000 / 212 ; //212 Hz is middle c
speaker.SetPulse( myPeriod , myPeriod / 2);  //Play
Thread.Sleep(1000); //1 second

The SetPulse method expects two parameters Period and Duration.

The math is described in more detail in the full code below, but basically the Period is 1 second/Frequency, and PWM is in microseconds: 1/1,000,000 sec. So:

Period = 1000000 / Frequency

For the PWM SetPulse() method we require both period, and duration. To find the duration for audio waves we divide period in half. So:

Duration = Period / 2

That should be enough to explain the bare basics of outputting sound from a Netduino to a piezoelectric speaker. Next Time I will explore playing a melody through the speaker.

Demo Video


speaker.SetPulse(myNotation.Period, myNotation.Period / 2);
Thread.Sleep(myNotation.SleepDuration(currentSong.interval()));
speaker.SetDutyCycle(0); // turn off

Writing the Program

public class Program
    {
        static PWM speaker = new PWM(Pins.GPIO_PIN_D5);

        public static void Main()
        {

            while (true)
            {
                //Period is 1/frequency
                //1/1,000,000 second : 1000000 --> 1 sec
                // Duration for Sound over PWM (Period / 2)
                uint myPeriod = 1000000 / 212; //212 Hz is middle c
                speaker.SetPulse(myPeriod, myPeriod / 2);  //Play
                Thread.Sleep(1000); //1 second

                speaker.SetPulse(0,0); // Turn Off
                Thread.Sleep(1000); //1 second
            }

        }

    }

Nov 23
by admin
3 Comments

Netduino Tutorial 5: The Traffic Lights

As I promised I was going to demonstrate building a traffic light. The previous four tutorials have built upon the knowledge needed to build a very simple device, in this case a traffic light. To complete it we need to re-use the circuit from Tutorial 4.

To create the traffic light, wire up 3 of the LED / 2N2222 transistor / 330 Ohm resistor circuits, one with a green LED, one with a Yellow LED, and one with a Red LED.

Wire the green circuit to Digital Pin0 on the Netduino. Wire the yellow circuit to Digital Pin1. Finally wire the red circuit to Digital Pin 2.


The code is very simple we just build off the last code, but instead of blinking we just switch to the next color. Like a real traffic our Netduino Traffic light will be red more often than not.

    public class Program
    {
        static OutputPort GreenLED = new OutputPort(Pins.GPIO_PIN_D0, false);
        static OutputPort YellowLED = new OutputPort(Pins.GPIO_PIN_D1, false);
        static OutputPort RedLED = new OutputPort(Pins.GPIO_PIN_D2, false);

        public static void Main()
        {
            while (true)
            {
                BlinkLED(GreenLED, 3000);
                BlinkLED(YellowLED, 1000);
                BlinkLED(RedLED, 5000);
            }

        }

        public static void BlinkLED(OutputPort LED, int duration)
        {
            LED.Write(true);
            Thread.Sleep(duration);
            LED.Write(false);
        }

    }

Nov 16
by admin
3 Comments

Netduino Tutorial Part 4: Building a Led / Resistor / Transistor Circuit

The first off the Netduino’s board task that I attempted was building an flashing led from discrete parts e.g. LED, 330 Ohm Resistor, and a 2N2222 transistor.

Technically you can build the circuit without the transistor, but with the transistor we can get a higher power level than the netduino digital pins can provide.

Above is the circuit diagram, the 2N2222 transistor allows us to use the low voltage of the digital pin on the Netduino to switch on the higher voltage side of the transistor and complete the circuit thus powering the LED.

Demo Video

The code for this is almost exactly the same as making the on-board LED blink, but instead we reference one of the digital pins. If you need more information on creating and deploying C# projects to the Netduino view the tutorials & projects on the organizations website.

  public class Program
    {
        static OutputPort LED = new OutputPort(Pins.GPIO_PIN_D0, false);
 
        public static void Main()
        {
            while (true)
            {
                BlinkLED(1000);
            }
 
        }
 
        public static void BlinkLED(int duration)
        {
            LED.Write(true);
            Thread.Sleep(duration);
 
            LED.Write(false);
            Thread.Sleep(duration);
        }
 
    }