Original Code from factory

Hi, I am new to Arduino. I just bought a Nano ESP32. Where can I find the original code (RGB blinking) loaded on the board?

void setup() {

// initialize digital pin 3,4 & 6 as an output.

pinMode(3, OUTPUT);

pinMode(4, OUTPUT);

pinMode(6, OUTPUT); }

// the loop function runs over and over again forever

void loop() {

//here current flows through pin 6 illuminating red led in the RGB LED

digitalWrite(3, LOW);

digitalWrite(4, LOW);

digitalWrite(6, HIGH);

delay(500);

//here current flows through pin 3 illuminating green led in the RGB LED

digitalWrite(3, HIGH);

digitalWrite(4, LOW);

digitalWrite(6, LOW);

delay(500);

//here current flows through pin 4 illuminating blue led in the RGB LED

digitalWrite(3, LOW);

digitalWrite(4, HIGH);

digitalWrite(6, LOW);

delay(500);

//Further mixture of colours can be crteated by keeping any two pins HIGH at the same time

}

Thank you so much for the quick reply. It really helps. It worked by using your code, but with some minor modifications:
(1) I changed pin 3, 4, 6 to 14, 15, 16, based on the datasheet.
(2) I used two LOW one HIGH in each segment. I think LOW is ON. Otherwise the color looks messed up.
Thank you again!

you could use the dedicated pin names

The ESP32 features an RGB LED that can be controlled with the

LED_RED, LED_GREEN and LED_BLUE pin names. These pins are not accessible on the headers of the board, and can only be used for the RGB LED.

To control them, use (STATE being HIGH or LOW)

digitalWrite(LED_RED, STATE);   //red
digitalWrite(LED_GREEN, STATE); //green
digitalWrite(LED_BLUE, STATE);  //blue

These pins are so called active-low, what this means in practice is that to turn on one of the LEDs, you need to write it to LOW, like this:

digitalWrite(LED_RED, LOW);    //red
digitalWrite(LED_GREEN, LOW);  //green
digitalWrite(LED_BLUE, LOW);   //blue

Thanks!

1 Like

Hi,
I am new with Arduino (Nano ESP32). When I upload a simple program to the board, it seems working at the beginning. But at the end, it shows a error message saying upload failed. Somehow the USB port became disconnected: "Arduino Nano ESP32 on COM4 [not connected]". What did I do incorrectly?

Thanks!

Hello @lixipu, the Arduino Nano ESP32 has two boot modes and relies on specific Flash contents to work correctly, so it's easy to mess something up, but no worries!

  • Make sure to select the USB Mode as "Normal mode" when loading sketches - the other mode is reserved for debugging and requires special care (more info here).
  • Try resetting the Flash contents by following this article and see if this helps.
  • I assume you are on Windows - try reinstalling the "Arduino ESP32 Boards" core from Board Manager in the IDE to reinstall the drivers on your computer.