{"id":13015,"date":"2017-01-17T14:33:11","date_gmt":"2017-01-17T19:33:11","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=13015"},"modified":"2017-01-17T14:33:11","modified_gmt":"2017-01-17T19:33:11","slug":"tutorial-2-easyesp-1-hello-world-example","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/tutorial-2-easyesp-1-hello-world-example\/","title":{"rendered":"Tutorial 2: EasyESP-1 &#8220;Hello World&#8221; Example"},"content":{"rendered":"<p>After <a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-1-setting-arduino-ide-easyesp-1\/\" target=\"_blank\"><strong>setting up the Arduino IDE<\/strong><\/a> to enable support for ESP8266, it\u2019s time to write your first code for EasyESP-1 board. We will start with the classic <em>hello world<\/em>! example of electronics, a flashing LED. This is the best example to start with any new hardware platform as it gives us an opportunity to verify that\u00a0the required\u00a0software tools\/drivers are installed properly and ready to rock.<\/p>\n<h3>Hardware Setup<\/h3>\n<p>In this example, we will connect the <strong>LD1<\/strong> and <strong>D1<\/strong> pins of <strong>J3<\/strong> header together with a jumper wire as shown below. This will connect the <strong>LD1<\/strong> LED near\u00a0the bottom right corner of EasyESP-1 to the <strong>D1<\/strong> I\/O pin (or GPIO5) of ESP8266.<\/p>\n<div id=\"attachment_13016\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20161010_172848-600x475.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13016\" class=\"size-full wp-image-13016\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20161010_172848-600x475.jpg\" alt=\"Connections for the \u201cHello World\u201d example\" width=\"600\" height=\"475\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20161010_172848-600x475.jpg 600w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/P_20161010_172848-600x475-580x459.jpg 580w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-13016\" class=\"wp-caption-text\"><em><strong>Connections for the \u201cHello World\u201d example<\/strong><\/em><\/p><\/div>\n<h3>Software<\/h3>\n<p>Open a new window on Arduino IDE and select appropriate options for Boards, Serial Port, CPU frequency, and Upload speed. You need to choose NodeMCU 1.0 (ESP-12E Module) from Board menu, set CPU frequency to 80 MHz, Upload Speed to 115200, and match Serial Port to the one that your EasyESP-1 is connected to. Check out my previous tutorial \u201c<a href=\"http:\/\/embedded-lab.com\/blog\/tutorial-1-setting-arduino-ide-easyesp-1\/\" target=\"_blank\"><strong>Getting started with EasyESP-1 using Arduino IDE<\/strong><\/a>\u201d for more details on this. Your selected options are shown in\u00a0the bottom tab of the Arduino IDE, make sure they match with the ones shown below.<\/p>\n<div id=\"attachment_13017\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/IDE1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13017\" class=\"wp-image-13017 size-full\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/IDE1.png\" alt=\"IDE1\" width=\"800\" height=\"506\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/IDE1.png 800w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/IDE1-580x367.png 580w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><p id=\"caption-attachment-13017\" class=\"wp-caption-text\"><em><strong>Arduino IDE option setup for EasyESP-1<\/strong><\/em><\/p><\/div>\n<p>As I described in the <a href=\"http:\/\/embedded-lab.com\/blog\/easyesp-1-rapid-prototyping-development-board-esp8266\/\" target=\"_blank\"><strong>EasyESP-1 Introduction<\/strong><\/a>,\u00a0EasyESP-1 uses the same I\/O indexing as used by <a href=\"https:\/\/nodemcu.readthedocs.io\/en\/master\/en\/modules\/gpio\/\" target=\"_blank\"><strong>NodeMCU<\/strong><\/a>. This does not match with internal GPIO indexing. For example, pin D1 is actually mapped to internal GPIO5. In\u00a0Arduino IDE, you can access this pin in both\u00a0ways. For example, <em>digitalWrite(D1, LOW)<\/em> and\u00a0<em>digitalWrite(5, LOW)<\/em> will both do the same thing, writes out logic \u2018low\u2019 to D1 pin.\u00a0Next, copy the following code and paste it into your empty program window. The program is written to blink the LD1 LED at a rate of 1Hz. Save the code, verify it, and upload it to EasyESP-1 board in the same way as you do for Arduino.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #808080; font-style: italic;\">\/*\n Hello World example for EasyESP-1\n Blink the red LED (LD1) on the EasyESP-1 board at 1Hz\n *\/<\/span>\n&nbsp;\n<span style=\"color: #339933;\">#define LD1   D1  \/\/ Define LD1 as D1 I\/O pin<\/span>\n<span style=\"color: #666666; font-style: italic;\">\/\/ Alternatively, you can also define it as GPIO5<\/span>\n<span style=\"color: #666666; font-style: italic;\">\/\/#define LD1 5<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> setup<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  pinMode<span style=\"color: #009900;\">&#40;<\/span>LD1<span style=\"color: #339933;\">,<\/span> OUTPUT<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/ Initialize LD1 as output<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> loop<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  digitalWrite<span style=\"color: #009900;\">&#40;<\/span>LD1<span style=\"color: #339933;\">,<\/span> LOW<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>   <span style=\"color: #666666; font-style: italic;\">\/\/ Turn ON LD1<\/span>\n  delay<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">500<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>               <span style=\"color: #666666; font-style: italic;\">\/\/ Wait for 0.5 sec<\/span>\n  digitalWrite<span style=\"color: #009900;\">&#40;<\/span>LD1<span style=\"color: #339933;\">,<\/span> HIGH<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>  <span style=\"color: #666666; font-style: italic;\">\/\/ Turn it off<\/span>\n  delay<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">500<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>               <span style=\"color: #666666; font-style: italic;\">\/\/ Wait for 0.5 sec<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<h3>Output<\/h3>\n<p>If everything worked perfectly, you would see <strong>LD1<\/strong> flashing at 1 Hz and with 50% duty cycle (i.e. on and off time are both 0.5 sec).<\/p>\n<div id=\"attachment_13019\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1-1-600x422.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-13019\" class=\"size-full wp-image-13019\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1-1-600x422.jpg\" alt=\"LD1 flashes at 1Hz rate\" width=\"600\" height=\"422\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1-1-600x422.jpg 600w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2017\/01\/output1-1-600x422-580x408.jpg 580w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-13019\" class=\"wp-caption-text\"><em><strong>LD1 flashes at 1Hz rate<\/strong><\/em><\/p><\/div>\n<h3><a href=\"https:\/\/www.elecrow.com\/easyesp-1-an-esp8266-experimenter-board-for-beginners.html\" target=\"_blank\">Buy EasyESP-1 board<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>After setting up the Arduino IDE to enable support for ESP8266, it\u2019s time to write your first code for EasyESP-1 board. We will start with the classic hello world! example of electronics, a flashing LED. This is the best example to start with any new hardware platform as it gives us an opportunity to verify that\u00a0the required\u00a0software tools\/drivers are installed properly and ready to rock. Hardware Setup In this example, we will connect the LD1 and D1 pins of J3 header together with a jumper wire as shown below. This will connect the LD1 LED near\u00a0the bottom right corner of<\/p>\n","protected":false},"author":1,"featured_media":13016,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1603,1044,1466],"tags":[1607,1606],"class_list":["post-13015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-tutorials","category-esp8266","category-tutorials","tag-esp8266-arduino-ide","tag-esp8266-hello-world"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13015","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=13015"}],"version-history":[{"count":5,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13015\/revisions"}],"predecessor-version":[{"id":13023,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/13015\/revisions\/13023"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/13016"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=13015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=13015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=13015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}