Nano ESP32 Selecting Pin Configuration

Learn how to switch between default & ESP32 pin configurations when programming your board.

Overview

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);

Compatibility Mode

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

17
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:

  • when porting an existing Arduino project from another Nano board, it's convenient to use the "Arduino pin" scheme which reflects the numbers printed on the board
  • when using third-party libraries for ESP32, you should use the "GPIO number" scheme which corresponds to the internal numbers

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.

Software & Hardware Needed

Different Pin Configurations

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:

  • Pin
    2
    is actually GPIO
    5
  • Pin
    5
    is actually GPIO
    8
  • and so on (see the full pin map).

It is common in a board's design that the actual microcontroller's pins don't match the header pins.

Default & Legacy Options

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)
option:

1// with default configuration, this enables pin 2 as an output
2pinMode(2, OUTPUT);

But, when using the

GPIO number (legacy)
option, we would need to configure it like this:

1// with ESP32 configuration, this enables pin 2 as an output
2pinMode(5, OUTPUT);

Pin Labels

You can also control pins using labels such as

D0
,
D1
,
D2
. These labels are predefined in the Board Package, 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 board
3(but will internally configure GPIO 5 on the ESP32)
4*/
5pinMode(D2, OUTPUT);

Change Pin Configuration

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.

Change pin configuration in the Arduino IDE.
Change pin configuration in the Arduino IDE.

You can now upload a sketch, and the configuration will change.

Nano ESP32 Pin Map

To understand how the Nano ESP32 board's pins correlates with the ESP32-S3 SoC pins, have a look at the pin map below:

NanoESP32
D0GPIO44
D1GPIO43
D2GPIO5
D3GPIO6
D4GPIO7
D5GPIO8
D6GPIO9
D7GPIO10
D8GPIO17
D9GPIO18
D10GPIO21
D11GPIO38
D12GPIO47
D13GPIO48
A0GPIO1
A1GPIO2
A2GPIO3
A3GPIO4
A4GPIO11
A5GPIO12
A6GPIO13
A7GPIO14
BOOT0GPIO46
BOOT1GPIO0

See the pinout below for a better visual translation:

Nano / ESP32 pinout
Nano / ESP32 pinout

Summary

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.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.