{"id":11615,"date":"2016-08-02T21:56:14","date_gmt":"2016-08-03T01:56:14","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=11615"},"modified":"2016-10-01T21:53:22","modified_gmt":"2016-10-02T01:53:22","slug":"making-a-simple-esp8266-internet-clock","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/making-a-simple-esp8266-internet-clock\/","title":{"rendered":"Making a simple ESP8266-based clock synchronized to NIST server"},"content":{"rendered":"<p>Internet has made it quite easy for computers to synchronize their clocks to an accurate clock value generated by a remote server. In the United States, the National Institute of Standards and Technology (NIST) provides official time. NIST disseminates the time using several methods, which include broadcasting over short-wave and long-wave radio, telephone dial-in services (ACTS), and Network Time Service (NTS) over the internet. This article describes a ESP8266-based clock project that utilizes NIST\u2019s NTS service to retrieve accurate time information and display it on a 4-digit seven segment LED display. The time is synchronized to the NIST server after every 2-minute interval. The display also contains a colon that blinks every second.<\/p>\n<div id=\"attachment_11623\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/AMop1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-11623\" class=\"wp-image-11623 size-medium\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/AMop1-580x387.jpg\" alt=\"AMop1\" width=\"580\" height=\"387\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/AMop1-580x387.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/AMop1.jpg 800w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-11623\" class=\"wp-caption-text\">ESP8266 seven segment LED clock<\/p><\/div>\n<h6><!--more--><\/h6>\n<h6>Things you will need<\/h6>\n<p>This project uses ESP-01 module to connect to the NIST time server through your local home\/office WiFi and display time on a serially-driven seven segment LED display. The WiFi network name (SSID) and password are hard-coded into the firmware\u00a0that is loaded into the ESP-01 module. The firmware for this program\u00a0is developed using\u00a0the Arduino IDE. The following hardware items are required to build this ESP8266-driven internet-connected seven segment LED clock.<\/p>\n<p>1. ESP-01 module<\/p>\n<p>2. <strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/esp8266-breadboard-adapter\/\" target=\"_blank\">ESP-01 breadboard adapter<\/a><\/strong><\/p>\n<p>3. <strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/spi-4-digit-seven-segment-led-display\/\" target=\"_blank\">Serial 7-segment LED display<\/a><\/strong><\/p>\n<p>4. <strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/general-purpose-50v-and-33v-fixed-power-supply\/\" target=\"_blank\">5V\/3.3V regulated power supply board<\/a><\/strong><\/p>\n<p>5. USB-UART module to program ESP-01<\/p>\n<p>6. 1K resistor, breadboard and wires<\/p>\n<div id=\"attachment_11657\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/08\/BOM.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-11657\" class=\"size-medium wp-image-11657\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/08\/BOM-580x337.jpg\" alt=\"Things you will need\" width=\"580\" height=\"337\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/08\/BOM-580x337.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/08\/BOM.jpg 800w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-11657\" class=\"wp-caption-text\">Things you will need<\/p><\/div>\n<p>ESP-01 module is not breadboard friendly, so you will need an external adapter to use it on a breadboard circuit. You can either make one by yourself or <strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/esp8266-breadboard-adapter\/\" target=\"_blank\">buy a ready-made<\/a><\/strong> from our <strong><a href=\"https:\/\/www.tindie.com\/stores\/rajbex\/\" target=\"_blank\">Tindie store<\/a><\/strong>.<\/p>\n<p>The <strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/spi-4-digit-seven-segment-led-display\/\" target=\"_blank\">seven segment display<\/a><\/strong> used in this project is MAX7219-powered and can be bought from our <strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/spi-4-digit-seven-segment-led-display\/\" target=\"_blank\">Tindie store<\/a><\/strong>. It has a high-quality 4-digit display (Yellow) with a colon and decimal digits. Check out the <strong><a href=\"http:\/\/embedded-lab.com\/blog\/new-version-of-max7219-based-4-digit-serial-seven-segment-led-display\/\" target=\"_blank\">documentation page<\/a><\/strong> for more details on the connections and wiring details of this product.<\/p>\n<p>The ESP-01 module draws ~300 mA of current during WiFi operation. Therefore, you will need a regulated 3.3V (rated 500mA or higher) power supply\u00a0to power the ESP-01 module. Also, the seven segment display module will require a regulated 5V power supply. I am using our <strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/general-purpose-50v-and-33v-fixed-power-supply\/\">Dual (5V\/3.3V)\u00a0Regulated Power Supply<\/a><\/strong> board for this project. This power supply provides 5V and 3.3V outputs with 500mA capacity for each.<\/p>\n<p>The connections between the ESP-01 module and the LED display are shown below. The MAX7219-based seven segment LED display requires 3 I\/O pins to drive all the segments. The GPIO2 and GPIO0 I\/O pins of ESP-01\u00a0are used to drive Data (DIN) and Clock (CLK) pins of MAX7219. The LOAD pin of MAX7219 is driven by the TX pin of ESP-01. The TX pin is actually GPIO1 and can also be used as I\/O pin. Note that you cannot use Serial print statements while writing the firmware for this project after using the Tx pin as a I\/O pin. You can also consider using a 3.3V-to-5V level shifter in between the MAX7219 and ESP-01 modules, but it has worked perfectly fine without it, as long as you power the MAX7219 with 5V.<\/p>\n<div id=\"attachment_11634\" style=\"width: 557px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/Circuit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-11634\" class=\"size-full wp-image-11634\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/Circuit.jpg\" alt=\"Circuit \" width=\"547\" height=\"378\" \/><\/a><p id=\"caption-attachment-11634\" class=\"wp-caption-text\">Circuit diagram for ESP8266-based clock<\/p><\/div>\n<p>The above circuit diagram does not show connections between the ESP-01 and USB-UART modules for\u00a0programming the ESP-01. You can google &#8220;how to program esp-01&#8221; to find information on programming\u00a0a\u00a0ESP-01 module using an USB-UART\u00a0module. Few articles that describe this process are listed below:<\/p>\n<p><a href=\"http:\/\/www.allaboutcircuits.com\/projects\/breadboard-and-program-an-esp-01-circuit-with-the-arduino-ide\/\">http:\/\/www.allaboutcircuits.com\/projects\/breadboard-and-program-an-esp-01-circuit-with-the-arduino-ide\/<\/a><\/p>\n<p><a href=\"http:\/\/www.esp8266.com\/wiki\/doku.php?id=getting-started-with-the-esp8266\">http:\/\/www.esp8266.com\/wiki\/doku.php?id=getting-started-with-the-esp8266<\/a><\/p>\n<p><a href=\"https:\/\/www.hackster.io\/glowascii\/esp8266-programming-jig-5afd03\">https:\/\/www.hackster.io\/glowascii\/esp8266-programming-jig-5afd03<\/a><\/p>\n<p>Note that you need to disconnect the\u00a0ESP-01 module from the above circuit to upload the clock firmware (provided later in this article) as the TX and GPIO0 pins will be required during programming.<\/p>\n<p>The following figure shows the actual setup of the clock circuit on a breadboard after the firmware has been uploaded to the ESP-01 module.<\/p>\n<div id=\"attachment_11627\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/setup1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-11627\" class=\"wp-image-11627 size-medium\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/setup1-580x491.jpg\" alt=\"setup1\" width=\"580\" height=\"491\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/setup1-580x491.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/setup1.jpg 800w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-11627\" class=\"wp-caption-text\">ESP8266-based clock circuit setup on breadboard<\/p><\/div>\n<h6>Firmware<\/h6>\n<p>With the availability of <strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\" target=\"_blank\">Arduino core for ESP8266<\/a><\/strong>, it&#8217;s been possible to develop programs for ESP8266 using the popular\u00a0Arduino IDE. It allows us to use most of the familiar\u00a0Arduino functions and libraries, and run them directly on ESP8266. If you haven&#8217;t setup your Arduino IDE to support\u00a0ESP8266, you can find the information to do that <strong><a href=\"https:\/\/github.com\/esp8266\/Arduino\" target=\"_blank\">here<\/a><\/strong>.<\/p>\n<p>You can find several examples online on the implementation of Network Time Protocol (NTP) in Arduino to fetch time from NIST server. NIST operates several time servers for its Internet Time Service (ITS). The list of these\u00a0time servers and their IP addresses can be found <strong><a href=\"http:\/\/tf.nist.gov\/tf-cgi\/servers.cgi\" target=\"_blank\">here<\/a><\/strong>. Note that NIST does not allow\u00a0queries to any of their servers more frequently than once every 4 seconds. In this project, the queries are made once every two minutes. In between the queries, which is a 2-minute interval, the time is\u00a0kept running locally using the <strong>delay()<\/strong> routine. You can download the ESP-01 Firmware for this project from the following link.<\/p>\n<p><strong><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/08\/Project_InternetClock_ESP01.zip\">Download Code for ESP8266 InternetClock_ESP01<\/a><\/strong><\/p>\n<p><em><strong>Important notes:<\/strong><\/em><\/p>\n<ul>\n<li>The time-fetching code was derived from\u00a0<strong>Kev_MacD<\/strong>&#8216;s instructables on <a href=\"http:\/\/www.instructables.com\/id\/Steampunk-ESP8622-Internet-connected-Clock-using-t\/\" target=\"_blank\">Steampunk ESP8266 Internet connected Clock<\/a>.<\/li>\n<li>In the code, you need to change the network SSID and password to match to your network.<\/li>\n<li>In addition, you also need to adjust the GMT offset for your location to get the correct local time. For example, the GMT offset for EST is -4 (<em>int hours_Offset_From_GMT = -4;<\/em>).<\/li>\n<li>The display part of the code uses the <a href=\"http:\/\/arduino.cc\/playground\/Main\/LedControl\" target=\"_blank\">LedControl library<\/a>. You can read my previous article on how to use <strong><a href=\"http:\/\/embedded-lab.com\/blog\/max7219-serial-seven-segment-displays-for-esp8266\/\" target=\"_blank\">MAX7219-based seven segment displays with ESP8266<\/a><\/strong>.<\/li>\n<li>The time is displayed in 12 hour format. The decimal digit of the first digit from right is a PM indicator, which means it will turn on for PM hours.<\/li>\n<li>The colon segments will blink at 1 Hz.<\/li>\n<\/ul>\n<div id=\"attachment_11630\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/Clock.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-11630\" class=\"wp-image-11630 size-medium\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/Clock-580x403.jpg\" alt=\"ESP8266 WiFi clock\" width=\"580\" height=\"403\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/Clock-580x403.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/Clock.jpg 800w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-11630\" class=\"wp-caption-text\">ESP8266 WiFi clock showing time 3:05 PM<\/p><\/div>\n<div id=\"attachment_11616\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/P_20160731_100303.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-11616\" class=\"wp-image-11616 size-medium\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/P_20160731_100303-580x391.jpg\" alt=\"P_20160731_100303\" width=\"580\" height=\"391\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/P_20160731_100303-580x391.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2016\/07\/P_20160731_100303.jpg 800w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-11616\" class=\"wp-caption-text\">Time shown is 10:01 AM<\/p><\/div>\n<p><strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/esp8266-breadboard-adapter\/\" target=\"_blank\">Buy ESP-01 adapter!<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/spi-4-digit-seven-segment-led-display\/\" target=\"_blank\">Buy MAX7219 serial LED display<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/www.tindie.com\/products\/rajbex\/general-purpose-50v-and-33v-fixed-power-supply\/\" target=\"_blank\">Buy dual (3.3V\/5.0V) regulated power supply<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Internet has made it quite easy for computers to synchronize their clocks to an accurate clock value generated by a remote server. In the United States, the National Institute of Standards and Technology (NIST) provides official time. NIST disseminates the time using several methods, which include broadcasting over short-wave and long-wave radio, telephone dial-in services (ACTS), and Network Time Service (NTS) over the internet. This article describes a ESP8266-based clock project that utilizes NIST\u2019s NTS service to retrieve accurate time information and display it on a 4-digit seven segment LED display. The time is synchronized to the NIST server after<\/p>\n","protected":false},"author":1,"featured_media":11630,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[245,1044,958,1467],"tags":[1435,1437,1436],"class_list":["post-11615","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded-lab-projects","category-esp8266","category-internet-of-things","category-projects","tag-esp8266-arduino","tag-esp8266-based-clock","tag-internet-clock"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/11615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=11615"}],"version-history":[{"count":29,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/11615\/revisions"}],"predecessor-version":[{"id":11660,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/11615\/revisions\/11660"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/11630"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=11615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=11615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=11615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}