Friday, May 1, 2015

StarGate SG-1 Advanced Arduino Neopixel Clock

Update 2020: Code is finally finished. This project was put on back burner for years but now with the Stay-at-home Covid-19 thing, I finally had the time to complete it. The TSL2561 has been discontinued by Adafruit but it is still available from other sources. Hopefully I'll get around to order the current TSL 2591 but this module is using different code - shouldn't be difficult to integrate. Program memory has less than 300 bytes left but I can always sacrifice one of the rtttl alarm songs to free-up some more.
If someone wants to build the clock and beta test it, please contact me and I'll send you a compiled hex file. Ill open the source and release it on GitHub once I am 100% satisfied that there are no existing bugs / issues.
Parts needed for this project: Arduino Uno R3 board, 60 NeoPixel ring (4 x 1/4 arcs), ChronoDot 2.1, TSL2561 light sensor board (I2C), 3 buttons, piezo buzzer and a 270 resistor. (most parts are available from Adafruit Industries). Bredboard and jumper wires for testing are helpful.

My fascination with clocks and watches always has been pretty hard to control.
Of course, when I saw the Adafruit Neopixel 60 LED Circle this was the first and most logical thing to come through anyone's mind. I wanted to check out what other have done with the Neopixel and found the  "Stargate LED Clock" project by David Hopkins (hopo28) on GitHub. It is a really well done clock and has some very cool visual effects. The enclosure is fantastic too - exactly as the clock is named - a Stargate. While David's clock is great, I felt that it lacked some features - it is just too uncomplicated for my taste. The ATMega chip has plenty of performance overhead and more than enough memory so I decided the load the clock with as many features as I could come up with and fit in the 32K flash memory.
I started with David's code as a foundation, made a list of enhancements and started implementing the features one by one. In the process I updated the hardware configuration as well. The clock now uses ChronoDot V2.1 as RTC and Adafruit TSL2561 Digital Light Sensor. To add audio output I added a simple piezzo speaker driven with PWM. To implement a menu system and keep it simple enough to control with only 3 buttons I need to use double-click and long-press button actions. The entire de-bounce routine was replaced.
Just to list a few of the features I have added : Menu System for setting all parameters (including the RTC calendar), using color patterns feedback and only 3 buttons, Advanced Brightness Control system, 6 programmable alarm modes, SunRise Alarm, triggered by the level of the ambient light in the room, Audio Volume control with 10 levels and adjustable "Quiet Hours" mode, Westminster Quarterly Chimes and hourly beeps, 12 Alarm Songs, Full Calendar display - MM/DD/YY, Custom User-Programmable Color Set (stored in the EEPROM, requires an USB computer connection).
My development platform is an Arduino Uno board but I'll migrate the clock to one of the smaller boards.
David has done  a really good job putting together the base of the clock (Thanks so much!) and it was easy for me to understand his functions and  add all these features, even when I needed to re-organize the program flow.
 Just completed the final revision  of SG-1 V2 (I had to optimize a lot of things and move some stuff to PROGMEM - as expected first I ran out of RAM and then out of program memory (blame is on the 12 alarm songs).
Update: I noticed that the Arduino 1.8.12 IDE generates much smaller code footprint and this allowed me to add many other improvements and optimizations. I improved the menu system and also added Time Adjust mode and direct calendar setup.

The development platform / prototype: Arduino Uno board, Neopixel 60 LED Circle, ChronoDot v2.1, TSL2561 Digital Light sensor, 3 buttons, piezzo speaker and a resistor.

The Main Color Set - Time is 11:14am (22 sec)

Main Color Set - Time is 1:19pm (37 sec). The Hour color changes to indicate PM.

Custom Color Set - The color of  each element of the display can be configured independently with a serial console and a text menu, displayed by the firmware. This Color Set has 2 modes and can be configured as either Dark (display off) or Custom Colors (User-defined). 
All colors and clock parameters, including alarm times, modes, sun Rise trigger level, etc are saved in the EEPROM. ChronoDot has its own backup lithium battery so a complete power failure will not affect the clock.

Simple Mode - Hour, Minute and Second  - Time is 11:14am (33 sec)


 Calendar Mode : Date is May (orange) 1st (blue), 2015 (white) Friday (green). The day of the week color changes to red for the weekends. The inner part of clock's face helps to quickly determine the date. The hour dots are used for the month, and the date and year are displayed only in-between the dots. It is a bit awkward at first because of the 4 day increments per segment, but one can quickly get used to it. Only the next 32 years are displayed in two runs - each is 16 years, then a new clock face is needed to reflect the next 16 year segment.

 Alarm OFF (left) and Alarm (ON). Alarm for Week days only. Alarm time 7:00am.
One of the color sets displays the Alarm time and mode. If a dual mode is selected - for instance Alarm on Weekdays and Weekends. the display will alternate between the two alarm times every 10 sec.

Alarm ON on Weekdays and Weekends. Alarm Time for the Weekends is 9:55pm (a favorite TV show starts :-). Hour, Minutes and Modes are all set with  the 3 buttons.


Sun Rise Alarm Modes - triggered only once a day! It can be triggered between 4am and 9am and the actual trigger is the level of ambient light in the room when the Sun raises. The trigger level is sampled beforehand, using a menu item and it is stored in the EEPROM. 
Some  of the configurable Alarm modes left-to-right: Weekdays Time Alarm + SunRise Alarm on the Weekends, Weekends only SunRise Alarm (no weekdays alarm), Every Day SunRise Alarm

Display Brightness Selector - 59 adjustable levels (left) and Auto mode (right) when the display brightness is controlled by the Ambient Room Light Level. The brighter is in the room, the brighter the clock display will be.

Volume Control (goes to 10 only, not 11:-). Left - Hourly Chime - plays Westminster quarter chimes + Bells for each hour, Right - Hourly Beep mode - beeps on the top of each hour. This selector sets also the volume for the button clicks in menu mode. A special Night Mode (Quiet Hours) can be selected - it disables any chimes during the night time quiet hours (Default is 23:00 to 05:00 but it can be changed and saved by the Text Terminal Menu)

Calendar Set Mode. All functions, modes, times and calendar can be set using 3 buttons and the menu system (using single, double-clicks and long-press actions)
There are a functions which require computer - for example to set the Custom Colors and Mode for the Custom Color Set but everything is saved then in the EEPROM.

Part of the menu system - Yes / No selector for Calendar Setup. 


Yes / No selector for Sampling Ambient Light Level trigger threshold for the SunRise Alarm

 Every hour the clock does a random Star Gate visual effect - I didn't change anything in this part of the code - its all hopo28. The effects and animations are pretty cool!
The alarm song selection is a rather geeky (Star Wars, Indiana Jones Theme, etc), but the clock has a RTTTL Player routine so any Rtttl formated song from the web can be added - the only limit is the available PROGMEM space - currently a little over 256 bytes are left from the 32K.

The Text Menu was enhanced a bit to allow setting of the additional parameters and to provide more detailed status. I also added a separate color element for 3/6/9/12 hour dots.

Now I am working on the enclosure - thinking of something like a picture frame, but will explore other options as well. The clock face needs some improvements as well.
Toying with the idea to use the Light Sensor as sort of  a "Shift register" for the Menu. The user can simply cover with one finger the light sensor and this will change the meaning of the button functions - for instance advancing minutes with one button and when the light sensor is dark (covered), the same button decrements the minutes instead. Another feature I would like to add is an automatic DST but I doubt that ill be able to free up enough program memory for this.

12 comments:

Anonymous said...

I have, as a beginner, built the Stargate clock of David several months ago. The features you have looks great. Is there a chance you sharing the code and/or the schematic?

Keep up the good work.

with Regards,
Michel

Andrey E. Stoev said...

Hi Michel,
I will gladly share the code. Please give me a few more weeks. I am still working on a few features and also there a couple of known issues I would like to fix. The firmware became pretty elaborate and we some many features, I want to make sure no ends are untied. What is your email - once I am done Ill email you the code.

Anonymous said...

Hello Andrey,

i am from germany and very interesting in your work.
I am an owner of a cnc router and think it would look
very great if the clock would be covered from aluminium
or wood like the clock os.

I hope you can also send me the code and shematic.
What do you think, how long will you need to finish
your project?

Best regards

Christian

mail: christian@schiltkamp.info

Anonymous said...

Hi Andrey,

Sorry for the very very late reaction.
My email is masmiesatgmaildotcom.

Thanks in advance.

Michael said...

Hi, I've build the clock mentioined in hackaday.io - it seems you have extended the code / functions. Is it possible that you send me the source code?
Thanks
Michael

Unknown said...

Hi, I'm Maxim from Russia to apologize for the language
really liked your specification hours send the source code of the posta
maxst83@mail.ru
Thank you

Anonymous said...

Hy! Im Alexander from Slovenia! I've build a clock with old code so i please You if You can send me the new one!

My mail:
askodegas@gmail.com

Thank You and best regards!

Andrey E. Stoev said...

there are a couple of bugs in the clock adjustment routine when the alarm is activated that i need to fix. sorry guys but due to my work schedule i was unable to work on this for months. As soon as i get to this and fix it ill publish the code.

Unknown said...

Hy Andrey. I have just started to play with the neopixels and I'm thinking of building a clock. Can you share me your code. Even if it has bugs, it will be a good learning to try to fix them. My email is loren.bufanu@gmail.com

Unknown said...

Hy Andrey. I have just started to play with the neopixels and I'm thinking of building a clock. Can you share me your code. Even if it has bugs, it will be a good learning to try to fix them. My email is loren.bufanu@gmail.com

Anonymous said...

Multiple features in your nice RGB LED clock fascinated me. I would like to build such clock one of myself and highly appreciate if you could share me the schematic and sketch/code to my email "vr_xlent@hotmail.com"

JWhitten said...

Hello,

This is a really slick project! I love it. Any chance of you posting the code and template for the faceplate? Even if they aren't finished, you'd be making a lot of people really happy!!!

Thanks and terrific work!

John