The Arduino Nano ESP32 is a Nano form factor board based on an ESP32-S3 SoC. This board is part of the Arduino Nano Family, and follows the same pinout as all Nano boards. This is very convenient if you want to port a project from another Nano board, as you can preserve the same wiring and pin numbers in the code.
This means that if you want to control a pin you can simply use the pin number that is printed on the board itself:
1// This will enable the pin marked with "D8" on the board:2digitalWrite(8, HIGH);
However, some libraries previously written for ESP32 boards (to name a few: OneWire, FastLED, ESP32Servo) don't support the pin numbers printed on the board and require you to refer to the internal microcontroller's GPIO number instead. For instance, to refer to the pin labelled "D8" on the board such libraries expect you to write
in your code as that's the GPIO number corresponding to that pin.
For this purpose, we added a compatibility mode so that you can choose which numbering scheme you want to use:
To change this configuration, simply connect your board, go to Tools > Pin Numbering and then select your option. More details are available in this tutorial.
So why does the Nano ESP32 pins not match the ESP32 (MCU) pins? The Nano ESP32 was designed using the Nano form factor, a favorable form factor for many, which has consistently kept its pins for many years.
This makes it possible to migrate an older Nano board, to a newer generation Nano (like the Nano ESP32), without having to change your hardware setup.
This of course brings a separate issue, which is that this numbering does not match the ESP32's native GPIO assignment. An example of this is:
is actually GPIO
is actually GPIO
It is common in a board's design that the actual microcontroller's pins don't match the header pins.
Luckily, we have two configurations available to choose between:
By Arduino pin (default)
By GPIO number (legacy)
So, let's say we are configuring a pin in a sketch, using the
Arduino pin (default)
1// with default configuration, this enables pin 2 as an output2pinMode(2, OUTPUT);
But, when using the
option, we would need to configure it like this:
GPIO number (legacy)
1// with ESP32 configuration, this enables pin 2 as an output2pinMode(5, OUTPUT);
You can also control pins using labels such as
. These labels are predefined in the core, and are adjusted based on what configuration you make.
For example, the following code will access the same pin, regardless of what configuration you use:
1/*2This will configure the "D2" physical pin on your board3(but will internally configure GPIO 5 on the ESP32)4*/5pinMode(D2, OUTPUT);
To change the pin configuration, open the Arduino IDE, and navigate to Tools > Pin Numbering. Here you can select between the default (Nano) and legacy (ESP32) options.
You can now upload a sketch, and the configuration will change.
To understand how the Nano ESP32 board's pins correlates with the ESP32-S3 SoC pins, have a look at the pin map below:
See the pinout below for a better visual translation:
In this tutorial, we've covered how the Nano ESP32's pinout differ from the ESP32-S3 SoC pinout. We've also had a look at how to change the configuration, and provided a pin map that can be used as a reference when making your next project.