Using the Arduino D1 R2

힘센캥거루
2025년 10월 7일(수정됨)
3
77

It could have been done using a regular Arduino Uno, but I decided to try the Wemos D1 R2 with built-in WiFi and struggled quite a bit.

This article is for those using Arduinos like the D1 R2 with different pin mappings.

1. IDE Setting

Due to the various types of Arduinos, you also need to install the board package suitable for each board.

Go to File-Preferences in the Arduino IDE.

Using the Arduino D1 R2-1

Then add the following URL to the Additional Boards Manager.

https://arduino.esp8266.com/stable/package_esp8266com_index.json
Using the Arduino D1 R2-2

Then search for D1 R2 in the board package on the left and install it.

Using the Arduino D1 R2-3

Finally, match the USB port and board type correctly and you're done.

Using the Arduino D1 R2-4

2. What are Pins like D1, D2?

The most confusing thing when connecting the WeMos D1 R2 was the pin numbers.

Boards like the Arduino Uno have a relatively simple structure, so the board pin number matches the pin number in the Arduino IDE.

For example, if you want to set pin 4 of the Arduino as output and pin 5 as input, you can do it as follows:

int outputPin = 4;
int inputPin = 5;

void setup(){
    pinMode(outputPin, OUTPUT);
    pinMode(inputPin, INPUT);
}

However, if you apply this directly to the Wemos D1 R2, it won't work.

This is because of a different pin number system.

This is because on the Wemos board, names like D1, D2 are mapped differently from numbers in the IDE.

#define outputPin D4
#define inputPin D5

void setup(){
    pinMode(outputPin, OUTPUT);
    pinMode(inputPin, INPUT);
}

So why does this Arduino have such a structure?

3. GPIO Pins and Arduino Pin Mapping

Looking at the Arduino Uno, you can see a large chipset embedded in it.

Think of this as the CPU, the processing unit, in terms of a computer.

The pins attached to the side of the Arduino are thought to be assigned to each leg of the Arduino chipset.

Using the Arduino D1 R2-5

The picture below shows which leg of the chipset each pin is assigned to.

Out of these connecting pins, the pins that can output or input digital signals are called GPIO pins.

GPIO is short for General Purpose Input/Output.

Using the Arduino D1 R2-6

In the case of the Arduino Uno, you can see that the GPIO pins almost match the board's pin numbers.

So you can run the code without issue if you enter the pin numbers as written in the IDE.

4. Pin Mapping of Wemos D1 R2

The D1 R2 board has a basic chipset along with a WiFi module.

Some of the chipset's pins are used for communication with the WiFi module, limiting the number of pins available for input and output.

When placing the remaining pins on the Arduino board, the GPIO numbers are assigned in no order, causing issues.

Using the Arduino D1 R2-7

As a result, the board manufacturer logically renumbered each pin as D0, D1, D2, so users wouldn't be confused, and made it so these numbers could be used 그대로 in the Arduino IDE.

As seen in the pin map image above, numbers like D1, D2 differ from the actual internal GPIO numbers, so be sure to refer to this map when using the pins.

5. Then How Should We Use It?

The board package installed in the Arduino IDE includes definitions for mapping logical pin names like D5, D6 to actual GPIO numbers.

So if you define as #define myPin D5 at the top, the definition #define D5 14 is included internally in the board package, ultimately making myPin point to GPIO14.

Using the Arduino D1 R2-8
#define myPin D5

void setup(){
    pinMode(myPin, OUTPUT);
}

Then you can use it just like a regular pin.

However, be cautious as some pins are related to booting or flashing.

Board Pin (Dn)

Actual GPIO Number

Remarks

D0

GPIO16

D1

GPIO5

I2C SCL

D2

GPIO4

I2C SDA

D3

GPIO0

Boot related pin, caution

D4

GPIO2

Built-in LED

D5

GPIO14

SPI SCK

D6

GPIO12

SPI MISO

D7

GPIO13

SPI MOSI

D8

GPIO15

Boot related pin, caution

RX

GPIO3

Serial receive

TX

GPIO1

Serial transmit

6. Concluding the Article

Using the Arduino D1 R2-9

Last time I used the D1 R2, I only added a simple temperature and humidity sensor, so it wasn't too difficult.

This time, as I connected more pins, I learned a few new things.

I'm considering running a maker club next year.

관련 글

Coding a Spider Robot with a micro:bit
Coding a Spider Robot with a micro:bit
This time, a free lecture was opened at a robotics technology meetup.It was a training session at Jaehyun High School on controlling a spider robot us...
Cloning an RFID Card with Arduino
Cloning an RFID Card with Arduino
Today I’m going to write about how to clone an RFID card with an Arduino.Once I write something down I don’t forget it, so I’m leaving this here as a...
Collecting Temperature and Humidity Data with Arduino ESP32
Collecting Temperature and Humidity Data with Arduino ESP32
Today, we will create a Wi-Fi Stevenson screen that measures temperature and humidity and transmits data using Arduino ESP32. This content is based on a script for a +1 session that will be conducted at school. 1. Materials The materials are simple. ESP32, DHT-22, three wires First, briefly explain the ESP32...
Solution for Timed out waiting for packet header on MacBook with Arduino
Solution for Timed out waiting for packet header on MacBook with Arduino
How to solve the Timed out issue when connecting Arduino Wemos D1 R2 to a MacBook
Connecting Arduino with Spreadsheets - Configuring Code
Connecting Arduino with Spreadsheets - Configuring Code
In the last article, we explored the sheet setup required to connect Arduino with a spreadsheet. In this article, we'll learn about data transmission using HTTPS communication from the Arduino D1 board. 1. Installing Arduino D1 Board Library It is necessary to install the board library...
Connecting Arduino with Spreadsheets - Google Sheets Setup
Connecting Arduino with Spreadsheets - Google Sheets Setup
Recently, I decided to work with students to observe and analyze the temperature and humidity around the school using Arduino. To store the data measured by Arduino, an SD card was necessary, and it was cumbersome to remove and reinsert the SD card to check the data. I suddenly thought about saving the data on the web...

댓글을 불러오는 중...