The OLED World clock can provide day, date and time in analog and digital fashion of 25 major cities/states on an OLED display using NTP server. This is an extention of my previous project(check here) that could display IST time on OLED display. This project does not require RTC or any real time monitoring module as the NodeMCU is synchronised with the NTP servers via active internet connection.
Time calculationThe basic idea to calculate time of several geographic location is to use the UTC time as the reference time and adding the UTC offset time of location to get the current time of the location intended. For example, the offset time of India is +5:30 and if the UTC time is 13:00, then the Indian Standard Time(IST) will be 13:00 + 5:30 =18:30 or 6:30 pm. UTC offset time varies from the western hemisphere(−12:00) to the eastern hemisphere(+14:00).
The following 25 major city/states and their UTC offset time(in hrs, mins) listed below is used in the program. The list can be elaborated even more(check here).
0:["JUNEAU",-8,0],
1:["LOS ANGELES",-7,0],
2:["MEXICO CITY",-5,0],
3:["MIAMI",-4,0],
4:["SANTIAGO",-4,0],
5:["NEW YORK",-4,0],
6:["RIO",-3,0],
7:["NUUK",-2,0],
8:["ACCRA",0,0],
9:["LISBON",1,0],
10:["LONDON",1,0],
11:["PARIS",2,0],
12:["MOSCOW",3,0],
13:["DUBAI",4,0],
14:["KARACHI",5,0],
15:["NEW DELHI",5,30],
16:["COLOMBO",5,30],
17:["DHAKA",5,45],
18:["BANGKOK",7,0],
19:["BEIJING",8,0],
20:["SINGAPORE",8,0],
21:["HONGKONG",8,0],
22:["TOKYO",9,0],
23:["SYDNEY",10,0],
24:["AUCKLAND",12,0],
In order to obtain even the date and day of the city/state intended, I have used the epoch time. Epoch time is the time in seconds elapsed since 1 January 1970. Epoch time of the state/city is obtained by adding the UTC offset( in seconds) with the UTC epoch time.
ExecutionI have used Micropython to program the NodeMCU as I recently got aware of it and this made me develop my first micropython project.
I have used the uPyCrafy IDE to flash the micropython firmware and to run the libraries/programs. Check here to install uPyCraft and flash the micropython firmware to the ESP8266 module.
The libraries required are SSD1306 and GFX and these were not included as a part of the standard micropython libraries. Here is the code for SSD1306 and GFX and save it as ssd1306.py and gfx.py. Download/Run these libraries before executing the main code.
Making of analog clock display is given in my previous project.
Comments
Please log in or sign up to comment.