Tuesday, February 28, 2012

Project Update: Nixie Clock part 3.1

Hey guys, I have a update for the WIFI Nixie Clock code.  Over the last few weeks I've had a chance to debug a little bit of the code.  Basically what was happening is that at midnight when I had set it up to reset the connection, it would never update the netTime variable and would keep rebooting.  It would do this till a reconnect counter triggered after the fifth attempt and it would send a reboot command and the whole clock would reboot. After that it would work as intended but it was annoying and took almost five minutes.  The fix for this was very simple.

So here's what I changed:

First, in the reconnect function, I changed how many times the system would reconnect to the wifi from five to seven.  This way every week the clock would perform a full reboot.  Its up to you how you want to handle that.  The section of code looks like this:

// reboot if not working right yet.
  iTrack++;
  if ( iTrack > 7 ) {
    WiFly.reboot();
    iTrack = 0;
  }

Next, here's the loop function with the easy fix and something I really should have done the first time.  Just set the netTime variable again after the reconnect function finishes.   Also, because I want to keep it from reconnecting again, I extended the delay to 30 seconds.  30 seconds is a very long time and really I'm being overly cautious.  Adjust it to whatever you like.  Personally, the reconnect function takes 30-40 seconds to connect to my wifi router so another 30 seconds before polling the wifi module keeps it from running the reconnect function again, for me.    Anyway, the loop function should should look like this now:

void loop()
{
  if (netTime==0)  // if the netTime var is equal to 0, which should be midnight, then resync the time
  {
    Serial << "Reconnect netTime = " << netTime << endl;  // debug output
    backlightColor();  // The Colors!!!      
    Reconnect();  // Reconnect to the wifi AP and query the NTP server for the time.  
    delay(30000);  // I run a long delay to keep it from running  from querying the NTP server too offten.  No reason to abuse a free service.
    netTime=((hour()-5)*100)+minute();  //set the netTime after running the Reconnect. 
  }
  else  
  {
    Serial << "netTime = " << netTime << endl;  // debug output
    getNetTime();     // run GMT to local Time Zone conversion
    backlightColor();   // The Colors!!!
    nixNum(netTime);  // send data to the nixie clock.  int array nixNum with int data from gmt converstion.
    delay(100);  // Short delay for the backlight
  }
}

Here's a link to the updated code.  Remember to set your wifi settings and a NTP server.  




2 comments:

  1. Cool Project! I'm building the same and wondered if you had any idea on how to modify the code to include the "seconds" with 2 extra tubes?

    ReplyDelete
  2. Ohh yea, that's real simple. The seconds are already in the code we so all we need to do is modify the equation and update the Nixie tube setup to allow for six characters in the array instead of four.

    For the equation, we just need to move the Hour and Minute digits up and add the seconds. So we take the original equation:

    x = (hour() * 100) + minute()

    And move the hour and minutes up to the make room for the seconds:

    x = (hour() * 10000) + (minute() * 100) + second()

    So now if its 3:40:30pm, x should be 154030.

    Make sure you update all the other equations in the code to reflect this change.
    I hope this helps

    I've also recently updated my code again to reflect changes in the WiflySerial library as well as getting the code working on version 1.0 of the Arduino software. And I've added a little flair for when the clock starts up or needs to reconnect to the wifi. I'll be posting that later this weekend.

    ReplyDelete