Wemos D1 R32 in UNO format

FunduinoPublished on

Ein ESP32 in der Bauform des Arduino UNO – Pinbelegung, WiFi und Bluetooth

Das Wemos D1 R32 sieht aus wie ein Arduino UNO, ist aber ein ESP32: deutlich schneller, mit mehr Speicher und mit WiFi und Bluetooth LE an Bord. Shields im UNO-Format passen mechanisch darauf.

Diese Anleitung ist eine Übersicht über das Board: Du richtest es in der Arduino IDE ein und gehst danach seine Schnittstellen durch – I2C, SPI, digitale und analoge Pins, die Touch-Eingänge sowie WiFi und Bluetooth. Zu jedem Bereich gehört ein kleines Beispielprogramm zum Ausprobieren.

Black circuit board in Arduino UNO format with ESP32-WROOM-32 module
The Wemos D1 R32 in UNO format

You need this

0.96-inch OLED display - 128x64 pixels, I2C, SSD1306 0.96-inch OLED display - 128x64 pixels, I2C, SSD1306 4,19 € *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

All 3 parts together 15,50 € *

* All prices include statutory VAT, plus shipping costs.

What the Wemos D1 R32 can do

The Wemos D1 R32 features an Espressif ESP32-WROOM-32 on a board with the same form factor as the Arduino UNO. UNO shields therefore fit the board mechanically.

The board offers:

  • digital inputs and outputs
  • analog inputs with 12-bit resolution
  • touch-sensitive touch pins
  • the I2C and SPI bus systems
  • WiFi
  • Bluetooth LE (BLE)

Many pins have multiple functions: The I2C, SPI, and touch pins can also be used as regular digital pins.

The UNO format does not mean that the pin labeled “D13” is also GPIO 13. The labels follow the UNO numbering, whereas in your sketch you address the ESP32’s GPIO numbers. So refer to the pinout diagrams in the following steps.

Black circuit board in Arduino UNO format with ESP32-WROOM-32 module
The Wemos D1 R32 in UNO format

Install the board in the Arduino IDE

To make the Arduino IDE recognize the ESP32, enter an additional Board Manager URL under File → Preferences :

https://espressif.github.io/arduino-esp32/package_esp32_index.json

Then follow these steps:

  • Click the Board Manager icon or open Tools → Board → Board Manager
  • Search for esp32
  • Install the “esp32 by Espressif Systems” package

Older guides still list the address dl.espressif.com/dl/package_esp32_index.json. It no longer works reliably - use the address mentioned above.

Arduino IDE settings dialog with the field for board manager URLs
The additional board manager URL is entered in the settings.
Board Manager for the Arduino IDE with the ESP32 package
Search for ESP32 in the Board Manager and install it.
1 / 2

Select board and port

If the Wemos D1 R32 isn't detected automatically, click “Select another board and port” in the dropdown above and search for esp32-wroom.

Select the appropriate port next to it. Its name varies depending on your operating system - for example, COM3 on Windows, while on macOS and Linux it starts with /dev/.

Arduino IDE board selection dialog
You can manually select the board via “Choose a different board and port”
Board selection dialog with the search term esp32-wroom
Search for esp32-wroom and select the appropriate port.
1 / 2

I2C pins

The I2C bus (Inter-Integrated Circuit) was originally developed by Philips so that a controller—here, the Wemos D1 R32—could communicate with multiple peripheral devices using just two wires. The two connections are called SDA (data) and SCL (clock).

  • GPIO 21 → SDA
  • GPIO 22 → SCL

These components are controlled via I2C:

Pinout diagram of the Wemos D1 R32 with highlighted I2C pins
Location of the I2C pins SDA and SCL

SPI pins

The SPI bus (Serial Peripheral Interface) also connects the controller to peripheral devices. It requires two data lines and two control lines:

  • COPI (Controller Out, Peripheral In) – data from the controller to the peripheral device
  • CIPO (Controller In, Peripheral Out) – data from the peripheral device to the controller
  • CS (Chip Select) – the controller selects the device it wants to communicate with
  • SCK (Serial Clock) – the clock frequency generated by the controller

On the Wemos D1 R32, these are available on the following pins:

  • GPIO 23 → COPI/SDO
  • GPIO 19 → CIPO/SDI
  • GPIO 18 → SCK
  • GPIO 5 → CS

In older literature and in many libraries, these lines are still called MOSI (Master Out Slave In, now COPI) and MISO (Master In Slave Out, now CIPO). Several initiatives are working to replace the old names, including SparkFun, OSHWA, and the Arduino documentation.

Pinout diagram of the Wemos D1 R32 with highlighted SPI pins
SPI pinout locations

Digital pins

The following GPIOs are available as digital inputs and outputs: 2, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, and 33.

GPIOs 34, 35, 36, and 39 are also digital pins, but can only be used as inputs (INPUT) - they cannot be used as outputs.

As an example, you switch on an LED with a push button: the LED lights up as long as the button is pressed.

The GPIOs 15, 32, and 33 are not routed to the usual pin headers on the board. To use them safely, a pin header must be soldered there.

Pinout diagram of the Wemos D1 R32 with highlighted digital pins
Location of the digital pins
Breadboard with LED and push button on the Wemos D1 R32
Setup: LED on pin 13, push button on pin 12
1 / 2
Sketch: Switching an LED with a push button
int LED = 13;
int Taster = 12;

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(Taster, INPUT_PULLUP);
}

void loop()
{
  // With INPUT_PULLUP, the pin is HIGH when idle.
  // When pressed, it is connected to GND and therefore LOW.
  if (digitalRead(Taster) == LOW) digitalWrite(LED, HIGH);
  else digitalWrite(LED, LOW);
}

Touch pins

The human body and conductive objects can store electrical charge. The ESP32 takes advantage of this: when you touch one of the touch pins, its reading changes significantly - without any additional components.

Available touch pins (datasheet designation in parentheses):

  • GPIO 4 (T0)
  • GPIO 12 (T5)
  • GPIO 14 (T6)
  • GPIO 15 (T3)
  • GPIO 27 (T7)
  • GPIO 32 (T9)
  • GPIO 33 (T8)

To try it out, connect a single wire to GPIO 14 (T6) and touch the exposed end of the wire with your finger. If it doesn't work right away, moisten your finger a little.

The same applies here: GPIO 15, 32, and 33 can only be used safely with a soldered pin header. The threshold value of 25 in the sketch is based on experience—first check the readings in the Serial Monitor and adjust it to your setup.

Pinout diagram of the Wemos D1 R32 with touch pins highlighted
Position of the touch pins
Photo of the Wemos D1 R32 with a cable connected to the touch pin
A single wire on touch pin 14 is enough as a sensor
Serial monitor with touch readings
Serial Monitor output: The measured value drops significantly as soon as the cable end is touched.
1 / 3
Sketch: Read touch pin
void setup()
{
  // Serielle Kommunikation starten
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  // Messwert nur einmal pro Durchlauf lesen und zwischenspeichern
  int Messwert = touchRead(14);

  Serial.print("Wert: ");
  Serial.print(Messwert);

  // Kleiner Wert -> Pin wurde beruehrt
  if (Messwert < 25) Serial.println(" -> Pin beruehrt");

  // Bei groesseren Werten wurde der Pin nicht beruehrt
  else Serial.println(" -> Pin nicht beruehrt");

  delay(1000);
}

Analog pins

The ESP32 has two analog-to-digital converters (ADC1 and ADC2), each with 12-bit resolution. A reading therefore ranges from 0 to 4095 - on the Arduino UNO, it’s only 0 to 1023.

On the Wemos D1 R32, the analog inputs are distributed as follows:

  • ADC1: GPIO 32, 33, 34, 35, 36, and 39
  • ADC2: including GPIO 2, 4, 12, 13, 14, 25, 26, and 27

As an example, read a potentiometer connected to GPIO 35. You can monitor the output in the Serial Monitor - it’s even easier to visualize in the Serial Plotter, which draws the value as a curve.

As soon as Wi-Fi is active, ADC2 is used by the wireless module. Analog measurements are then only possible via ADC1, meaning GPIO 32 to 39. Plan your connections accordingly from the start if your project is going to connect to Wi-Fi later on.

Pinout diagram of the Wemos D1 R32 with highlighted analog pins
Location of the analog inputs
Breadboard with potentiometer for the Wemos D1 R32
Setup: Potentiometer on analog input GPIO 35
Serial plotter with rising and falling curve
Serial Plotter output when turning the potentiometer
1 / 3
Sketch: Read potentiometer
// Potentiometer an GPIO 35
int Potentiometer = 35;

// Variable fuer den gelesenen Wert
int GelesenerWert = 0;

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

void loop()
{
  // Analogen Wert lesen (0 bis 4095)
  GelesenerWert = analogRead(Potentiometer);
  Serial.println(GelesenerWert);
  delay(500);
}

Wi-Fi: build a small web server

The ESP32 can not only connect to a Wi-Fi network but also act as a server on it. The following program serves a small webpage with six random numbers that updates itself every minute.

Before uploading, enter your router’s SSID and password in the sketch. After startup, the serial monitor displays the IP address assigned to the board via DHCP. Enter this address in your browser.

The router assigns the address via DHCP - it may change after a restart. If you want the board to remain reachable at the same address, assign a fixed IP to its MAC address in the router.

Serial monitor with the Wemos D1 R32 IP address
The IP address assigned via DHCP appears in the Serial Monitor.
Browser window with the heading Random Numbers and a row of numbers
The random number page served by the board in the browser
1 / 2
Sketch: Web server with random numbers
#include "WiFi.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);
  delay(1000);

  // Start WiFi
  WiFi.begin(Router, Passwort);

  // Establish connection
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(200);
    Serial.print(".");
  }
  Server.begin();

  // Display the router SSID
  Serial.println();
  Serial.print("Connected to ");
  Serial.println(WiFi.SSID());

  // Display the board's IP - enter this address in your browser
  Serial.println(WiFi.localIP());

  // Initialize the random number generator with noise from an unconnected analog pin
  randomSeed(analogRead(35));
}

void loop()
{
  Client = Server.available();
  if (!Client) return;

  // While the client is connected ...
  while (Client.connected())
  {
    if (!Client.available()) continue;

    // Read the request from the client ...
    char Zeichen = Client.read();

    // ... and respond only after the line break
    if (Zeichen != '\n') continue;

    /*
      Build the HTML page.
      The following instructions must be sent with print or println.
      println "beautifies" the source code,
      creating a line break in 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
    Client.println("<meta http-equiv=\"refresh\" content=\"60\">");

    // Heading and horizontal line
    Client.println("<h2>Random numbers</h2>");
    Client.println("<hr>");

    // Display six random numbers.
    // random() returns values up to Maximum - 1, so use Maximum + 1.
    for (int i = 0; i < 6; i++)
    {
      int Zahl = random(Minimum, Maximum + 1);
      Client.print(Zahl);
      Client.print(" ");
    }
    Client.println("<hr>");

    // Display IP addresses
    Client.print("IP of this board (server): ");
    Client.print(WiFi.localIP());
    Client.print("<br>IP of the device making the request: ");
    Client.print(Client.remoteIP());

    // Close the page
    Client.println("</body>");
    Client.println("</html>");

    // The HTTP response ends with a new line
    Client.println();
    break;
  }

  // End the connection
  delay(1);
  Client.stop();
}

Bluetooth LE: control the internal LED via app

First, install the library ArduinoBLE via Sketch → Include Library → Manage Libraries or by clicking the corresponding icon in the left-hand toolbar.

The program controls the board’s built-in LED: writing a 1 turns it on, and writing a 0 turns it off. The value is written by an app on a smartphone.

The free app LightBlueis suitable for this and is available for iOS and Android. Connect to the “LED schalten” device in the app and write the value 1 or 0 to the characteristic.

The service and characteristic each need their own UUID. If you use the same one for both, some apps may behave unpredictably. You can generate your own UUIDs for free with an online generator such as uuidgenerator.net.

Library manager of the Arduino IDE with the ArduinoBLE library
The “ArduinoBLE” library in the Library Manager
Sketch: Control the internal LED via Bluetooth LE
#include "ArduinoBLE.h"
/*
  Determine unique UUIDs:
  https://www.guidgenerator.com/online-guid-generator.aspx
  https://www.uuidgenerator.net/
  BLERead | BLEWrite | BLENotify -> read, write, notify
  Each service and characteristic needs its own UUID.
*/

// Name of the BLE service
BLEService LEDSchalten("19b10000-e8f2-537e-4f6c-d104768a1214");

BLEUnsignedCharCharacteristic Auswahl("19b10001-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite | BLENotify);

// Internal LED
int LED = 2;

void setup()
{
  Serial.begin(9600);

  // Set pinMode
  pinMode(LED, OUTPUT);

  // Start BLE
  if (!BLE.begin()) Serial.println("Bluetooth module could not be started!");
  else Serial.println("Bluetooth module started successfully!");

  // Set the name (displayed in the app) and assign the service
  BLE.setLocalName("Switch LED");
  BLE.setAdvertisedService(LEDSchalten);

  // Auswahl as a placeholder for the value selected in the app
  LEDSchalten.addCharacteristic(Auswahl);

  // Add the LEDSchalten service
  BLE.addService(LEDSchalten);

  // Write the initial value for communication
  Auswahl.writeValue(0);

  // Make visible
  BLE.advertise();
}

void loop()
{
  // Wait for a connection to devices
  BLEDevice Verbindung = BLE.central();

  // If the ESP32 is connected to a device ...
  if (Verbindung)
  {
    Serial.println("Connected ... ");

    // While the controller is connected to a device ...
    while (Verbindung.connected())
    {
      if (Auswahl.written())
      {
        // Turn on the LED
        if (Auswahl.value() == 1)
        {
          Serial.print(Auswahl.value());
          Serial.println(" -> LED on");
          digitalWrite(LED, HIGH);
        }

        // Turn off the LED
        if (Auswahl.value() == 0)
        {
          Serial.print(Auswahl.value());
          Serial.println(" -> LED off");
          digitalWrite(LED, LOW);
        }
      }
    }
  }
}
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.