Skip to content

Commit ceaccb4

Browse files
committed
Update pin-setup.md
1 parent 0882ae8 commit ceaccb4

File tree

1 file changed

+25
-9
lines changed
  • content/hardware/03.nano/boards/nano-esp32/tutorials/pin-setup

1 file changed

+25
-9
lines changed

content/hardware/03.nano/boards/nano-esp32/tutorials/pin-setup/pin-setup.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ hardware:
77
tags: [ESP32, Pin Configuration]
88
---
99

10+
## Overview
11+
1012
The [Arduino Nano ESP32](https://store.arduino.cc/nano-esp32) is a Nano form factor board based on an ESP32-S3 SoC. This board is part of the [Arduino Nano Family](https://store.arduino.cc/pages/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.
1113

1214
This means that if you want to control a pin you can simply use the pin number that is printed on the board itself:
1315

14-
```
16+
```arduino
1517
// This will enable the pin marked with "8" on the board:
1618
digitalWrite(8, HIGH);
1719
```
1820

21+
### Compatibility Mode
22+
1923
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 "8" on the board such libraries expect you to write `17` in your code as that's the GPIO number corresponding to that pin.
2024

2125
For this purpose, we added a compatibility mode so that you can choose which numbering scheme you want to use:
@@ -40,33 +44,45 @@ This makes it possible to migrate an older Nano board, to a newer generation Nan
4044
This of course brings a separate issue, which is that by default, the Nano ESP32 does not use the ESP32's pinout. An example of this is:
4145
- Pin `2` is actually `5`
4246
- Pin `5` is actually `8`
43-
- and so on..
47+
- and so on (see the full [pin map](#nano-esp32-pin-map)).
4448

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

51+
### Default & Legacy Options
52+
4753
Luckily, we have two configurations available to choose between:
48-
- **Nano (Default)**
49-
- **ESP32-S3 (Legacy)**.
54+
- `By Arduino pin (default)`
55+
- `By GPIO number (legacy)`.
5056

51-
So, let's say we are configuring a pin in a sketch:
57+
So, let's say we are configuring a pin in a sketch, using the `Arduino pin (default)` option:
5258

5359
```arduino
5460
// with default configuration, this enables pin 2 as an output
5561
pinMode(2, OUTPUT);
5662
```
5763

58-
But, using the ESP32 configuration (legacy):
64+
But, when using the `GPIO number (legacy)` option, we would need to configure it like this:
5965

6066
```arduino
6167
// with ESP32 configuration, this enables pin 2 as an output
6268
pinMode(5, OUTPUT);
6369
```
6470

65-
### Which Pin Config Should I Choose?
71+
### Pin Labels
72+
73+
You can also control pins using labels such as `D0`, `D1`, `D2`. These labels are predefined in the core, and are adjusted based on what configuration you make.
74+
75+
For example, if you are using the `GPIO number (legacy)` option:
76+
77+
```arduino
78+
/*
79+
This will configure the "D2" physical pin on your board
80+
(but will internally configure pin 5 on the ESP32)
81+
*/
82+
pinMode(D2, OUTPUT);
83+
```
6684

67-
The answer to this depends on what platform you prefer most: if you are most familiar with Arduino & the Nano form factor, we recommend you use the default (Nano).
6885

69-
If you experience with the ESP32 platform, and not so much with the Arduino platform, the legacy (ESP32) configuration might be a better option. However please bare in mind that pins in the code will not match the Nano ESP32's physical pin labels.
7086

7187
## Change Pin Configuration
7288

0 commit comments

Comments
 (0)