Wemos D1 Mini – Pinout and Setup

FunduinoPublished on

Pinbelegung, Bussysteme, WLAN und die Einrichtung in der Arduino IDE

Der Wemos D1 Mini ist ein winziges Board mit WLAN an Bord – und damit ein guter Einstieg in alles, was mit dem Netzwerk zu tun hat. Die Programmierung läuft wie beim Arduino über die Arduino IDE.

Diese Seite ist eine Referenz: Sie zeigt dir die Pinbelegung für I²C, SPI, die digitalen Pins und den analogen Eingang, gibt zu jedem Bereich ein kleines Beispiel und erklärt zum Schluss die Einrichtung in der Arduino IDE.

Wemos D1 Mini Type-C from above
The D1 Mini Type C with Mini-USB connector

You need this

0.96-inch OLED display - 128x64 pixels, I2C, SSD1306 0.96-inch OLED display - 128x64 pixels, I2C, SSD1306 4,62 € *Item no. FUN-1010561About the product — 0.96-inch OLED display - 128x64 pixels, I2C, SSD1306
LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V 6,21 € *Item no. F23107181About the product — LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V
DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V 5,10 € *Item no. F23106657About the product — DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V
D1 Mini microcontroller - Wi-Fi, Bluetooth LE, Micro-USB D1 Mini microcontroller - Wi-Fi, Bluetooth LE, Micro-USB 4,57 € *Item no. F23107825About the product — D1 Mini microcontroller - Wi-Fi, Bluetooth LE, Micro-USB

All 4 parts together 20,50 € *

* All prices include statutory VAT, plus shipping costs.

What the Wemos D1 Mini can do

The Wemos D1 Mini offers:

  • digital inputs and outputs
  • an analog input
  • the I²C and SPI bus systems
  • Wi-Fi

There are currently two versions. The pinout is identical on both; only the USB connector differs: the D1 Mini Type C connects via Mini-USB, while the D1 Mini V4.0 connects via USB-C.

Wemos D1 Mini Type-C from above
The D1 Mini Type C with Mini-USB connector
Wemos D1 Mini V4.0 from above
The D1 Mini V4.0 with USB-C connector
1 / 2

The I²C pins

The I²C bus (Inter-Integrated Circuit) was originally developed by Philips so that a controller - here, the Wemos D1 Mini - can communicate with various peripheral devices. The two connections are called SDA and SCL:

  • D1 – SCL
  • D2 – SDA

These components are controlled via I²C, for example:

Pinout of the Wemos D1 Mini with highlighted I2C pins
The I²C pins: D1 is SCL, D2 is SDA

The SPI pins

The SPI bus (Serial Peripheral Interface) is also used for communication between a controller and peripheral devices. It requires two data lines and two control lines:

  • COPI (Controller Out, Peripheral In) – communication from the controller to the peripheral device
  • CIPO (Controller In, Peripheral Out) – communication from the peripheral device to the controller
  • CS (Chip Select) – the controller activates the peripheral device and starts communication
  • SCK (Serial Clock) – the clock frequency generated by the controller for the SPI bus

On the Wemos D1 Mini, they are assigned to these pins:

  • D7 – COPI/SDO
  • D6 – CIPO/SDI
  • D5 – CLK
  • D8 – CS

Several initiatives are working to replace the old but still widely used terms MOSI (Master Out Slave In, now COPI) and MISO (Master In Slave Out, now CIPO). Learn more at SparkFun, at OSHWA and in the Arduino documentation.

Pinout of the Wemos D1 Mini with highlighted SPI pins
The SPI pins D5 to D8

The digital pins

You can use most digital pins freely. However, some have a special role when uploading a sketch:

  • D0 – is HIGH during upload
  • D1, D2 – free to use (also the I²C pins)
  • D3 – enables firmware upload when LOW
  • D4 – must not be LOW during upload; afterward, it can be used as a regular input/output pin. The onboard LED is connected to this pin.
  • D5, D6, D7 – free to use (also the SPI pins)
  • D8 – must not be HIGH during upload

To try it out, run a blink program with an LED on pin D8. If you use D4 instead, the onboard LED will light up too.

Pinout of the Wemos D1 Mini with highlighted digital pins
The digital pins of the Wemos D1 Mini
Wemos D1 Mini with an LED on pin D8
Setup for the blink program: LED on D8
1 / 2
Blink program for an LED on D8
int LED = D8;
void setup()
{
  pinMode(LED, OUTPUT);
}

void loop()
{
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
  delay(1000);
}

The analog pin

The Wemos D1 Mini has exactly one analog pin: A0. The resolution is 10 bits, so the highest value is 1023.

As an example, the sketch reads a potentiometer connected to A0. It’s especially easy to visualize in the Serial Plotter: you can see the rotation as a curve.

Wemos D1 Mini with a potentiometer connected to pin A0
Potentiometer on analog pin A0
Serial plotter showing the curve of a potentiometer
Output in the serial plotter when turning the potentiometer
1 / 2
Read the potentiometer on pin A0
// Potentiometer an Pin A0
int Potentiometer = A0;

// Variable für den gelesenen Wert
int GelesenerWert = 0;

void setup()
{
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  // analogen Wert lesen
  GelesenerWert = analogRead(Potentiometer);
  Serial.println(GelesenerWert);
  delay(500);
}

Wi-Fi example: Random numbers in the browser

The following program turns the Wemos D1 Mini into a small web server: it generates random numbers and displays them in a browser.

Enter your router’s SSID and password at the top of the sketch. After uploading, the IP address assigned to the board by the router via DHCP appears in the serial monitor. Enter this address in a browser of your choice.

The board and the computer you use to access the page must be on the same network. The page is only accessible on the local network, not from the internet.

Serial monitor with the IP address of the Wemos D1 Mini
The IP address assigned via DHCP appears in the serial monitor.
Browser window with the random numbers generated by the Wemos D1 Mini
The random numbers in the browser
1 / 2
Wi-Fi example: Display random numbers in the browser
#include "ESP8266WiFi.h"
// Router SSID and password
char Router[] = "Router_SSID";
char Passwort[] = "xxxxxxxx";
WiFiServer Server(80);
WiFiClient Client;
// Minimum and maximum random numbers
int Minimum = 1;
int Maximum = 49;
void setup()
{
 Serial.begin(9600);
 // Wait for serial connection
 while (!Serial);
 // Start WiFi
 WiFi.begin(Router, Passwort);
 // Establish connection
 while (WiFi.status() != WL_CONNECTED)
 {
 delay(200);
 Serial.print(".");
 }
 Server.begin();
 // Display router SSID
 Serial.println();
 Serial.print("Connected to ");
 Serial.println(WiFi.SSID());
 // Display IP
 Serial.println(WiFi.localIP());
 // Start random number generator with the signal on A0
 randomSeed(analogRead(0));
}
void loop()
{
 Client = Server.available();
 if (Client)
 {
 // Build page when SeiteAufbauen is true
 boolean SeiteAufbauen = true;
 // As long as the client is connected ...
 while (Client.connected())
 {
 if (Client.available())
 {
 // Read request from client ...
 char Zeichen = Client.read();
 // Return (\n) sent
 if (Zeichen == '\n')
 {
 // If SeiteAufbauen has the value true
 if (SeiteAufbauen)
 {
 /*
 Build HTML page.
 The following statements must be sent with print or println.
 println "beautifies" the source code by adding a line break
 to the source code.
 */
 Client.println("HTTP/1.1 200 OK");
 Client.println("Content-type:text/html");
 // Blank line is required
 Client.println();
 Client.println("<!doctype html>");
 Client.println("<html>");
 Client.println("<body>");
 // Refresh every 60 seconds with a meta tag
 Client.println("<meta http-equiv=\"refresh\" content=\"60\">");
 // <h2> Heading H2
 Client.println("<h2>Random numbers</h2>");
 // <hr> horizontal line
 Client.println("<hr>");
 // Display random numbers
 for (int i = 0; i < 7; i++)
 {
 int Zahl = random(Minimum, Maximum);
 Client.println(Zahl);
 Client.println(" ");
 }
 Client.print("<hr>");
 // Display IPs
 Client.print("Own IP (server): ");
 Client.print(Client.remoteIP());
 // <br> break = new line
 Client.print("<br>Client DHCP IP address ");
 Client.print(WiFi.localIP());
 // Close the page
 Client.println("</h2></body>");
 Client.println("</html>");
 // HTTP response ends with a new line
 Client.println();
 // Page fully loaded -> exit loop
 break;
 }
 // If a new line (\n) was sent -> build the page
 if (Zeichen == '\n') SeiteAufbauen = true;
 else if (Zeichen != '\r') SeiteAufbauen = false;
 delay(1);
 Client.stop();
 }
 }
 }
 }
}

Install and select the board

Enter under File › Preferences an additional board manager URL:

https://arduino.esp8266.com/stable/package_esp8266com_index.json

  • Click the Board Manager icon or open Tools › Board › Boards Manager
  • search for esp8266
  • Install the board

If the Wemos D1 Mini is not detected automatically afterward, click “Select another board and port” and search for “Wemos D1”. The USB port name depends on your operating system.

You can find the same setup in more detail in the guide Installing Wemos D1 and NodeMCU in the Arduino IDE.

Arduino IDE settings window with the ESP8266 Boards Manager URL entered
The board manager URL under File › Preferences
Board management in the Arduino IDE with the search result esp8266
Search for esp8266 in the Boards Manager and install it.
Arduino IDE dialog for selecting a board and port
“Select a different board and a different port”
Board selection in the Arduino IDE with the search result Wemos D1
Search for “Wemos D1” and select the board
1 / 4
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.