Pin numbering for WeMos D1 Mini (ESP8266)

Here I explain the difference in pin numbering for the WeMos D1 Mini compared to an Arduino and include a sample blink sketch.

Setting up the Arduino IDE for the WeMos D1 mini

This tutorial assumes that you have set up the Arduino IDE to able to compile the Wemos D1 mini.

You can follow the steps as outlined in the post Configuring the Wemos D1 Mini Pro ESP8266 for Arduino IDE. Once it is set up as described in the tutorial the Arduino IDE needs to be set to compile for the WeMos D1 Mini

Difference between the Arduino and WeMos D1 mini pins

One of the problems you will encounter when programming the WeMos D1 is that pin 1 on the WeMos isnt pin 1 in the Arduino IDE. The pin numbers in the WeMos D1 Pro (the ESP8266) are differently numbered than the Arduino.

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:

void setup() {
  Serial.begin(115200);
  pinMode(5, OUTPUT); //Digital pin 1 is pin 5 on the ESP8266
}

The full list of output pins to identifiers are as follows, taken from the source code:

Labelled WeMos Pin NumberArduino Pin Number constant to use “Real” Microcontroller Pin Number
Digital Pin 0D016
Digital Pin 1D15
Digital Pin 2D24
Digital Pin 3D30
Digital Pin 4D42
Digital Pin 5D514
Digital Pin 6D612
Digital Pin 7D713
Digital Pin 8D815
TXTX1
RXRX3

These can be used to program the WeMos D1 mini using the Arduino IDE.

However there is an easier way. The ESP8266 Arduino library 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 D1.

So our above example can be made easier using these constants

void setup() {
  Serial.begin(115200);
  pinMode(D1, OUTPUT); //Digital pin 1 is pin 4 on the ESP8266 and D1 as a constant
}

Using these constants mean we don’t need to refer to the table to find which pin number relates to Arduino pin.

Example Blink Sketch for WeMos D1 mini

To demonstrate using these constants I have rewritten the Arduino blink sketch using the WeMos D1 mini. The code is as follows:

void setup() {
  Serial.begin(115200);
  pinMode(D1, OUTPUT);
}

void loop() {
  //We use D1 as a constant instead of 1 since the port mapping is different to the Arduino.
  digitalWrite(D1, HIGH);
  Serial.println("Blink On");
  delay(2000);
  digitalWrite(D1, LOW);
  Serial.println("Blink Off");
  delay(2000);
}

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.

The main difference to the standard Arduino Blink sketch is that I am using the constant D1 as discussed earlier instead of 5 as the pin number.

Using these constants you can easily program the WeMos D1 mini and other WeMos microcontrollers.

If you have any questions about the WeMos or using the constants above feel free to ask below.

15 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.