Flora NeoPixel Ring Clock

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
iguanaman
 
Posts: 73
Joined: Sat Mar 19, 2016 4:48 pm

Re: Flora NeoPixel Ring Clock

Post by iguanaman »

Instead of moving the starting LED I changed the offset. Mine was -5 for central and I had to change it to 21 (!) in order to get the correct time.
That was last night. This morning the time is still correct.

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

Mine has kept the correct time so far. I left it running all night and when I woke up it looked like the display had frozen. The millisecond LEDs were not circling the display, but It looked as if the time was correct. I shut it off, then turned it back on and the GPS got a fix pretty quick and the animations were working like normal. Time of day was also correct. Lastly, I checked the serial monitor and it was showing the correct time in 24hr format. I hope that this is all.

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

Iguanaman, I found something else not correct in the code. The number of pixels on each ring is incorrect. You probably saw that already, but I did not. Here is the way it is written:
//Your NeoPixel rings may not line up with ours, or each other. |
//Enter which NeoPixel leds are on top LED (0-23 and 0-13). |
#define outerTOP_LED 0
#define innerTOP_LED 0

The way it should be is:
//Your NeoPixel rings may not line up with ours, or each other. |
//Enter which NeoPixel leds are on top LED (0-23 and 0-11). |
#define outerTOP_LED 0
#define innerTOP_LED 0

I didn't realize before that the numbers would be incorrect because the inner ring is only 12 pixels, but a range of 0 to 13 is actually 14 pixels. So it should be 0 to 11 which would make 12 pixels. Hmmm! That might explain why I get a weird display on the numbers every so often, particularly at the top of the hour and at Noon and Mid-Night!
I changed that in the code and uploaded it without any trouble. I'll try to keep an eye on the clock to see what happens throughout the day.

By the way, I'm sure your using the Arduino IDE, but it keeps giving me fits, (I'm using a Mac desktop). I try to use CodeBender as often as I can, (if the boards are supported), and I have very few problems at all with that. What about you?

User avatar
iguanaman
 
Posts: 73
Joined: Sat Mar 19, 2016 4:48 pm

Re: Flora NeoPixel Ring Clock

Post by iguanaman »

The total number of LEDS (36) would be correct. Adafruit_NeoPixel strip = Adafruit_NeoPixel(36, PIN, NEO_GRB + NEO_KHZ800);
The line that shows 0-13 is a typo and a comment line and would not affect the execution of the code.
Yes I am using the Arduino IDE in Windows.

User avatar
iguanaman
 
Posts: 73
Joined: Sat Mar 19, 2016 4:48 pm

Re: Flora NeoPixel Ring Clock

Post by iguanaman »

I began looking at the hour result and noticed that after 7pm (central time) the hour was jumping to 11. I checked the satellite results and they looked normal. The issue was the code was not dealing with the hour once it went to zero (GMT) It was simply subtracting the hour by the offset which was a negative number. Anyway try this version out and see if it works okay on your clock.

Code: Select all

//NeoPixel clock with FLORA based on Kevin Alford's NeoPixel ring clock face
    //https://github.com/zeroeth/time_loop
    //http://www.youtube.com/watch?v=b-mROp-ZKuk
    //modified by Becky Stern for Adafruit Industries
    //further modified by Jon Simonds (basically just cleaned up some unneeded variables and took a little 
    //           from here and there in the Adafruit example code, and have a functioning GPS NeoPixel clock. <GRIN> )
    //
    //another modification by Patrick Dugan 7/20/2016.   The code was not correctly handling the hour assignment once the 
    //  GPS hour was past 23 (0) I added code to add 12 to the hour if the hour was less than 12.  Since the clock is not displaying
    //  AM/PM difference it should still look correct.  I also took the liberty of making the second hand amber rather than purple because
    //  it seemed too close to the millisecond color.
    
    #include <Adafruit_GPS.h>
    #include <Adafruit_NeoPixel.h>
    #include <SoftwareSerial.h>
    #include <Time.h>
    
    Adafruit_GPS GPS(&Serial1);
    
    #define PIN 12
    
    // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
    // Set to 'true' if you want to debug and listen to the raw GPS sentences
    #define GPSECHO false
         
    // this keeps track of whether we're using the interrupt
    // off by default!
    boolean usingInterrupt = false;
    
    // From adaFruit NEOPIXEL goggles example: Gamma correction improves appearance of midrange colors
    const uint8_t gamma[] = {
          0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
          0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,
          1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,
          3,  3,  4,  4,  4,  4,  5,  5,  5,  5,  5,  6,  6,  6,  6,  7,
          7,  7,  8,  8,  8,  9,  9,  9, 10, 10, 10, 11, 11, 11, 12, 12,
         13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20,
         20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29,
         30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42,
         42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
         58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 75,
         76, 77, 78, 80, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96,
         97, 99,100,102,103,105,106,108,109,111,112,114,115,117,119,120,
        122,124,125,127,129,130,132,134,136,137,139,141,143,145,146,148,
        150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,
        182,184,186,188,191,193,195,197,199,202,204,206,209,211,213,215,
        218,220,223,225,227,230,232,235,237,240,242,245,247,250,252,255
    };
    
    // Parameter 1 = number of pixels in strip
    // Parameter 2 = pin number (most are valid)
    // Parameter 3 = pixel type flags, add together as needed:
    //   NEO_RGB     Pixels are wired for RGB bitstream
    //   NEO_GRB     Pixels are wired for GRB bitstream
    //   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
    //   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(36, PIN, NEO_GRB + NEO_KHZ800);
    
    //--------------------------------------------------|
    //Your NeoPixel rings may not line up with ours, or each other.     |
    //Enter which NeoPixel leds are on top LED (0-23 and 0-11).  |
      #define outerTOP_LED                8
      #define innerTOP_LED                4
    //--------------------------------------------------|
    
    int outertopLED = outerTOP_LED;
    int innertopLED = innerTOP_LED;
    
    //tequila sunrise color scheme
    //uint32_t milli_color  = strip.Color ( 44,  21,  0); // redest orange
    //uint32_t second_color = strip.Color (  44,  30, 0); //slightly yellower
    //uint32_t hour_color   = strip.Color (  44, 42,  0); //yellow
    //uint32_t minute_color = strip.Color ( 43, 0, 5); //red
    //uint32_t off_color    = strip.Color (  0,  0,  0);
    
    
    ///blue, green, & purple color scheme
    uint32_t milli_color  = strip.Color ( 24,  0,  24); // magenta
    uint32_t second_color = strip.Color (  60,  10, 0); // purple
    uint32_t hour_color   = strip.Color (  43, 0,  5); // RED for initial no GPS fix
    uint32_t minute_color = strip.Color ( 0, 44, 10); // green
    uint32_t off_color    = strip.Color (  0,  0,  0);
    
    // Offset hours from gps time (UTC)
    //const int offset = 1;   // Central European Time
    
    
    //const int offset = -4;  // Eastern Daylight Time (USA)
    const int offset = -5;  // Central Daylight Time (USA)
    //const int offset = -6;  // Central Standard Time (USA)
    //const int offset = -8;  // Pacific Standard Time (USA)
    //const int offset = -7;  // Pacific Daylight Time (USA)
    
    /* CLOCK */
    class ClockPositions
    {
     public:
     
      uint32_t milli;
      uint32_t currentsecond;
      uint32_t currentminute;
      uint32_t currenthour;
    
    
      ClockPositions ();
      void update    ();
    };
    
    
    ClockPositions::ClockPositions()
    {
      milli         = 0;
      currentsecond = 0;
      currentminute = 0;
      currenthour   = 0;
      //DateTime(__DATE__, __TIME__);
      
    }
    
    
    void ClockPositions::update()
    {
      milli  = map ((millis() %  1000), 0,  1000, 0, 24);
      
      currentsecond = outertopLED + map ((second() % 60), 0, 60, 0, 23);
      if (currentsecond > 24) {currentsecond = currentsecond-24;};
      
      currenthour   = innertopLED + map ((hour() % 12), 0,  12, 24, 35);
      if (currenthour > 35) { currenthour = currenthour-12;}
      
      currentminute = outertopLED + map (minute() % 60, 0,  60, 0, 23);
      if (currentminute > 23) {currentminute = currentminute-24;};
    }
    
    
    
    /* CLOCK VIEW */
    
    class ClockSegments
    {
     public:
      ClockPositions    &positions;
      Adafruit_NeoPixel &strip;
    
      ClockSegments (Adafruit_NeoPixel&, ClockPositions&);
      void draw  ();
      void clear ();
      void add_color (uint8_t position, uint32_t color);
      uint32_t blend (uint32_t color1, uint32_t color2);
    };
    
    
    ClockSegments::ClockSegments (Adafruit_NeoPixel& n_strip, ClockPositions& n_positions): strip (n_strip), positions (n_positions)
    {
    }
    
    
    void ClockSegments::draw()
    {
      clear();
    
      add_color (positions.currentminute,  minute_color);
      add_color (positions.currenthour,  hour_color  );
      
    
      add_color (positions.currentsecond     % 24, second_color);
      add_color ((positions.currentsecond+1) % 24, second_color);
      //add_color ((positions.second+2) % 24, second_color);
    
    
      add_color (positions.milli     % 24,  milli_color);
      add_color ((positions.milli+1) % 24,  milli_color);
      add_color ((positions.milli+2) % 24,  milli_color);
    
      strip.show ();
    }
    
    
    void ClockSegments::add_color (uint8_t position, uint32_t color)
    {
      uint32_t blended_color = blend (strip.getPixelColor (position), color);
    
      /* Gamma mapping */
      uint8_t r,b,g;
    
      r = (uint8_t)(blended_color >> 16),
      g = (uint8_t)(blended_color >>  8),
      b = (uint8_t)(blended_color >>  0);
    
      strip.setPixelColor (position, blended_color);
    }
    
    
    uint32_t ClockSegments::blend (uint32_t color1, uint32_t color2)
    {
      uint8_t r1,g1,b1;
      uint8_t r2,g2,b2;
      uint8_t r3,g3,b3;
    
      r1 = (uint8_t)(color1 >> 16),
      g1 = (uint8_t)(color1 >>  8),
      b1 = (uint8_t)(color1 >>  0);
    
      r2 = (uint8_t)(color2 >> 16),
      g2 = (uint8_t)(color2 >>  8),
      b2 = (uint8_t)(color2 >>  0);
    
    
      return strip.Color (constrain (r1+r2, 0, 255), constrain (g1+g2, 0, 255), constrain (b1+b2, 0, 255));
    }
    
    
    void ClockSegments::clear ()
    {
      for(uint16_t i=0; i<strip.numPixels (); i++) {
          strip.setPixelColor (i, off_color);
      }
    }
    
    
    /* APP */
    ClockPositions positions;
    ClockSegments  segments(strip, positions);
    
    void setup ()
    {
       // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
      // also spit it out
      Serial.begin(115200);
      //Serial.println("Adafruit GPS library basic test!");
    
      // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
      GPS.begin(9600);
      
      // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
      GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
      // uncomment this line to turn on only the "minimum recommended" data
      //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
      // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
      // the parser doesn't care about other sentences at this time
      
      // Set the update rate
      GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
      // For the parsing code to work nicely and have time to sort thru the data, and
      // print it out we don't suggest using anything higher than 1 Hz
    
      // Request updates on antenna status, comment out to keep quiet
      GPS.sendCommand(PGCMD_ANTENNA);
    
      useInterrupt(true);
    
      delay(1000);
      // Ask for firmware version
      Serial1.println(PMTK_Q_RELEASE);
      
      // Request updates on antenna status, comment out to keep quiet
      // GPS.sendCommand(PGCMD_ANTENNA);
        
      strip.begin ();
      strip.show (); // Initialize all pixels to 'off'
    }
    
    uint32_t gpsTimer = millis();
    
    void loop ()
    {
      // if millis() or timer wraps around, we'll just reset it
      if (gpsTimer > millis()) gpsTimer = millis();
          
      // approximately every 60 seconds or so, update time
      //if ((millis() - gpsTimer > 60000 * 5)) {
      if ((millis() - gpsTimer > 10000)) {
        gpsTimer = millis(); // reset the timer
        
    //    Serial.print("GPS Fix: ");
    //    Serial.print((int)GPS.fix);
    //    Serial.print("  Quality: ");
    //    Serial.print((int)GPS.fixquality);
    //    Serial.print("  Satellites: ");
    //    Serial.println((int)GPS.satellites);
        if (GPS.fix) {
          // set the Time to the latest GPS reading
          if (GPS.hour < 24) {      
              if (GPS.hour < 12) {
                  setTime(GPS.hour+12+offset, GPS.minute, GPS.seconds, GPS.day, GPS.month, GPS.year);            
              } else {
                  setTime(GPS.hour+offset, GPS.minute, GPS.seconds, GPS.day, GPS.month, GPS.year);            
              }
            //adjustTime(offset * SECS_PER_HOUR);
    //        Serial.print("\nTime: ");
    //        Serial.print(hour(), DEC); Serial.print(':');
    //        Serial.print(minute(), DEC); Serial.print(':');
    //        Serial.println(second(), DEC);
            //
            // Set colors for Hours,Minutes,Secs,Milli if we have a GPS fix
            //
            // milli_color  = strip.Color ( 24,  0,  24); // magenta
            // second_color = strip.Color (  17,  0, 44); // purple
            hour_color   = strip.Color (  0, 10,  44); // royal blue
            // minute_color = strip.Color ( 0, 44, 10); // green
          }
        } else {
          //
          // Set colors for Hours,Minutes,Secs,Milli if we DO NOT have a GPS fix
          //
          // milli_color  = strip.Color ( 24,  0,  24); // magenta
          // second_color = strip.Color (  17,  0, 44); // purple
          hour_color   = strip.Color (  43, 0,  5); // royal blue
          // minute_color = strip.Color ( 0, 44, 10); // green
        }
    
        
      }
    
      positions.update ();
      segments.draw ();
     
    }
    
    /******************************************************************/
    // Interrupt is called once a millisecond, looks for any new GPS data, and stores it
    SIGNAL(TIMER0_COMPA_vect) {
      char c = GPS.read();
      // if you want to debug, this is a good time to do it!
      if (GPSECHO)
        if (c) Serial.print(c);
      if (GPS.newNMEAreceived()) {
        //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false
      
        if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
          return;  // we can fail to parse a sentence in which case we should just wait for another
      }
    }
    
    void useInterrupt(boolean v) {
      if (v) {
        // Timer0 is already used for millis() - we'll just interrupt somewhere
        // in the middle and call the "Compare A" function above
        OCR0A = 0xAF;
        TIMSK0 |= _BV(OCIE0A);
        usingInterrupt = true;
      } else {
        // do not call the interrupt function COMPA anymore
        TIMSK0 &= ~_BV(OCIE0A);
        usingInterrupt = false;
      }
    }
    
    // Fill the dots one after the other with a color
    void colorWipe(uint32_t c, uint32_t wait) {
      for(uint16_t i=0; i<strip.numPixels(); i++) {
          strip.setPixelColor(i, c);
          strip.show();
          delay(wait);
      }
    }

User avatar
iguanaman
 
Posts: 73
Joined: Sat Mar 19, 2016 4:48 pm

Re: Flora NeoPixel Ring Clock

Post by iguanaman »

One more correction around line 128:

Code: Select all

currenthour   = innertopLED + map ((hour() % 12), 0,  12, 24, 35);
      if (hour() == 12) {
        currenthour = currenthour - 1;
      }
The map command was not correctly getting the currenthour if 12 so I wrote a "kludge" to correct that.

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

Yeah thanks! I'll have to try that. I had about given up on the thing and take it apart to use the Flora in another project.
I too noticed that at 8PM, (eastern time), that the clock would jump to 12:00.
Have you noticed as well that whenever 12:00 does come the pixel at "12:00" doesn't light up but the "1:00" one will light up and stay on until 2:00? Additionally the minute indicator jumps from :59 minutes to :01?

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

What I see is that the time will show 11:59 and when it turns to 12:00 the NeoPixels will look like they're showing 1:01, but the serial monitor will show that it's tracking the time as 12:01. Then the minutes will go through to 1:59, (really 12:59), then display 1:01, (and the serial monitor showing the time is 1:01.
This happens regardless of whether it is AM or PM.

User avatar
iguanaman
 
Posts: 73
Joined: Sat Mar 19, 2016 4:48 pm

Re: Flora NeoPixel Ring Clock

Post by iguanaman »

Spetznatz1 wrote:What I see is that the time will show 11:59 and when it turns to 12:00 the NeoPixels will look like they're showing 1:01, but the serial monitor will show that it's tracking the time as 12:01. Then the minutes will go through to 1:59, (really 12:59), then display 1:01, (and the serial monitor showing the time is 1:01.
This happens regardless of whether it is AM or PM.
Does that include the small update I made? (updating around line 128)

User avatar
iguanaman
 
Posts: 73
Joined: Sat Mar 19, 2016 4:48 pm

Re: Flora NeoPixel Ring Clock

Post by iguanaman »

RingClock7.zip
(4.38 KiB) Downloaded 59 times
Here is a zip of the latest with the 12 o'clock adjustment

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

I don't believe so, I am going to try to update the code loaded on the Flora tonight.

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

Hey Iguanaman, so far it looks pretty good. You should really make the tech support at Adafruit aware so they can adjust their project page for this clock. Thanks so much for your hard work.
On a side note, what course could you recommend I take to learn how to do this coding myself? I am about set to buy the arduino starter kit, that teaches the basics. I can understand a few things in the coding, but not enough.
Thanks Much!

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

Oh, and I love the new colors. They definitely stand out from one another!

User avatar
iguanaman
 
Posts: 73
Joined: Sat Mar 19, 2016 4:48 pm

Re: Flora NeoPixel Ring Clock

Post by iguanaman »

Spetznatz1 wrote:Hey Iguanaman, so far it looks pretty good. You should really make the tech support at Adafruit aware so they can adjust their project page for this clock. Thanks so much for your hard work.
On a side note, what course could you recommend I take to learn how to do this coding myself? I am about set to buy the arduino starter kit, that teaches the basics. I can understand a few things in the coding, but not enough.
Thanks Much!
I did notify Adafruit about the issue and provided them with the link to this post so they could review the latest revision. As far as learning to code I bought the starter kit and went through all the tutorials to learn how to do things. I have been programming in other languages for a long time (just not C++ which Arduino IDE code basically is) so it wasn't difficult to pick up for me. If you do any Google searches on "how to program/code XYZ in Arduino" you should find a lot of examples but the starter kit is a great way to begin.

User avatar
Spetznatz1
 
Posts: 31
Joined: Sun Nov 08, 2015 9:31 pm

Re: Flora NeoPixel Ring Clock

Post by Spetznatz1 »

I am still seeing an issue with the "minute" indicator. Mine goes from showing a :57-:59 to :01-03. The minute indicator doesn't stop over the "12 O'Clock position", it just skips over the top indicator. Have you seen this problem? I used your last code in the zip file.

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”