You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/03.nano/boards/nano-esp32/tutorials/pin-setup/pin-setup.md
+25-9Lines changed: 25 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,15 +7,19 @@ hardware:
7
7
tags: [ESP32, Pin Configuration]
8
8
---
9
9
10
+
## Overview
11
+
10
12
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.
11
13
12
14
This means that if you want to control a pin you can simply use the pin number that is printed on the board itself:
13
15
14
-
```
16
+
```arduino
15
17
// This will enable the pin marked with "8" on the board:
16
18
digitalWrite(8, HIGH);
17
19
```
18
20
21
+
### Compatibility Mode
22
+
19
23
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.
20
24
21
25
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
40
44
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:
41
45
- Pin `2` is actually `5`
42
46
- Pin `5` is actually `8`
43
-
- and so on..
47
+
- and so on (see the full [pin map](#nano-esp32-pin-map)).
44
48
45
49
It is common in a board's design that the actual microcontroller's pins doesn't match the header pins.
46
50
51
+
### Default & Legacy Options
52
+
47
53
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)`.
50
56
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:
52
58
53
59
```arduino
54
60
// with default configuration, this enables pin 2 as an output
55
61
pinMode(2, OUTPUT);
56
62
```
57
63
58
-
But, using the ESP32 configuration (legacy):
64
+
But, when using the `GPIO number (legacy)` option, we would need to configure it like this:
59
65
60
66
```arduino
61
67
// with ESP32 configuration, this enables pin 2 as an output
62
68
pinMode(5, OUTPUT);
63
69
```
64
70
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
+
```
66
84
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).
68
85
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.
0 commit comments