{"id":1066,"date":"2018-03-17T13:00:40","date_gmt":"2018-03-17T13:00:40","guid":{"rendered":"http:\/\/chewett.co.uk\/blog\/?p=1066"},"modified":"2021-07-23T17:33:13","modified_gmt":"2021-07-23T16:33:13","slug":"pin-numbering-for-wemos-d1-mini-esp8266","status":"publish","type":"post","link":"https:\/\/chewett.co.uk\/blog\/1066\/pin-numbering-for-wemos-d1-mini-esp8266\/","title":{"rendered":"Pin numbering for WeMos D1 Mini (ESP8266)"},"content":{"rendered":"\n<p>Here I explain the difference in pin numbering for the WeMos D1 Mini compared to an Arduino and include a sample blink sketch.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Setting up the Arduino IDE for the WeMos D1 mini<\/h2>\n\n\n\n<p>This tutorial assumes that you have set up the Arduino IDE to able to compile the&nbsp;Wemos D1 mini.<\/p>\n\n\n\n<p>You can follow the steps as outlined in the post <a href=\"http:\/\/chewett.co.uk\/blog\/937\/configuring-wemos-d1-mini-pro-esp8266-arduino-ide\/\">Configuring the Wemos D1 Mini Pro ESP8266 for Arduino IDE<\/a>. Once it is set up as described in the tutorial the Arduino IDE needs to be set to compile for the WeMos D1 Mini<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Difference between the Arduino and WeMos D1 mini pins<\/h2>\n\n\n\n<p>One of the problems you will encounter when programming the WeMos D1 is that pin 1 on the WeMos isnt&nbsp;pin 1 in the Arduino IDE. The pin numbers in the WeMos D1 Pro (the ESP8266) are differently numbered than the Arduino.<\/p>\n\n\n\n<p>This means that if you want to turn on pin 1 on the WeMos D1 mini you will need to use a different pin in the IDE. For example to enable the pin labelled D1 for output for the WeMos you would need to use the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup() {\n  Serial.begin(115200);\n  pinMode(5, OUTPUT); \/\/Digital pin 1 is pin 5 on the ESP8266\n}<\/code><\/pre>\n\n\n\n<p>The full list of output pins to identifiers are as follows, taken from the <a href=\"https:\/\/github.com\/esp8266\/Arduino\/blob\/master\/variants\/d1_mini\/pins_arduino.h#L49-L61\" target=\"_blank\" rel=\"noopener\">source code<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><strong>Labelled WeMos Pin Number<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Arduino Pin Number constant to use&nbsp;<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>&#8220;Real&#8221; Microcontroller Pin Number<\/strong><\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  0<\/td><td class=\"has-text-align-center\" data-align=\"center\">D0<\/td><td class=\"has-text-align-center\" data-align=\"center\">16<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  1<\/td><td class=\"has-text-align-center\" data-align=\"center\">D1<\/td><td class=\"has-text-align-center\" data-align=\"center\">5<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  2<\/td><td class=\"has-text-align-center\" data-align=\"center\">D2<\/td><td class=\"has-text-align-center\" data-align=\"center\">4<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  3<\/td><td class=\"has-text-align-center\" data-align=\"center\">D3<\/td><td class=\"has-text-align-center\" data-align=\"center\">0<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  4<\/td><td class=\"has-text-align-center\" data-align=\"center\">D4<\/td><td class=\"has-text-align-center\" data-align=\"center\">2<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  5<\/td><td class=\"has-text-align-center\" data-align=\"center\">D5<\/td><td class=\"has-text-align-center\" data-align=\"center\">14<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  6<\/td><td class=\"has-text-align-center\" data-align=\"center\">D6<\/td><td class=\"has-text-align-center\" data-align=\"center\">12<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin  7<\/td><td class=\"has-text-align-center\" data-align=\"center\">D7<\/td><td class=\"has-text-align-center\" data-align=\"center\">13<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Digital Pin 8<\/td><td class=\"has-text-align-center\" data-align=\"center\">D8<\/td><td class=\"has-text-align-center\" data-align=\"center\">15<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">TX<\/td><td class=\"has-text-align-center\" data-align=\"center\">TX<\/td><td class=\"has-text-align-center\" data-align=\"center\">1<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">RX<\/td><td class=\"has-text-align-center\" data-align=\"center\">RX<\/td><td class=\"has-text-align-center\" data-align=\"center\">3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>These can be used to program the WeMos D1 mini using the Arduino IDE.<\/p>\n\n\n\n<p>However there is an easier way. The ESP8266 Arduino library&nbsp;provides a number of constants to program the WeMos electronics easier. These constants are named as same as the pins, so digital pin one labelled on the WeMos as D1 can be used with the constant <code>D1<\/code>.<\/p>\n\n\n\n<p>So our above example can be made easier using these constants<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup() {\n  Serial.begin(115200);\n  pinMode(D1, OUTPUT); \/\/Digital pin 1 is pin 4 on the ESP8266 and D1 as a constant\n}<\/code><\/pre>\n\n\n\n<p>Using these constants mean we don&#8217;t need to refer to the table to find which pin number relates to Arduino pin.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example Blink Sketch for WeMos D1 mini<\/h2>\n\n\n\n<p>To demonstrate using these constants I have rewritten the Arduino blink sketch using the WeMos D1 mini. The code is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup() {\n  Serial.begin(115200);\n  pinMode(D1, OUTPUT);\n}\n\nvoid loop() {\n  \/\/We use D1 as a constant instead of 1 since the port mapping is different to the Arduino.\n  digitalWrite(D1, HIGH);\n  Serial.println(\"Blink On\");\n  delay(2000);\n  digitalWrite(D1, LOW);\n  Serial.println(\"Blink Off\");\n  delay(2000);\n}<\/code><\/pre>\n\n\n\n<p>Here I initialize the Serial connection so we can see progress of the program. Using this I have added the additional logging to the program.<\/p>\n\n\n\n<p>The main difference to the standard Arduino Blink sketch is that I am using the constant <code>D1<\/code> as discussed earlier instead of <code>5<\/code> as the pin number.<\/p>\n\n\n\n<p>Using these constants you can easily program the WeMos D1 mini and other WeMos microcontrollers.<\/p>\n\n\n\n<p>If you have any questions about the WeMos or using the constants above feel free to ask below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here I explain the difference in pin numbering for the WeMos D1 Mini compared to an Arduino and include a sample blink sketch.<\/p>\n","protected":false},"author":1,"featured_media":1070,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[97],"tags":[132,211,210,209,237],"class_list":["post-1066","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-electronics","tag-arduino","tag-arduino-ide","tag-esp8266","tag-wemos","tag-wemos-d1-mini"],"wppr_data":{"cwp_meta_box_check":"No"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/03\/pin_numbering_wemos_d1_mini.jpg?fit=800%2C800&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p2toWX-hc","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1412,"url":"https:\/\/chewett.co.uk\/blog\/1412\/using-the-ds18b20-temperature-sensor-with-a-wemos-d1-mini-esp8266\/","url_meta":{"origin":1066,"position":0},"title":"Using the DS18B20 Temperature Sensor with a WeMos D1 Mini (ESP8266)","author":"Chewett","date":"November 21, 2018","format":false,"excerpt":"In this blog post I talk about the additional steps needed to use the DS18B20 onewire temperature sensor with a WeMos D1 Mini (ESP8266) using the Arduino IDE. Important differences compared to using the DS18B20 on an Arduino There is one major difference to bear in mind when using the\u2026","rel":"","context":"In &quot;Electronics&quot;","block_context":{"text":"Electronics","link":"https:\/\/chewett.co.uk\/blog\/category\/electronics\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/11\/wd18b20_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/11\/wd18b20_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/11\/wd18b20_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/11\/wd18b20_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":937,"url":"https:\/\/chewett.co.uk\/blog\/937\/configuring-wemos-d1-mini-pro-esp8266-arduino-ide\/","url_meta":{"origin":1066,"position":1},"title":"Configuring the Wemos D1 Mini Pro ESP8266 for Arduino IDE","author":"Chewett","date":"December 30, 2017","format":false,"excerpt":"This guide runs you through a basic set of steps to configure the Aduino IDE to program a Wemos D1 Mini Pro ESP8266. What is the Wemos D1 mini Pro The Wemos D1 mini Pro is an Arduino-like board that runs using the ESP8266 microcontroller. One of the key differences\u2026","rel":"","context":"In &quot;Electronics&quot;","block_context":{"text":"Electronics","link":"https:\/\/chewett.co.uk\/blog\/category\/electronics\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/01\/wemos_d1_mini_post_icon.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/01\/wemos_d1_mini_post_icon.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/01\/wemos_d1_mini_post_icon.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/01\/wemos_d1_mini_post_icon.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1405,"url":"https:\/\/chewett.co.uk\/blog\/1405\/using-the-dht11-temperature-sensor-with-a-wemos-d1-mini-esp8266\/","url_meta":{"origin":1066,"position":2},"title":"Using the DHT11 Temperature Sensor with a WeMos D1 Mini (ESP8266)","author":"Chewett","date":"August 18, 2018","format":false,"excerpt":"In this blog post I talk about the additional steps needed to use the DHT11 temperature sensor with a WeMos D1 Mini (ESP8266) with the Arduino IDE. Differences from running a DHT11 on an Arduino There are two major differences to bear in mind when using the DHT11 on a\u2026","rel":"","context":"In &quot;Electronics&quot;","block_context":{"text":"Electronics","link":"https:\/\/chewett.co.uk\/blog\/category\/electronics\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/dht11_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/dht11_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/dht11_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/08\/dht11_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2543,"url":"https:\/\/chewett.co.uk\/blog\/2543\/i2c-connection-pins-on-the-wemos-d1-mini-esp8266\/","url_meta":{"origin":1066,"position":3},"title":"I2C Connection Pins on the WeMos D1 Mini (ESP8266)","author":"Chewett","date":"July 18, 2020","format":false,"excerpt":"This blog post details the I2C connections on the WeMos D1 Mini (ESP8266). Using I2C connections with the WeMos D1 Mini (ESP8266) Within IoT devices the I2C protocol is used a lot for multi-master multi-slave communication as a relatively simple serial bus. You will find that small sensors will report\u2026","rel":"","context":"In &quot;Electronics&quot;","block_context":{"text":"Electronics","link":"https:\/\/chewett.co.uk\/blog\/category\/electronics\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/08\/wemos_i2c_pin_numbering_posticon_output.png?fit=1200%2C628&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/08\/wemos_i2c_pin_numbering_posticon_output.png?fit=1200%2C628&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/08\/wemos_i2c_pin_numbering_posticon_output.png?fit=1200%2C628&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/08\/wemos_i2c_pin_numbering_posticon_output.png?fit=1200%2C628&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2020\/08\/wemos_i2c_pin_numbering_posticon_output.png?fit=1200%2C628&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1476,"url":"https:\/\/chewett.co.uk\/blog\/1476\/using-the-dht22-temperature-sensor-with-a-wemos-d1-mini-esp8266\/","url_meta":{"origin":1066,"position":4},"title":"Using the DHT22 Temperature Sensor with a WeMos D1 Mini (ESP8266)","author":"Chewett","date":"September 22, 2018","format":false,"excerpt":"In this blog post I talk about the additional steps needed to use the DHT22 temperature sensor with a WeMos D1 Mini (ESP8266) with the Arduino IDE. Differences from running a DHT22 on an Arduino There are two major differences to bear in mind when using the DHT22 on a\u2026","rel":"","context":"In &quot;Electronics&quot;","block_context":{"text":"Electronics","link":"https:\/\/chewett.co.uk\/blog\/category\/electronics\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/09\/dht22_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/09\/dht22_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/09\/dht22_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/09\/dht22_on_wemos_d1_mini.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1849,"url":"https:\/\/chewett.co.uk\/blog\/1849\/using-the-sw-420-motion-vibration-sensor-with-a-wemos-d1-mini-esp8266\/","url_meta":{"origin":1066,"position":5},"title":"Using the SW-420 Motion Vibration Sensor with a WeMos D1 Mini (ESP8266)","author":"Chewett","date":"December 22, 2018","format":false,"excerpt":"In this blog post I talk about how you can use a SW-420 Motion Vibration sensor with a WeMos D1 Mini (ESP8266) using the Arduino IDE. Summary of the SW-420 Motion Vibration Sensor This sensor mounts a motion detection component with a small micro-controller and a potentiometer. This has a\u2026","rel":"","context":"In &quot;Electronics&quot;","block_context":{"text":"Electronics","link":"https:\/\/chewett.co.uk\/blog\/category\/electronics\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/12\/sw420_vibration_sensor_wemos.jpg?fit=800%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/12\/sw420_vibration_sensor_wemos.jpg?fit=800%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/12\/sw420_vibration_sensor_wemos.jpg?fit=800%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/chewett.co.uk\/blog\/wp-content\/uploads\/2018\/12\/sw420_vibration_sensor_wemos.jpg?fit=800%2C800&ssl=1&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/1066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=1066"}],"version-history":[{"count":7,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/1066\/revisions"}],"predecessor-version":[{"id":2951,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/posts\/1066\/revisions\/2951"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/media\/1070"}],"wp:attachment":[{"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=1066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=1066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chewett.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=1066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}