Digital Clock with Wio Terminal
|Wio terminal is a smart development platform based on ATSAMD51 controller. It has a nice 320×240 LCD screen along with WiFi support provided by RTL8720DN wireless chip. In this post we will how to develop a simple digital clock.
ATSAMD51 has a feature rich 32-bit RTC (Real Time Counter), we can’t exclusively depend on the RTC as wio terminal is not equipped with backup battery. So every time there is power cycle, we need to set the time. To avoid this we can use the NTP (Network Time protocol) service by leveraging the wio terminal WiFi capabilities. Every time (or periodically) there is power cycle, we can get time from NTP server and configure the controller RTC with accurate time. For ESP32 based 7-Segment digital clock checkout this post.
Setup and Requirements
- Wio terminal and Arduino IDE, follow this guide to setup arduino ide for programming Wio terminal and update RTL8720 firmware.
- Working WiFi Connection.
- Install following libraries using Arduino Library manage
- Seed Arduino rpcWiFi
- Seeed Arduino RTC
Solution Approach
On startup Wio will try to connect to WiFi and fetch time from NTP server. Wio will wait until WiFi connection becomes available. Once NTP response is available, Wio will keep updating the screen every minute. RTC will also be refreshed with value from NTP every T minutes.
I also used custom font called space mono, please follow this guide if you want to use different custom font. We need convert the TrueType font file into a Adafruit GFX h file format.
Code upload and testing
Full Arduino project is available here. Download the folder and open it in arduino. The time zone is set to IST, if you are living in a different timezone then you need to update the tzOffset appropriately.
long tzOffset = 19800UL; // set your timezone offset in seconds
You also need to update WiFi name and password. Then you can upload the code and time should appear on the screen immediately.
const char* ssid = "***";
const char* password = "***";
DateTime doesn’t have methods to get the month and day in text, so I defined arrays to hold days and months, then used dayOfTheWeek and month methods to show current day and month in text format. The dayOfTheWeek of method returns 0-6 (Sunday-Saturday), so we can use the return value as index of the days array. But the month method returns 1-12, so we have reduce by 1 to use the return value as index. The source file for DateTime is available here.
sprintf(printBuffer, "%s %02d %s",days[currentTime.dayOfTheWeek()], currentTime.day(), months[currentTime.month()-1]);
Every time the screen updates, there is noticeable flicker as we are updating the entire screen instead of updating the part of screen that changed. Seems the flicker can’t avoided if we are using custom fonts, It might be possible to avoid the flicker with default fonts (1-8).