Arduino has determined that a limited number of Arduino Nano ESP32 boards were assembled with an RGB LED which has the green and blue pins inverted.
The inverted pins will result in the following behavior:
- The predefined
LED_GREEN
constant will have the blue LED pin number. - The predefined
LED_BLUE
constant will have the green LED pin number. - The RGB LED will be blue instead of green when the board is in recovery mode.
- The RGB LED will be yellow instead of purple when the board is in bootloader mode.
Identify which RGB LED is on your board
It is possible to determine the type of RGB LED by visually inspecting the board:
- Find the white reset button on the top of the board.
- Hold the board so that the USB port is facing upward, and the RST label facing the right way.
- Locate the RGB LED just right of the reset button.
- Look closely at the RGB LED component:
- If it has a black color, it does not have swapped green and blue pins.
- If it has a gray/green color, it has swapped green and blue pins.
Using the RGB LED with inverted green and blue pins
Referencing the pins directly
When writing to the RGB LED pins, use 16
for green, and 15
for blue.
Set the RGB LED to green:
digitalWrite(14, HIGH); // Red OFF
digitalWrite(16, LOW); // Green ON
digitalWrite(15, HIGH); // Blue OFF
Set the RGB LED to blue:
digitalWrite(14, HIGH); // Red OFF
digitalWrite(16, HIGH); // Green OFF
digitalWrite(15, LOW); // Blue ON
Declaring your own constants
For convenience, you can declare your own constants in sketches where you use the RGB LED:
const uint8_t MY_LED_RED = 14;
const uint8_t MY_LED_GREEN = 16;
const uint8_t MY_LED_BLUE = 15;
Set the RGB LED to purple with the above constants:
digitalWrite(MY_LED_RED, LOW); // Red ON
digitalWrite(MY_LED_GREEN, HIGH); // Green OFF
digitalWrite(MY_LED_BLUE, LOW); // Blue ON
Correcting the predefined constants by editing io_pin_remap.cpp
If you’re comfortable editing files inside the board core, you can change a few lines so that the LED_GREEN
and LED_BLUE
constants have the correct values.
Follow these steps:
-
Open the Arduino 15 folder(?).
-
Navigate to
packages/arduino/hardware/esp32/<version>
. -
Open
io_pin_remap.cpp
in a text editor. -
Find the following lines:
[LED_RED] = 46, [LED_GREEN] = 0, [LED_BLUE] = 45, // RTS
-
Edit them so they look like this:
[LED_RED] = 46, [LED_GREEN] = 45, // RTS [LED_BLUE] = 0,
-
Save the changes to
io_pin_remap.cpp
.
To preserve hardware flow control on the serial port, also make this change in pins_arduino.h
:
-
Inside the same folder as before, open
pins_arduino.h
. -
Find the line
static constexpr uint8_t RTS = LED_BLUE;
and change it to
static constexpr uint8_t RTS = LED_GREEN;
-
Save the changes to
pins_arduino.h
.
Note that the changes will be overwritten if you update or change the esp32 board package version.