Thursday, January 31, 2019

TFT LCD Clock

The market seems to be flooded lately with the versatile TFT (thin film transistor) LCD color displays so I thought it was time to put one to use in a new project.  I needed (wanted) an accurate digital display for my ham shack that could show time in two formats: 12-hr (eastern) and 24-hr (UTC).  I chose a 2.8" screen (320 x 240  pixels) with touch capability that could directly connect to an Arduino Uno w/o a shield interface.  These are dirt cheap if purchased from China (~$11.00 including shipping).  I also decided to use an RTC (real time clock) that could be programmed with the current time and date w/o having to perform any calculations.  Adafruit has an RTC module available based upon the Maxim DS3231 chip which is not only highly accurate (+-2ppm) but also capable of automatically adjusting for leap years up to the year 2100.  As a bonus, it also offers a battery backup feature so that reprogramming only needs to be done every 4-5 years or so.

The items were ordered and then I used public domain software from Github, Adafruit and others for controlling the various hardware interfaces.  I designed and  wrote the specific code for controlling the visual display elements and user interface.  The biggest challenge was selecting fonts that would "fit" into the memory space of the Uno (32kB).  I wanted a large font (55pt) for the main time display but it consumed over 5kB of memory just for the "0-9" and ":" characters alone.

Another software issue concerned the support of the different time formats (along with the additional memory demands).  I wanted to include UTC format because its commonly used in amateur radio communications when logging a QSO.  Since the eastern time zone (where I live) is 5 hours behind UTC time, every time I switched between the two time formats there would be a difference in not only the displayed hour but also potentially the day and month (actually the year could be different as well).  When eastern time format was selected, I would need to contend with another problem: daylight savings time.  Instead of scratch writing something that might or might not work (might not was the more likely outcome), I decided to search for public domain code that might address these issues.  Surely others have had these same concerns at some point?  Sure enough I eventually found a "timezone" library that handled the time differential in UTC mode and automatically adjusted the time twice a year when switching between regular and daylight savings time  (thanks to Github/JChristensen).  I simply extracted the appropriate code sections and pasted them into my code.  After a bit of tweaking everything worked as it should.

After struggling with the memory issue for a bit I finally decided to use a platform with greater memory...the Arduino Mega 2560 (256kB).  I purchased a cheap clone from China for ~$16.00 (regular price $38.00) and got started on code development.  I finally came up with what looked to me like an overall nice layout, color scheme and font selections as seen in the image below:


An added touch (pun intended) is the touch screen feature that allows me to press the screen to select between UTC and eastern time.